diff --git a/.gitignore b/.gitignore index 9b8deb4..95499cb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ .clj-kondo/ .lsp/ + + +build/ +.internal diff --git a/defold_game/.editor_settings b/defold_game/.editor_settings new file mode 100644 index 0000000..d62211c --- /dev/null +++ b/defold_game/.editor_settings @@ -0,0 +1,86 @@ +{ + :code { + :breakpoints [ + ] + } + :workflow { + :open-tabs [ + [ + [ + "/main/main.atlas" + :scene + ] + [ + "/main/main.collection" + :scene + ] + [ + "/main/player.tilesource" + :scene + ] + [ + "/main/player.script" + :code + ] + [ + "/main/main.script" + :code + ] + [ + "/game.project" + :cljfx-form-view + ] + [ + "/input/game.input_binding" + :cljfx-form-view + ] + [ + "/main/player.sprite" + :scene + ] + ] + ] + :recent-files [ + [ + "/main/player.tilesource" + :text + ] + [ + "/main/player.sprite" + :text + ] + [ + "/main/main.atlas" + :scene + ] + [ + "/main/player.tilesource" + :scene + ] + [ + "/game.project" + :cljfx-form-view + ] + [ + "/input/game.input_binding" + :cljfx-form-view + ] + [ + "/main/main.collection" + :scene + ] + [ + "/main/player.sprite" + :scene + ] + [ + "/main/main.script" + :code + ] + [ + "/main/player.script" + :code + ] + ] + } +} \ No newline at end of file diff --git a/defold_game/README.md b/defold_game/README.md new file mode 100644 index 0000000..7a684e1 --- /dev/null +++ b/defold_game/README.md @@ -0,0 +1,19 @@ +# Welcome to Defold + +This project was created from the "desktop" project template. This means that the settings in ["game.project"](defold://open?path=/game.project) have been changed to be suitable for a desktop game: + +- The screen size is set to 1280x720 +- Projection is set to Fixed Fit +- macOS and Windows icons are set +- Mouse clicks are bound to action "touch" +- A simple script in a game object is set up to receive and react to input + +[Build and run](defold://project.build) to see it in action. You can of course alter these settings to fit your needs. + +Check out [the documentation pages](https://defold.com/learn) for examples, tutorials, manuals and API docs. + +If you run into trouble, help is available in [our forum](https://forum.defold.com). + +Happy Defolding! + +--- diff --git a/defold_game/assets/app_icons/appicon.icns b/defold_game/assets/app_icons/appicon.icns new file mode 100644 index 0000000..f5a79a4 Binary files /dev/null and b/defold_game/assets/app_icons/appicon.icns differ diff --git a/defold_game/assets/app_icons/appicon.ico b/defold_game/assets/app_icons/appicon.ico new file mode 100644 index 0000000..e6dd0b0 Binary files /dev/null and b/defold_game/assets/app_icons/appicon.ico differ diff --git a/defold_game/assets/images/background.png b/defold_game/assets/images/background.png new file mode 100644 index 0000000..4692a7f Binary files /dev/null and b/defold_game/assets/images/background.png differ diff --git a/defold_game/assets/images/logo.png b/defold_game/assets/images/logo.png new file mode 100644 index 0000000..1facc50 Binary files /dev/null and b/defold_game/assets/images/logo.png differ diff --git a/defold_game/assets/images/player.png b/defold_game/assets/images/player.png new file mode 100644 index 0000000..ca62b72 Binary files /dev/null and b/defold_game/assets/images/player.png differ diff --git a/defold_game/game.project b/defold_game/game.project new file mode 100644 index 0000000..3cc0ee1 --- /dev/null +++ b/defold_game/game.project @@ -0,0 +1,35 @@ +[project] +title = Desktop Game + +[bootstrap] +main_collection = /main/main.collectionc + +[input] +game_binding = /input/game.input_bindingc +use_accelerometer = 0 + +[display] +width = 1280 +height = 720 +high_dpi = 1 + +[script] +shared_state = 1 + +[windows] +app_icon = /assets/app_icons/appicon.ico + +[osx] +app_icon = /assets/app_icons/appicon.icns + +[android] +input_method = HiddenInputField + +[physics] +gravity_y = -1000.0 +scale = 0.01 +velocity_threshold = 100.0 + +[html5] +scale_mode = stretch + diff --git a/defold_game/input/game.input_binding b/defold_game/input/game.input_binding new file mode 100644 index 0000000..45a27f2 --- /dev/null +++ b/defold_game/input/game.input_binding @@ -0,0 +1,20 @@ +key_trigger { + input: KEY_W + action: "up" +} +key_trigger { + input: KEY_A + action: "left" +} +key_trigger { + input: KEY_S + action: "down" +} +key_trigger { + input: KEY_D + action: "right" +} +mouse_trigger { + input: MOUSE_BUTTON_LEFT + action: "touch" +} diff --git a/defold_game/main/main.atlas b/defold_game/main/main.atlas new file mode 100644 index 0000000..5faa635 --- /dev/null +++ b/defold_game/main/main.atlas @@ -0,0 +1,15 @@ +images { + image: "/assets/images/background.png" +} +images { + image: "/assets/images/logo.png" +} +images { + image: "/builtins/graphics/particle_blob.png" +} +images { + image: "/assets/images/player.png" + pivot_x: 0.536806 + pivot_y: 0.447809 +} +extrude_borders: 2 diff --git a/defold_game/main/main.collection b/defold_game/main/main.collection new file mode 100644 index 0000000..a908b83 --- /dev/null +++ b/defold_game/main/main.collection @@ -0,0 +1,79 @@ +name: "main" +scale_along_z: 0 +embedded_instances { + id: "go" + data: "components {\n" + " id: \"main\"\n" + " component: \"/main/main.script\"\n" + "}\n" + "embedded_components {\n" + " id: \"logo\"\n" + " type: \"sprite\"\n" + " data: \"default_animation: \\\"logo\\\"\\n" + "material: \\\"/builtins/materials/sprite.material\\\"\\n" + "textures {\\n" + " sampler: \\\"texture_sampler\\\"\\n" + " texture: \\\"/main/main.atlas\\\"\\n" + "}\\n" + "\"\n" + "}\n" + "embedded_components {\n" + " id: \"background\"\n" + " type: \"sprite\"\n" + " data: \"default_animation: \\\"background\\\"\\n" + "material: \\\"/builtins/materials/sprite.material\\\"\\n" + "textures {\\n" + " sampler: \\\"texture_sampler\\\"\\n" + " texture: \\\"/main/main.atlas\\\"\\n" + "}\\n" + "\"\n" + " position {\n" + " z: -0.5\n" + " }\n" + "}\n" + "" + position { + x: 640.0 + y: 360.0 + } +} +embedded_instances { + id: "camera" + data: "embedded_components {\n" + " id: \"camera\"\n" + " type: \"camera\"\n" + " data: \"aspect_ratio: 1.0\\n" + "fov: 0.7854\\n" + "near_z: -1.0\\n" + "far_z: 1.0\\n" + "orthographic_projection: 1\\n" + "orthographic_mode: ORTHO_MODE_AUTO_COVER\\n" + "\"\n" + "}\n" + "" + position { + x: 640.0 + y: 360.0 + } +} +embedded_instances { + id: "player" + data: "components {\n" + " id: \"body\"\n" + " component: \"/main/player.sprite\"\n" + " position {\n" + " x: 109.0\n" + " y: 90.0\n" + " }\n" + " scale {\n" + " x: 2.0\n" + " y: 2.0\n" + " z: 2.0\n" + " }\n" + "}\n" + "components {\n" + " id: \"player1\"\n" + " component: \"/main/player.script\"\n" + "}\n" + "" +} diff --git a/defold_game/main/main.script b/defold_game/main/main.script new file mode 100644 index 0000000..1fde8d3 --- /dev/null +++ b/defold_game/main/main.script @@ -0,0 +1,10 @@ +-- function init(self) +-- msg.post(".", "acquire_input_focus") +-- end +-- +-- function on_input(self, action_id, action) +-- if action_id == hash("touch") and action.pressed then +-- print("Touch!") +-- end +-- end +-- \ No newline at end of file diff --git a/defold_game/main/player.script b/defold_game/main/player.script new file mode 100644 index 0000000..5a36a35 --- /dev/null +++ b/defold_game/main/player.script @@ -0,0 +1,30 @@ +function init(self) + msg.post(".", "acquire_input_focus") -- <1> + self.vel = vmath.vector3() -- <2> +end + +function update(self, dt) + local pos = go.get_position() -- <3> + pos = pos + self.vel * dt -- <4> + go.set_position(pos) -- <5> + + self.vel.x = 0 -- <6> + self.vel.y = 0 + + -- sprite.play_flipbook("#body", "s") + rot = go.get_rotation() + print(rot) + +end + +function on_input(self, action_id, action) + if action_id == hash("up") then + self.vel.y = 150 -- <7> + elseif action_id == hash("down") then + self.vel.y = -150 + elseif action_id == hash("left") then + self.vel.x = -150 -- <8> + elseif action_id == hash("right") then + self.vel.x = 150 + end +end diff --git a/defold_game/main/player.sprite b/defold_game/main/player.sprite new file mode 100644 index 0000000..27c84f9 --- /dev/null +++ b/defold_game/main/player.sprite @@ -0,0 +1,6 @@ +default_animation: "n" +material: "/builtins/materials/sprite.material" +textures { + sampler: "texture_sampler" + texture: "/main/player.tilesource" +} diff --git a/defold_game/main/player.tilesource b/defold_game/main/player.tilesource new file mode 100644 index 0000000..d16afdf --- /dev/null +++ b/defold_game/main/player.tilesource @@ -0,0 +1,52 @@ +image: "/assets/images/player.png" +tile_width: 25 +tile_height: 25 +collision_groups: "player" +animations { + id: "e" + start_tile: 4 + end_tile: 4 + playback: PLAYBACK_NONE +} +animations { + id: "n" + start_tile: 1 + end_tile: 1 + playback: PLAYBACK_NONE +} +animations { + id: "ne" + start_tile: 3 + end_tile: 3 + playback: PLAYBACK_NONE +} +animations { + id: "nw" + start_tile: 8 + end_tile: 8 + playback: PLAYBACK_NONE +} +animations { + id: "s" + start_tile: 2 + end_tile: 2 + playback: PLAYBACK_NONE +} +animations { + id: "se" + start_tile: 5 + end_tile: 5 + playback: PLAYBACK_NONE +} +animations { + id: "sw" + start_tile: 6 + end_tile: 6 + playback: PLAYBACK_NONE +} +animations { + id: "w" + start_tile: 7 + end_tile: 7 + playback: PLAYBACK_NONE +} diff --git a/game/src/entities/player.fnl b/game/src/entities/player.fnl index e6386a1..925fd70 100644 --- a/game/src/entities/player.fnl +++ b/game/src/entities/player.fnl @@ -31,7 +31,8 @@ (local height 15) (local player { :x 50 :y 50 :speed 80 :battery 100 :rot 0 - :vision-pts [] + :vision-pts [] ; the points that make a polygon around the player's cone of vision + :vision-hitboxes [] ; the hitboxes that are visible to the player's cone of vision :hitbox [50 50 width height] :ever-moved false ; useful for inital update }) @@ -74,6 +75,7 @@ (let [pts (self:cal-vision-points) (ox oy) (self:origin-pt) poly-pts [ox oy] + visable-hitboxes [] ] (each [_ pt (ipairs pts)] (let [ @@ -81,12 +83,14 @@ first-item (. items 1)] (if first-item (do + (table.insert visable-hitboxes (. first-item :item)) (table.insert poly-pts (. first-item :x1)) (table.insert poly-pts (. first-item :y1))) (do (table.insert poly-pts (. pt 1)) (table.insert poly-pts (. pt 2)))))) (set self.vision-pts poly-pts) + (set self.vision-hitboxes visable-hitboxes) )) diff --git a/game/src/levels/dev.fnl b/game/src/levels/dev.fnl index 2890ba9..757c3b9 100644 --- a/game/src/levels/dev.fnl +++ b/game/src/levels/dev.fnl @@ -61,7 +61,7 @@ camera walls fog-of-war - radar + ; radar (hud {: screen}) ] })] diff --git a/game/src/systems/fog_of_war.fnl b/game/src/systems/fog_of_war.fnl index ebd0a2d..848a318 100644 --- a/game/src/systems/fog_of_war.fnl +++ b/game/src/systems/fog_of_war.fnl @@ -7,7 +7,9 @@ (local fow { :player-vision-pts [] - :player-pos [0 0] + :player-vision-hitboxes [] + :player-pt [0 0] + :player-origin-pt [0 0] :font nil :canvas nil :main-canvas nil @@ -16,8 +18,11 @@ (lambda fow.load [self] (set self.canvas (love.graphics.newCanvas 1000 1000)) (beholder.observe "PLAYER.MOVED" (lambda [player] - (set self.player-pos [player.x player.y]) - (set self.player-vision-pts player.vision-pts))) + (let [(ox oy) (player:origin-pt)] + (set self.player-origin-pt [ox oy])) + (set self.player-pt [player.x player.y]) + (set self.player-vision-hitboxes player.vision-hitboxes) + (set self.player-vision-pts player.vision-pts))) (let [previousCanvas (love.graphics.getCanvas)] (love.graphics.setCanvas self.canvas) @@ -35,19 +40,25 @@ (lambda fow.draw15 [self] - (let [ - previousBlendMode (love.graphics.getBlendMode) - [x y] self.player-pos] + (let [previousBlendMode (love.graphics.getBlendMode)] (love.graphics.setBlendMode "replace") (love.graphics.setColor 0 0 0 0) ; transparent (love.graphics.push) - (love.graphics.translate (- x 3) (- y 7)) + (love.graphics.translate (unpack self.player-pt)) + (love.graphics.translate -3 -7) (love.graphics.polygon "fill" 3 11 3 17 7 21 17 21 21 17 21 11 17 7 7 7) (love.graphics.pop) ; draw the vision cone (when (> (length self.player-vision-pts) 2) (love.graphics.polygon "fill" self.player-vision-pts)) + ; draw the vision hitboxes + (each [_ hitbox (pairs self.player-vision-hitboxes)] + (love.graphics.rectangle "fill" hitbox.x hitbox.y hitbox.w hitbox.h)) (love.graphics.setBlendMode previousBlendMode)) + + (color.set-color :white) + (each [_ hitbox (pairs self.player-vision-hitboxes)] + (love.graphics.rectangle "line" hitbox.x hitbox.y hitbox.w hitbox.h)) (love.graphics.setCanvas self.main-canvas)) (lambda fow.draw80 [self] diff --git a/game/src/systems/radar.fnl b/game/src/systems/radar.fnl index 9506ae4..416718b 100644 --- a/game/src/systems/radar.fnl +++ b/game/src/systems/radar.fnl @@ -41,6 +41,7 @@ (set self.debug-pt [tip-x tip-y]))) (lambda radar.draw11 [self] + "Draw radar boxes" (color.set-color :light-pink) (each [_ box (pairs self.boxes)] (love.graphics.rectangle "line" box.x box.y box.w box.h)