fix spawn and better match hitbox to player sprite
This commit is contained in:
parent
414006b667
commit
7e75b665f5
6 changed files with 42 additions and 23 deletions
|
|
@ -76,7 +76,7 @@
|
|||
:objects
|
||||
(let [objects (:content (first (filter #(= (get-in % [:attrs :name]) "objects") (:content map-tmx))))]
|
||||
(vec (map (fn [obj]
|
||||
(let [attrs (dissoc (:attrs obj) :id)
|
||||
(let [attrs (assoc (:attrs obj) :x (Double. (get-in obj [:attrs :x])) :y (Double. (get-in obj [:attrs :y])))
|
||||
tags (flatten (map :content (:content obj)))
|
||||
properties (map #(hash-map (keyword (get-in % [:attrs :name])) (get-in % [:attrs :value])) tags)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"activeFile": "objects.tsx",
|
||||
"activeFile": "tutorial.tmx",
|
||||
"expandedProjectPaths": [
|
||||
"/Users/she0001t/personal_projects/fennel_love2d_experiments/two_player_cleaning_game/assets",
|
||||
".",
|
||||
"/Users/she0001t/personal_projects/fennel_love2d_experiments/two_player_cleaning_game"
|
||||
"/Users/she0001t/personal_projects/fennel_love2d_experiments/two_player_cleaning_game",
|
||||
"/Users/she0001t/personal_projects/fennel_love2d_experiments/two_player_cleaning_game/assets"
|
||||
],
|
||||
"fileStates": {
|
||||
"level_001.tmx": {
|
||||
|
|
@ -30,11 +30,11 @@
|
|||
"expandedObjectLayers": [
|
||||
2
|
||||
],
|
||||
"scale": 1.1429,
|
||||
"selectedLayer": 0,
|
||||
"scale": 3.1565,
|
||||
"selectedLayer": 2,
|
||||
"viewCenter": {
|
||||
"x": 657.5378423309126,
|
||||
"y": 883.7168606177268
|
||||
"x": 612.8623475368288,
|
||||
"y": 1141.1373356565816
|
||||
}
|
||||
},
|
||||
"walls.tsx": {
|
||||
|
|
@ -60,8 +60,8 @@
|
|||
"recentFiles": [
|
||||
"level_001.tmx",
|
||||
"walls.tsx",
|
||||
"tutorial.tmx",
|
||||
"objects.tsx",
|
||||
"tutorial.tmx",
|
||||
"map_tileset.tsx"
|
||||
],
|
||||
"tileset.lastUsedFormat": "tsx",
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -5,11 +5,12 @@
|
|||
(local assets (require "src/assets.fnl"))
|
||||
|
||||
(lambda info-pad [x y name]
|
||||
(let [pad {: x : y : name}
|
||||
(let [pad {: x : y : name :hitbox [x y 25 25]}
|
||||
(w h) (assets.objects-sprite:getDimensions)]
|
||||
(lambda pad.load [self]
|
||||
(set self.quad (love.graphics.newQuad 75 0 25 25 w h)))
|
||||
|
||||
|
||||
(fn pad.draw-debug [self]
|
||||
(color.set-color :black)
|
||||
(love.graphics.rectangle "line" self.x self.y 25 25))
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
(var bump-world nil)
|
||||
(var level-key nil)
|
||||
|
||||
(lambda bump-filter [item other]
|
||||
(if (= other.behavior "block") :slide :cross))
|
||||
|
||||
(lambda angle-to-direction [angle]
|
||||
"Convert angle (radians) to compass direction keyword"
|
||||
(local tau (* 2 math.pi))
|
||||
|
|
@ -19,7 +22,10 @@
|
|||
(local directions [:e :se :s :sw :w :nw :n :ne])
|
||||
(. directions (+ (% section 8) 1)))
|
||||
|
||||
(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0 })
|
||||
|
||||
(local width 19)
|
||||
(local height 15)
|
||||
(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0 :hitbox [50 50 width height] })
|
||||
|
||||
(fn player.update [self dt]
|
||||
(let [
|
||||
|
|
@ -38,9 +44,7 @@
|
|||
dir-fn (if (or d-key a-key) #(+ $1 $2) #(- $1 $2))
|
||||
new-x (dir-fn self.x (* self.speed dt (math.cos self.rot)))
|
||||
new-y (dir-fn self.y (* self.speed dt (math.sin self.rot)))
|
||||
col-filter-fn (lambda [item other]
|
||||
(if (= other.behavior "block") :slide :cross))
|
||||
(x y cols len) (bump-world:move self new-x new-y col-filter-fn)]
|
||||
(x y cols len) (bump-world:move self new-x new-y bump-filter)]
|
||||
(set self.x x)
|
||||
(set self.y y))
|
||||
(if (> self.battery 0)
|
||||
|
|
@ -50,8 +54,12 @@
|
|||
|
||||
(fn player.load [self]
|
||||
(set self.battery 100)
|
||||
(set self.x (. levels :levels level-key :spawns :player-1 :x))
|
||||
(set self.y (. levels :levels level-key :spawns :player-1 :y))
|
||||
(let [
|
||||
spawn-x (-> (. levels :levels level-key :spawns :player-1 :x) (- (/ width 2)))
|
||||
spawn-y (-> (. levels :levels level-key :spawns :player-1 :y) (- (/ height 2)))
|
||||
(x y cols len) (bump-world:move self spawn-x spawn-y bump-filter)]
|
||||
(set self.x x)
|
||||
(set self.y y))
|
||||
(set self.quads
|
||||
(let [
|
||||
(w h) (assets.player-sprite:getDimensions)]
|
||||
|
|
@ -64,8 +72,7 @@
|
|||
:sw (love.graphics.newQuad 125 0 25 25 w h)
|
||||
:w (love.graphics.newQuad 150 0 25 25 w h)
|
||||
:nw (love.graphics.newQuad 175 0 25 25 w h)
|
||||
}))
|
||||
(bump-world:add self self.x self.y self.w self.h))
|
||||
})))
|
||||
|
||||
(fn player.draw50 [self]
|
||||
"draw player sprite and hitbox"
|
||||
|
|
@ -73,14 +80,15 @@
|
|||
(love.graphics.draw
|
||||
assets.player-sprite
|
||||
(. self.quads (angle-to-direction player.rot))
|
||||
self.x self.y))
|
||||
(- self.x 3) (- self.y 7)))
|
||||
|
||||
(fn player.draw-debug [self]
|
||||
"draw player hitbox and direction line"
|
||||
(color.set-color :black)
|
||||
(love.graphics.rectangle "line" self.x self.y self.w self.h)
|
||||
(love.graphics.rectangle "line" self.x self.y width height)
|
||||
(love.graphics.rectangle "line" self.x self.y 1 1)
|
||||
(love.graphics.push)
|
||||
(let [ox (+ self.x (/ 25 2)) oy (+ self.y (/ 25 2))]
|
||||
(let [ox (+ self.x (/ width 2)) oy (+ self.y (/ height 2))]
|
||||
(love.graphics.translate ox oy)
|
||||
(love.graphics.rotate self.rot)
|
||||
(love.graphics.line 0 0 35 0))
|
||||
|
|
|
|||
|
|
@ -18,6 +18,14 @@
|
|||
))
|
||||
)
|
||||
|
||||
(lambda collider-manager [bump-world]
|
||||
(local collider-manager {})
|
||||
(lambda collider-manager.addToGroup [self group-name entity]
|
||||
(when (= group-name :hitbox)
|
||||
; (utils.debug-print {:adding entity})
|
||||
(bump-world:add entity (unpack entity.hitbox))))
|
||||
collider-manager)
|
||||
|
||||
|
||||
(fn load [screen]
|
||||
(let [
|
||||
|
|
@ -32,11 +40,12 @@
|
|||
}
|
||||
:groups {
|
||||
; gravity = {filter = {'gravity'}},
|
||||
; :colliders {:filter [:collider]}
|
||||
:hitbox {:filter [:hitbox]}
|
||||
; :post-draw {:filter [:post-draw]}
|
||||
}
|
||||
:systems [
|
||||
(nata:oop)
|
||||
(collider-manager bump-world)
|
||||
camera
|
||||
walls
|
||||
(hud {: screen})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue