Compare commits
3 commits
20d7c75b07
...
99f73315b3
| Author | SHA1 | Date | |
|---|---|---|---|
| 99f73315b3 | |||
| 4540542f13 | |||
| 753e6ace68 |
8 changed files with 169 additions and 76 deletions
BIN
two_player_cleaning_game/assets/charging_station.aseprite
Normal file
BIN
two_player_cleaning_game/assets/charging_station.aseprite
Normal file
Binary file not shown.
BIN
two_player_cleaning_game/assets/objects.aseprite
Normal file
BIN
two_player_cleaning_game/assets/objects.aseprite
Normal file
Binary file not shown.
BIN
two_player_cleaning_game/assets/objects.png
Normal file
BIN
two_player_cleaning_game/assets/objects.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 549 B |
|
|
@ -4,24 +4,25 @@
|
||||||
<export target="level_001.tmj" format="json"/>
|
<export target="level_001.tmj" format="json"/>
|
||||||
</editorsettings>
|
</editorsettings>
|
||||||
<tileset firstgid="1" source="walls.tsx"/>
|
<tileset firstgid="1" source="walls.tsx"/>
|
||||||
|
<tileset firstgid="21" source="objects.tsx"/>
|
||||||
<layer id="1" name="Tile Layer 1" width="50" height="50">
|
<layer id="1" name="Tile Layer 1" width="50" height="50">
|
||||||
<data encoding="csv">
|
<data encoding="csv">
|
||||||
5,1,1,1,1,1,1,1,1,1,1,1,12,1,1,1,1,1,1,1,12,1,1,1,1,1,1,1,1,12,1,1,1,1,1,1,1,1,1,12,1,1,1,1,1,1,1,1,1,4,
|
5,1,1,1,1,1,1,1,1,1,1,1,12,1,1,1,1,1,1,1,12,1,1,1,1,1,1,1,1,12,1,1,1,1,1,1,1,1,1,12,1,1,1,1,1,1,1,1,1,4,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
10,0,0,0,21,22,21,0,0,0,0,0,10,0,0,0,0,0,0,0,10,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,8,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,8,11,11,11,11,11,11,11,11,11,10,
|
10,0,0,0,0,21,0,0,0,0,0,0,10,0,0,0,0,0,0,0,8,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,8,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,8,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
|
10,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
|
10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,11,11,11,10,
|
10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,8,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
10,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,0,0,0,0,10,11,11,11,11,11,11,11,11,8,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
10,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
10,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
10,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,10,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
||||||
14,1,1,1,1,1,1,1,1,1,1,1,15,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
14,1,1,1,1,1,1,1,1,1,1,1,15,0,0,0,0,0,0,0,10,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,2,1,1,1,1,1,1,1,1,13,1,1,1,1,1,1,1,1,1,13,1,1,4,11,11,11,11,11,11,10,
|
10,11,11,11,11,11,11,11,11,11,11,11,10,0,0,0,0,0,0,0,2,1,1,1,1,1,1,1,1,13,1,1,1,1,1,1,1,1,1,13,1,1,4,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,10,
|
10,11,11,11,11,11,11,11,11,11,11,11,10,0,0,0,0,0,0,0,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,8,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,10,
|
10,11,11,11,11,11,11,11,11,11,11,11,8,0,0,0,0,0,0,0,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,10,
|
10,11,11,11,11,11,11,11,11,11,11,11,11,0,0,0,0,0,0,0,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,5,1,1,1,1,1,1,1,1,13,1,18,11,11,17,1,15,
|
10,11,11,11,11,11,11,11,11,11,11,11,11,0,0,0,0,0,0,0,11,11,11,11,11,11,11,11,11,11,11,11,11,5,1,1,1,1,1,1,1,1,13,1,18,11,11,17,1,15,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
|
10,11,11,11,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
|
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
|
||||||
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,10,
|
10,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,9,11,11,11,11,11,11,10,
|
||||||
|
|
|
||||||
20
two_player_cleaning_game/assets/tiled/objects.tsx
Normal file
20
two_player_cleaning_game/assets/tiled/objects.tsx
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<tileset version="1.10" tiledversion="1.12.1" name="objects" tilewidth="25" tileheight="25" tilecount="16" columns="4">
|
||||||
|
<image source="../objects.png" width="100" height="100"/>
|
||||||
|
<tile id="0">
|
||||||
|
<properties>
|
||||||
|
<property name="name" value="charging_pad"/>
|
||||||
|
</properties>
|
||||||
|
<objectgroup draworder="index" id="2">
|
||||||
|
<object id="1" x="2.08266" y="2.08266" width="21.0002" height="21.087"/>
|
||||||
|
</objectgroup>
|
||||||
|
</tile>
|
||||||
|
<tile id="1">
|
||||||
|
<properties>
|
||||||
|
<property name="name" value="charging_station"/>
|
||||||
|
</properties>
|
||||||
|
<objectgroup draworder="index" id="2">
|
||||||
|
<object id="1" x="1.12811" y="2.08266" width="22.8225" height="20.6531"/>
|
||||||
|
</objectgroup>
|
||||||
|
</tile>
|
||||||
|
</tileset>
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
{
|
{
|
||||||
"activeFile": "walls.tsx",
|
"activeFile": "level_001.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": {
|
||||||
"scale": 4.0012,
|
"scale": 2.4998,
|
||||||
"selectedLayer": 0,
|
"selectedLayer": 0,
|
||||||
"viewCenter": {
|
"viewCenter": {
|
||||||
"x": 821.1286614015795,
|
"x": 149.0119209536763,
|
||||||
"y": 723.9078276517045
|
"y": 73.8059044723578
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"map_tileset.tsx": {
|
"map_tileset.tsx": {
|
||||||
|
|
@ -19,6 +19,10 @@
|
||||||
"scaleInDock": 1,
|
"scaleInDock": 1,
|
||||||
"scaleInEditor": 8
|
"scaleInEditor": 8
|
||||||
},
|
},
|
||||||
|
"objects.tsx": {
|
||||||
|
"scaleInDock": 1,
|
||||||
|
"scaleInEditor": 6.3771
|
||||||
|
},
|
||||||
"walls.tsx": {
|
"walls.tsx": {
|
||||||
"scaleInDock": 1.4397,
|
"scaleInDock": 1.4397,
|
||||||
"scaleInEditor": 8.2977
|
"scaleInEditor": 8.2977
|
||||||
|
|
@ -34,12 +38,14 @@
|
||||||
"map.width": 50,
|
"map.width": 50,
|
||||||
"openFiles": [
|
"openFiles": [
|
||||||
"level_001.tmx",
|
"level_001.tmx",
|
||||||
"walls.tsx"
|
"walls.tsx",
|
||||||
|
"objects.tsx"
|
||||||
],
|
],
|
||||||
"project": "untitled.tiled-project",
|
"project": "untitled.tiled-project",
|
||||||
"recentFiles": [
|
"recentFiles": [
|
||||||
"level_001.tmx",
|
"objects.tsx",
|
||||||
"walls.tsx",
|
"walls.tsx",
|
||||||
|
"level_001.tmx",
|
||||||
"map_tileset.tsx"
|
"map_tileset.tsx"
|
||||||
],
|
],
|
||||||
"tileset.lastUsedFormat": "tsx",
|
"tileset.lastUsedFormat": "tsx",
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -18,6 +18,7 @@
|
||||||
:black-half-tone [0 0 0 0.25]
|
:black-half-tone [0 0 0 0.25]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
(fn reset-color []
|
(fn reset-color []
|
||||||
"reset color to white (no tinting)"
|
"reset color to white (no tinting)"
|
||||||
(love.graphics.setColor 1 1 1))
|
(love.graphics.setColor 1 1 1))
|
||||||
|
|
@ -30,9 +31,17 @@
|
||||||
(var player-art nil) ; 25x50 pixels each player is 25x25
|
(var player-art nil) ; 25x50 pixels each player is 25x25
|
||||||
(var dust-sprite nil) ; 35x35 pixels
|
(var dust-sprite nil) ; 35x35 pixels
|
||||||
(var battery-bar-sprite nil)
|
(var battery-bar-sprite nil)
|
||||||
(var walls-sprite nil)
|
(local walls {
|
||||||
(var walls-batch nil)
|
:sprite nil
|
||||||
(var wall-quads nil)
|
:quads []
|
||||||
|
:batch nil
|
||||||
|
})
|
||||||
|
(local objects {
|
||||||
|
:sprite nil
|
||||||
|
:quads {}
|
||||||
|
:list []
|
||||||
|
})
|
||||||
|
|
||||||
(local screen
|
(local screen
|
||||||
(let [scale 2 canvas-w 800 canvas-h 450]
|
(let [scale 2 canvas-w 800 canvas-h 450]
|
||||||
{ :screen-w (* canvas-w scale)
|
{ :screen-w (* canvas-w scale)
|
||||||
|
|
@ -43,51 +52,102 @@
|
||||||
:canvas nil}))
|
:canvas nil}))
|
||||||
(local camera {:x 0 :y 0})
|
(local camera {:x 0 :y 0})
|
||||||
(local debug false)
|
(local debug false)
|
||||||
|
(lambda debug-print [obj]
|
||||||
|
(print (fennel.view obj)))
|
||||||
|
|
||||||
(local collider-debug-boxes [])
|
(local collider-debug-boxes [])
|
||||||
|
(lambda add-collider-debug-box [x y w h]
|
||||||
|
(table.insert collider-debug-boxes {: x : y :width w :height h}))
|
||||||
|
|
||||||
(local bump-world (bump.newWorld 25))
|
(local bump-world (bump.newWorld 25))
|
||||||
(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0 })
|
(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0 })
|
||||||
; 16:9 (Modern Widescreen - Recommended)**
|
|
||||||
; - **640x360** ← Best middle ground
|
|
||||||
; - 800x450
|
|
||||||
; - 1024x576
|
|
||||||
; - 1280x720
|
|
||||||
|
|
||||||
; **4:3 (Classic/Arcade Feel)**
|
(fn load-walls []
|
||||||
; - **320x240** (very retro, but small)
|
(set walls.sprite (love.graphics.newImage "assets/walls.png"))
|
||||||
; - **800x600** (spacious, classic 4:3)
|
(set walls.batch (love.graphics.newSpriteBatch walls.sprite 2500))
|
||||||
; - 1024x768
|
;; load quads
|
||||||
|
(let [(w h) (walls.sprite:getDimensions)]
|
||||||
|
(for [i 0 19 1]
|
||||||
|
(table.insert walls.quads (love.graphics.newQuad (* i 25) 0 25 25 w h))))
|
||||||
|
;; fill batch
|
||||||
|
(each [_ row (pairs (. levels :level01 :tiles))]
|
||||||
|
(each [_ tile (pairs row)]
|
||||||
|
(let [
|
||||||
|
x tile.x
|
||||||
|
y tile.y
|
||||||
|
id tile.tile-id
|
||||||
|
colliders (or (. levels.level01.wall-colliders (- id 1)) [])]
|
||||||
|
(if (and (> id 0) (< id 21)) ;; 1-20 are wall tiles
|
||||||
|
(do
|
||||||
|
; (print (fennel.view {:quad (. walls.quads id) : x : y : id}))
|
||||||
|
(walls.batch:add (. walls.quads id) x y)
|
||||||
|
(each [_ collider (pairs colliders)]
|
||||||
|
(bump-world:add {: x : y :name :wall :behavior :block} (+ x collider.x) (+ y collider.y) collider.width collider.height)
|
||||||
|
(table.insert
|
||||||
|
collider-debug-boxes
|
||||||
|
{:x (+ x collider.x) :y (+ y collider.y) :width collider.width :height collider.height}))
|
||||||
|
))))))
|
||||||
|
|
||||||
|
(lambda create-charging-station [x y]
|
||||||
|
(let [
|
||||||
|
station {: x : y :type :charging-station :active-pads {1 false 2 false 3 false}}
|
||||||
|
pads {
|
||||||
|
1 {:x (- x 25) :y y :width 25 :height 25 :light-x (+ x 5)}
|
||||||
|
3 {:x (+ x 25) :y y :width 25 :height 25 :light-x (+ x 5 6 6)}
|
||||||
|
2 {:x x :y (+ y 25) :width 25 :height 25 :light-x (+ x 5 6)}
|
||||||
|
}]
|
||||||
|
(bump-world:add {: x : y :name :charging-station :behavior :block} x y 25 25)
|
||||||
|
(add-collider-debug-box x y 25 25)
|
||||||
|
(fn station.draw [self]
|
||||||
|
(reset-color)
|
||||||
|
(love.graphics.draw objects.sprite objects.quads.charging-station self.x self.y)
|
||||||
|
(for [i 1 3 1]
|
||||||
|
(let [pad (. pads i)]
|
||||||
|
(if (. self.active-pads i)
|
||||||
|
(do (love.graphics.draw objects.sprite objects.quads.charging-pad-active pad.x pad.y)
|
||||||
|
(set-color :light-pink)
|
||||||
|
(love.graphics.rectangle "fill" pad.light-x (+ y 18) 2 2)
|
||||||
|
(reset-color))
|
||||||
|
(love.graphics.draw objects.sprite objects.quads.charging-pad pad.x pad.y))))
|
||||||
|
)
|
||||||
|
(lambda pad-hover-cb [self dt]
|
||||||
|
(tset station.active-pads self.id true)
|
||||||
|
(when (< player.battery 100) (set player.battery (+ player.battery (* dt 6)))))
|
||||||
|
(lambda station.update [self _dt]
|
||||||
|
(set self.active-pads {1 false 2 false 3 false}))
|
||||||
|
(for [i 1 3 1]
|
||||||
|
(let [pad (. pads i)]
|
||||||
|
(bump-world:add {:name :charging-pad :behavior :hover :hover-cb pad-hover-cb :id i} pad.x pad.y 25 25)
|
||||||
|
(add-collider-debug-box pad.x pad.y 25 25)))
|
||||||
|
(table.insert objects.list station)))
|
||||||
|
|
||||||
|
(fn load-objects []
|
||||||
|
(set objects.sprite (love.graphics.newImage "assets/objects.png"))
|
||||||
|
(let [(w h) (objects.sprite:getDimensions)]
|
||||||
|
(set objects.quads.charging-pad (love.graphics.newQuad 0 0 25 25 w h))
|
||||||
|
(set objects.quads.charging-pad-active (love.graphics.newQuad 50 0 25 25 w h))
|
||||||
|
(set objects.quads.charging-station (love.graphics.newQuad 25 0 25 25 w h)))
|
||||||
|
|
||||||
|
(each [_ row (pairs (. levels :level01 :tiles))]
|
||||||
|
(each [_ tile (pairs row)]
|
||||||
|
(let [
|
||||||
|
x tile.x
|
||||||
|
y tile.y
|
||||||
|
id tile.tile-id]
|
||||||
|
(when (> id 20) ;; 21+ are object tiles
|
||||||
|
(when (= id 22) (create-charging-station x y)))))))
|
||||||
|
|
||||||
|
|
||||||
(fn love.load []
|
(fn love.load []
|
||||||
(love.window.setMode screen.screen-w screen.screen-h)
|
(love.window.setMode screen.screen-w screen.screen-h)
|
||||||
(tset screen :canvas (love.graphics.newCanvas screen.canvas-w screen.canvas-h))
|
(tset screen :canvas (love.graphics.newCanvas screen.canvas-w screen.canvas-h))
|
||||||
(bump-world:add player player.x player.y player.w player.h)
|
(bump-world:add player player.x player.y player.w player.h)
|
||||||
|
|
||||||
;; load world images
|
(load-walls)
|
||||||
(set walls-sprite (love.graphics.newImage "assets/walls.png"))
|
(load-objects)
|
||||||
(set walls-batch (love.graphics.newSpriteBatch walls-sprite 2500))
|
|
||||||
(set battery-bar-sprite (love.graphics.newImage "assets/battery_bar.png"))
|
|
||||||
|
|
||||||
;; load wall quads
|
;; load world images
|
||||||
(set wall-quads [])
|
(set battery-bar-sprite (love.graphics.newImage "assets/battery_bar.png"))
|
||||||
(let [(w h) (: walls-sprite :getDimensions)]
|
|
||||||
(for [i 0 19 1]
|
|
||||||
(table.insert wall-quads (love.graphics.newQuad (* i 25) 0 25 25 w h))))
|
|
||||||
;; load tiles
|
|
||||||
(each [_ row (pairs (. levels :level01 :tiles))]
|
|
||||||
(each [_ tile (pairs row)]
|
|
||||||
(let [
|
|
||||||
x (. tile :x)
|
|
||||||
y (. tile :y)
|
|
||||||
id (. tile :tile-id)
|
|
||||||
colliders (or (. levels.level01.wall-colliders (- id 1)) [])]
|
|
||||||
(walls-batch:add (. wall-quads id) x y)
|
|
||||||
; (print (fennel.view colliders))
|
|
||||||
(each [_ collider (pairs colliders)]
|
|
||||||
(bump-world:add {: x : y :type "wall"} (+ x collider.x) (+ y collider.y) collider.width collider.height)
|
|
||||||
(table.insert
|
|
||||||
collider-debug-boxes
|
|
||||||
{:x (+ x collider.x) :y (+ y collider.y) :width collider.width :height collider.height})
|
|
||||||
))))
|
|
||||||
|
|
||||||
(set player-art
|
(set player-art
|
||||||
(let [
|
(let [
|
||||||
|
|
@ -125,23 +185,17 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start))
|
||||||
|
|
||||||
(fn draw-world []
|
(fn draw-world []
|
||||||
(reset-color)
|
(reset-color)
|
||||||
(love.graphics.draw walls-batch)
|
(love.graphics.draw walls.batch)
|
||||||
;; draw collider debug boxes
|
;; draw collider debug boxes
|
||||||
(when debug
|
(when debug
|
||||||
(set-color :black)
|
(set-color :black)
|
||||||
(each [_ collider (pairs collider-debug-boxes)]
|
(each [_ collider (pairs collider-debug-boxes)]
|
||||||
(love.graphics.rectangle "line" collider.x collider.y collider.width collider.height))))
|
(love.graphics.rectangle "line" collider.x collider.y collider.width collider.height))))
|
||||||
|
|
||||||
(local has-true? (fn [lst]
|
|
||||||
(accumulate [found? false _ v (ipairs lst)]
|
|
||||||
(or found? v))))
|
|
||||||
|
|
||||||
; All true
|
|
||||||
(local all-true? (fn [lst]
|
|
||||||
(accumulate [result true _ v (ipairs lst)]
|
|
||||||
(and result v))))
|
|
||||||
|
|
||||||
(fn love.update [dt]
|
(fn love.update [dt]
|
||||||
|
(each [_ obj (pairs objects.list)]
|
||||||
|
(obj:update dt))
|
||||||
; move / rotate player
|
; move / rotate player
|
||||||
(let [
|
(let [
|
||||||
d-key (love.keyboard.isDown :d)
|
d-key (love.keyboard.isDown :d)
|
||||||
|
|
@ -160,14 +214,21 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start))
|
||||||
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 player.x (* player.speed dt (math.cos player.rot)))
|
new-x (dir-fn player.x (* player.speed dt (math.cos player.rot)))
|
||||||
new-y (dir-fn player.y (* player.speed dt (math.sin player.rot)))
|
new-y (dir-fn player.y (* player.speed dt (math.sin player.rot)))
|
||||||
(x y) (bump-world:move player new-x new-y)]
|
col-filter-fn (lambda [item other]
|
||||||
(tset player :x x)
|
(if (= other.behavior "block") :slide :cross))
|
||||||
(tset player :y y))
|
(x y cols len) (bump-world:move player new-x new-y col-filter-fn)]
|
||||||
(if (> player.battery 0)
|
(tset player :x x)
|
||||||
(tset player :battery (- player.battery (* dt 2))))))
|
(tset player :y y))
|
||||||
|
(if (> player.battery 0)
|
||||||
|
(set player.battery (- player.battery (* dt 2))))))
|
||||||
;; Update camera to follow player (keep player centered on screen)
|
;; Update camera to follow player (keep player centered on screen)
|
||||||
(tset camera :x (- player.x (/ screen.canvas-w 2)))
|
(tset camera :x (- player.x (/ screen.canvas-w 2)))
|
||||||
(tset camera :y (- player.y (/ screen.canvas-h 2))))
|
(tset camera :y (- player.y (/ screen.canvas-h 2)))
|
||||||
|
|
||||||
|
(let
|
||||||
|
[(items len) (bump-world:queryRect player.x player.y 25 25 #(= $1.behavior "hover"))]
|
||||||
|
(each [_ item (pairs items)]
|
||||||
|
(item:hover-cb dt))))
|
||||||
|
|
||||||
(fn draw-ui []
|
(fn draw-ui []
|
||||||
(love.graphics.push)
|
(love.graphics.push)
|
||||||
|
|
@ -229,6 +290,10 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start))
|
||||||
(love.graphics.pop)
|
(love.graphics.pop)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
(fn draw-objects []
|
||||||
|
(each [_ obj (pairs objects.list)]
|
||||||
|
; (print (fennel.view obj))
|
||||||
|
(obj:draw)))
|
||||||
|
|
||||||
(fn love.draw []
|
(fn love.draw []
|
||||||
(love.graphics.setCanvas screen.canvas)
|
(love.graphics.setCanvas screen.canvas)
|
||||||
|
|
@ -238,6 +303,7 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start))
|
||||||
(love.graphics.push) ; stores the default coordinate system
|
(love.graphics.push) ; stores the default coordinate system
|
||||||
(love.graphics.translate (* -1 camera.x) (* -1 camera.y))
|
(love.graphics.translate (* -1 camera.x) (* -1 camera.y))
|
||||||
(draw-world)
|
(draw-world)
|
||||||
|
(draw-objects)
|
||||||
(draw-player)
|
(draw-player)
|
||||||
(love.graphics.pop)
|
(love.graphics.pop)
|
||||||
(draw-ui)
|
(draw-ui)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue