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
|
:objects
|
||||||
(let [objects (:content (first (filter #(= (get-in % [:attrs :name]) "objects") (:content map-tmx))))]
|
(let [objects (:content (first (filter #(= (get-in % [:attrs :name]) "objects") (:content map-tmx))))]
|
||||||
(vec (map (fn [obj]
|
(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)))
|
tags (flatten (map :content (:content obj)))
|
||||||
properties (map #(hash-map (keyword (get-in % [:attrs :name])) (get-in % [:attrs :value])) tags)]
|
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": [
|
"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": {
|
"fileStates": {
|
||||||
"level_001.tmx": {
|
"level_001.tmx": {
|
||||||
|
|
@ -30,11 +30,11 @@
|
||||||
"expandedObjectLayers": [
|
"expandedObjectLayers": [
|
||||||
2
|
2
|
||||||
],
|
],
|
||||||
"scale": 1.1429,
|
"scale": 3.1565,
|
||||||
"selectedLayer": 0,
|
"selectedLayer": 2,
|
||||||
"viewCenter": {
|
"viewCenter": {
|
||||||
"x": 657.5378423309126,
|
"x": 612.8623475368288,
|
||||||
"y": 883.7168606177268
|
"y": 1141.1373356565816
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"walls.tsx": {
|
"walls.tsx": {
|
||||||
|
|
@ -60,8 +60,8 @@
|
||||||
"recentFiles": [
|
"recentFiles": [
|
||||||
"level_001.tmx",
|
"level_001.tmx",
|
||||||
"walls.tsx",
|
"walls.tsx",
|
||||||
"tutorial.tmx",
|
|
||||||
"objects.tsx",
|
"objects.tsx",
|
||||||
|
"tutorial.tmx",
|
||||||
"map_tileset.tsx"
|
"map_tileset.tsx"
|
||||||
],
|
],
|
||||||
"tileset.lastUsedFormat": "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"))
|
(local assets (require "src/assets.fnl"))
|
||||||
|
|
||||||
(lambda info-pad [x y name]
|
(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)]
|
(w h) (assets.objects-sprite:getDimensions)]
|
||||||
(lambda pad.load [self]
|
(lambda pad.load [self]
|
||||||
(set self.quad (love.graphics.newQuad 75 0 25 25 w h)))
|
(set self.quad (love.graphics.newQuad 75 0 25 25 w h)))
|
||||||
|
|
||||||
|
|
||||||
(fn pad.draw-debug [self]
|
(fn pad.draw-debug [self]
|
||||||
(color.set-color :black)
|
(color.set-color :black)
|
||||||
(love.graphics.rectangle "line" self.x self.y 25 25))
|
(love.graphics.rectangle "line" self.x self.y 25 25))
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@
|
||||||
(var bump-world nil)
|
(var bump-world nil)
|
||||||
(var level-key nil)
|
(var level-key nil)
|
||||||
|
|
||||||
|
(lambda bump-filter [item other]
|
||||||
|
(if (= other.behavior "block") :slide :cross))
|
||||||
|
|
||||||
(lambda angle-to-direction [angle]
|
(lambda angle-to-direction [angle]
|
||||||
"Convert angle (radians) to compass direction keyword"
|
"Convert angle (radians) to compass direction keyword"
|
||||||
(local tau (* 2 math.pi))
|
(local tau (* 2 math.pi))
|
||||||
|
|
@ -19,7 +22,10 @@
|
||||||
(local directions [:e :se :s :sw :w :nw :n :ne])
|
(local directions [:e :se :s :sw :w :nw :n :ne])
|
||||||
(. directions (+ (% section 8) 1)))
|
(. 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]
|
(fn player.update [self dt]
|
||||||
(let [
|
(let [
|
||||||
|
|
@ -38,9 +44,7 @@
|
||||||
dir-fn (if (or d-key a-key) #(+ $1 $2) #(- $1 $2))
|
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-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)))
|
new-y (dir-fn self.y (* self.speed dt (math.sin self.rot)))
|
||||||
col-filter-fn (lambda [item other]
|
(x y cols len) (bump-world:move self new-x new-y bump-filter)]
|
||||||
(if (= other.behavior "block") :slide :cross))
|
|
||||||
(x y cols len) (bump-world:move self new-x new-y col-filter-fn)]
|
|
||||||
(set self.x x)
|
(set self.x x)
|
||||||
(set self.y y))
|
(set self.y y))
|
||||||
(if (> self.battery 0)
|
(if (> self.battery 0)
|
||||||
|
|
@ -50,8 +54,12 @@
|
||||||
|
|
||||||
(fn player.load [self]
|
(fn player.load [self]
|
||||||
(set self.battery 100)
|
(set self.battery 100)
|
||||||
(set self.x (. levels :levels level-key :spawns :player-1 :x))
|
(let [
|
||||||
(set self.y (. levels :levels level-key :spawns :player-1 :y))
|
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
|
(set self.quads
|
||||||
(let [
|
(let [
|
||||||
(w h) (assets.player-sprite:getDimensions)]
|
(w h) (assets.player-sprite:getDimensions)]
|
||||||
|
|
@ -64,8 +72,7 @@
|
||||||
:sw (love.graphics.newQuad 125 0 25 25 w h)
|
:sw (love.graphics.newQuad 125 0 25 25 w h)
|
||||||
:w (love.graphics.newQuad 150 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)
|
: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]
|
(fn player.draw50 [self]
|
||||||
"draw player sprite and hitbox"
|
"draw player sprite and hitbox"
|
||||||
|
|
@ -73,14 +80,15 @@
|
||||||
(love.graphics.draw
|
(love.graphics.draw
|
||||||
assets.player-sprite
|
assets.player-sprite
|
||||||
(. self.quads (angle-to-direction player.rot))
|
(. self.quads (angle-to-direction player.rot))
|
||||||
self.x self.y))
|
(- self.x 3) (- self.y 7)))
|
||||||
|
|
||||||
(fn player.draw-debug [self]
|
(fn player.draw-debug [self]
|
||||||
"draw player hitbox and direction line"
|
"draw player hitbox and direction line"
|
||||||
(color.set-color :black)
|
(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)
|
(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.translate ox oy)
|
||||||
(love.graphics.rotate self.rot)
|
(love.graphics.rotate self.rot)
|
||||||
(love.graphics.line 0 0 35 0))
|
(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]
|
(fn load [screen]
|
||||||
(let [
|
(let [
|
||||||
|
|
@ -32,11 +40,12 @@
|
||||||
}
|
}
|
||||||
:groups {
|
:groups {
|
||||||
; gravity = {filter = {'gravity'}},
|
; gravity = {filter = {'gravity'}},
|
||||||
; :colliders {:filter [:collider]}
|
:hitbox {:filter [:hitbox]}
|
||||||
; :post-draw {:filter [:post-draw]}
|
; :post-draw {:filter [:post-draw]}
|
||||||
}
|
}
|
||||||
:systems [
|
:systems [
|
||||||
(nata:oop)
|
(nata:oop)
|
||||||
|
(collider-manager bump-world)
|
||||||
camera
|
camera
|
||||||
walls
|
walls
|
||||||
(hud {: screen})
|
(hud {: screen})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue