~alect/secret-santa-jam-2022

a743e7848f3ba75497ece9610d3b87b22a9ea97a — alectroemel 1 year, 4 months ago 0575220 main
add music
M assets/audio/background.mp3 => assets/audio/background.mp3 +0 -0
A assets/audio/sfx-death.mp3 => assets/audio/sfx-death.mp3 +0 -0
A assets/audio/sfx-drone.mp3 => assets/audio/sfx-drone.mp3 +0 -0
M assets/world.ldtk => assets/world.ldtk +26 -23
@@ 8505,20 8505,6 @@
					"gridTiles": [],
					"entityInstances": [
						{
							"__identifier": "Spawn_Point",
							"__grid": [38,6],
							"__pivot": [0,0],
							"__tags": [],
							"__tile": null,
							"__smartColor": "#94D2D9",
							"iid": "aa811920-7820-11ed-bcde-45ca5c2acf44",
							"width": 8,
							"height": 8,
							"defUid": 35,
							"px": [304,48],
							"fieldInstances": []
						},
						{
							"__identifier": "Wreath",
							"__grid": [14,17],
							"__pivot": [0.5,0.5],


@@ 8591,6 8577,20 @@
								{ "__identifier": "laser", "__value": 0, "__type": "Float", "__tile": null, "defUid": 61, "realEditorValues": [] },
								{ "__identifier": "laser_active", "__value": true, "__type": "Bool", "__tile": null, "defUid": 62, "realEditorValues": [] }
							]
						},
						{
							"__identifier": "Spawn_Point",
							"__grid": [38,5],
							"__pivot": [0,0],
							"__tags": [],
							"__tile": null,
							"__smartColor": "#94D2D9",
							"iid": "ce29fa80-7820-11ed-ab92-71f855cd447a",
							"width": 8,
							"height": 8,
							"defUid": 35,
							"px": [304,40],
							"fieldInstances": []
						}
					]
				},


@@ 8622,9 8622,9 @@
						0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,
						0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
						1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,
						0,0,0,0,0,1,0,0,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,
						0,1,1,0,0,0,0,1,1,1,1,0,0,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,
						0,0,0,0,0,0,1,1,2,2,2,2,1,1,1,1,0,0,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
						0,1,1,0,0,1,0,0,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,
						0,1,1,0,0,0,1,1,1,1,1,0,0,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,
						0,0,0,0,0,0,1,1,2,2,2,1,1,1,1,1,0,0,1,1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
						0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,1,2,0,0,0,0,0,0,0,0,0,
						0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,2,0,0,0,0,
						0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,1,1,0,0,0,1,1,


@@ 8701,8 8701,10 @@
						{ "px": [184,64], "src": [0,32], "f": 0, "t": 64, "d": [20,343] },
						{ "px": [176,72], "src": [0,32], "f": 0, "t": 64, "d": [20,382] },
						{ "px": [184,72], "src": [0,32], "f": 0, "t": 64, "d": [20,383] },
						{ "px": [296,72], "src": [0,32], "f": 0, "t": 64, "d": [20,397] },
						{ "px": [304,72], "src": [0,32], "f": 0, "t": 64, "d": [20,398] },
						{ "px": [312,72], "src": [0,32], "f": 0, "t": 64, "d": [20,399] },
						{ "px": [296,80], "src": [0,32], "f": 0, "t": 64, "d": [20,437] },
						{ "px": [304,80], "src": [0,32], "f": 0, "t": 64, "d": [20,438] },
						{ "px": [312,80], "src": [0,32], "f": 0, "t": 64, "d": [20,439] },
						{ "px": [304,88], "src": [0,32], "f": 0, "t": 64, "d": [20,478] },


@@ 8807,13 8809,14 @@
						{ "px": [24,64], "src": [0,16], "f": 0, "t": 32, "d": [18,323] },
						{ "px": [32,64], "src": [0,8], "f": 1, "t": 16, "d": [18,324] },
						{ "px": [192,64], "src": [0,16], "f": 1, "t": 32, "d": [18,344] },
						{ "px": [288,64], "src": [0,16], "f": 0, "t": 32, "d": [18,356] },
						{ "px": [0,72], "src": [0,8], "f": 1, "t": 16, "d": [18,360] },
						{ "px": [24,72], "src": [0,8], "f": 0, "t": 16, "d": [18,363] },
						{ "px": [32,72], "src": [0,16], "f": 1, "t": 32, "d": [18,364] },
						{ "px": [192,72], "src": [0,16], "f": 1, "t": 32, "d": [18,384] },
						{ "px": [248,72], "src": [0,16], "f": 0, "t": 32, "d": [18,391] },
						{ "px": [256,72], "src": [0,16], "f": 1, "t": 32, "d": [18,392] },
						{ "px": [296,72], "src": [0,16], "f": 0, "t": 32, "d": [18,397] },
						{ "px": [288,72], "src": [0,8], "f": 0, "t": 16, "d": [18,396] },
						{ "px": [0,80], "src": [0,8], "f": 1, "t": 16, "d": [18,400] },
						{ "px": [24,80], "src": [0,8], "f": 0, "t": 16, "d": [18,403] },
						{ "px": [32,80], "src": [0,16], "f": 1, "t": 32, "d": [18,404] },


@@ 8886,7 8889,6 @@
						{ "px": [264,80], "src": [8,0], "f": 0, "t": 1, "d": [16,433] },
						{ "px": [272,80], "src": [8,0], "f": 0, "t": 1, "d": [16,434] },
						{ "px": [280,80], "src": [8,0], "f": 0, "t": 1, "d": [16,435] },
						{ "px": [288,80], "src": [8,0], "f": 0, "t": 1, "d": [16,436] },
						{ "px": [72,136], "src": [16,0], "f": 0, "t": 2, "d": [16,689] },
						{ "px": [0,144], "src": [8,0], "f": 0, "t": 1, "d": [16,720] },
						{ "px": [8,144], "src": [16,0], "f": 0, "t": 2, "d": [16,721] },


@@ 8929,9 8931,10 @@
						{ "px": [72,32], "src": [0,0], "f": 1, "t": 0, "d": [9,169] },
						{ "px": [24,48], "src": [0,0], "f": 0, "t": 0, "d": [9,243] },
						{ "px": [32,48], "src": [0,0], "f": 1, "t": 0, "d": [9,244] },
						{ "px": [288,56], "src": [0,0], "f": 0, "t": 0, "d": [9,316] },
						{ "px": [296,56], "src": [0,0], "f": 1, "t": 0, "d": [9,317] },
						{ "px": [248,64], "src": [0,0], "f": 0, "t": 0, "d": [9,351] },
						{ "px": [256,64], "src": [0,0], "f": 1, "t": 0, "d": [9,352] },
						{ "px": [296,64], "src": [0,0], "f": 0, "t": 0, "d": [9,357] },
						{ "px": [64,136], "src": [0,0], "f": 0, "t": 0, "d": [9,688] },
						{ "px": [80,136], "src": [0,0], "f": 1, "t": 0, "d": [9,690] },
						{ "px": [208,160], "src": [0,0], "f": 0, "t": 0, "d": [9,826] },


@@ 8940,8 8943,9 @@
						{ "px": [272,160], "src": [0,0], "f": 1, "t": 0, "d": [9,834] },
						{ "px": [144,168], "src": [0,0], "f": 1, "t": 0, "d": [9,858] },
						{ "px": [168,168], "src": [0,0], "f": 0, "t": 0, "d": [9,861] },
						{ "px": [296,64], "src": [40,8], "f": 1, "t": 21, "d": [28,357] },
						{ "px": [256,80], "src": [40,8], "f": 1, "t": 21, "d": [28,432] },
						{ "px": [296,80], "src": [40,8], "f": 0, "t": 21, "d": [28,437] },
						{ "px": [288,80], "src": [40,8], "f": 0, "t": 21, "d": [28,436] },
						{ "px": [24,144], "src": [40,8], "f": 0, "t": 21, "d": [28,723] },
						{ "px": [32,168], "src": [40,8], "f": 1, "t": 21, "d": [28,844] },
						{ "px": [64,168], "src": [40,8], "f": 0, "t": 21, "d": [28,848] },


@@ 8973,7 8977,6 @@
						{ "px": [288,144], "src": [72,8], "f": 0, "t": 25, "d": [44,756] },
						{ "px": [288,152], "src": [72,8], "f": 0, "t": 25, "d": [44,796] },
						{ "px": [272,72], "src": [64,16], "f": 0, "t": 40, "d": [42,394] },
						{ "px": [280,72], "src": [64,16], "f": 0, "t": 40, "d": [42,395] },
						{ "px": [48,160], "src": [64,16], "f": 0, "t": 40, "d": [42,806] },
						{ "px": [96,160], "src": [64,16], "f": 0, "t": 40, "d": [42,812] },
						{ "px": [104,160], "src": [64,16], "f": 0, "t": 40, "d": [42,813] },


@@ 8993,7 8996,7 @@
						{ "px": [232,160], "src": [56,16], "f": 0, "t": 39, "d": [47,829] },
						{ "px": [280,160], "src": [56,16], "f": 0, "t": 39, "d": [47,835] },
						{ "px": [152,168], "src": [56,16], "f": 0, "t": 39, "d": [47,859] },
						{ "px": [288,72], "src": [72,16], "f": 0, "t": 41, "d": [48,396] },
						{ "px": [280,72], "src": [72,16], "f": 0, "t": 41, "d": [48,395] },
						{ "px": [56,160], "src": [72,16], "f": 0, "t": 41, "d": [48,807] },
						{ "px": [200,160], "src": [72,16], "f": 0, "t": 41, "d": [48,825] },
						{ "px": [248,160], "src": [72,16], "f": 0, "t": 41, "d": [48,831] },

M src/components.janet => src/components.janet +4 -0
@@ 4,6 4,7 @@
(def-component player
  :run-sfx (any)
  :jump-sfx (any)
  :death-sfx (any)
  :run-sfx-t :number)

(fsm/define


@@ 104,3 105,6 @@

(def-tag from-ldtk-world)
(def-tag house-smoke)

(def-component music :stream (any))
(def-tag wreath-sfx)

M src/entities.janet => src/entities.janet +14 -1
@@ 9,6 9,7 @@
              (player
               :run-sfx (load-sound "./assets/audio/sfx-run.mp3")
               :jump-sfx (load-sound "./assets/audio/sfx-jump.mp3")
               :death-sfx (load-sound "./assets/audio/sfx-death.mp3")
               :run-sfx-t 0)
              (direction-controller :right)
              (jump-controller :impulse -3.4


@@ 65,7 66,14 @@
              (from-ldtk-world)
              (aseprite/init-animation-machine
               "./assets/export/" "wreath.json"
               {:x 0 :y 0} :idle)))
               {:x 0 :y 0} :idle))

  (let [stream (load-music-stream "./assets/audio/sfx-drone.mp3")]
    (play-music-stream stream)
    (add-entity world
                (wreath-sfx)
                (from-ldtk-world)
                (music :stream stream))))

(defn create-spawn-point [world x y]
  (add-entity world


@@ 170,3 178,8 @@
       (load-texture)
       (picture :texture)
       (add-entity wld)))

(defn create-bg-music [wld]
  (let [stream (load-music-stream "./assets/audio/background.mp3")]
    (play-music-stream stream)
    (add-entity wld (music :stream stream))))

M src/main.janet => src/main.janet +31 -10
@@ 264,7 264,8 @@
        (:s ldtk-world)
        (put pos :y (- GAME_SCREEN_HEIGHT 1 (colbox :height))))))

(defn santa-respawn [wld anim-mach pos vel spawn-point-pos]
(defn santa-respawn [wld anim-mach pos vel spawn-point-pos plyr]
  (play-sound (plyr :death-sfx))
  # (create-hit-freeze wld)
  (:die anim-mach)



@@ 295,7 296,7 @@
   spawn-points [:spawn-point :position]
   wld :world}
  (when-let [has-player (> (length players) 0)
             [[_ pos vel colbox anim-mach]] players
             [[plyr pos vel colbox anim-mach]] players

             has-spawn-point (> (length spawn-points) 0)
             [_ spawn-point-pos] (first spawn-points)


@@ 305,7 306,7 @@
                           (collide? :right lvl pos colbox :grid-id 2)
                           (collide? :up lvl pos colbox :grid-id 2)
                           (collide? :down lvl pos colbox :grid-id 2))]
    (santa-respawn wld anim-mach pos vel spawn-point-pos)))
    (santa-respawn wld anim-mach pos vel spawn-point-pos plyr)))

(def-system debug-player
  {[[ldtk-world]] [:ldtk-world]}


@@ 352,13 353,14 @@

(freeze/def-freeze-system jump-off-wreath-drones [:hit-freeze]
  {wreaths [:wreath :position]
   [[pos vel colbox jump-ctl _]] [:position :velocity :collision-box :jump-controller :player]}
   [[pos vel colbox jump-ctl plyr]] [:position :velocity :collision-box :jump-controller :player]}
  (when (and (pos? (vel :y))
             (any? (map |(> 12 (-> (:clone ($ 1))
                                   (:add 4)
                                   (:distance pos)))
                        wreaths)))
    # (freeze! :frames 20)
    (play-sound (plyr :jump-sfx))
    (put vel :y (* 1.6 (jump-ctl :impulse)))))

(defn angle-to-rad [angle]


@@ 387,7 389,7 @@
                                      ;triangle-points)))

(def-system collide-with-wreath-laser
  {[[pos vel colbox anim-mach _]] [:position :velocity :collision-box :animation-machine :player]
  {[[pos vel colbox anim-mach plyr]] [:position :velocity :collision-box :animation-machine :player]
   spawn-points [:spawn-point :position]
   wreaths [:wreath :position]
   wld :world}


@@ 398,7 400,7 @@
           :while (not= :dead (anim-mach :current))
           :when (and (wr :laser-active)
                      (rectangle-triangle-overlap? pos colbox triangle-pos))]
      (santa-respawn wld anim-mach pos vel spawn-point-pos))))
      (santa-respawn wld anim-mach pos vel spawn-point-pos plyr))))

(def-system draw-wreath-laser
  {wreaths [:wreath :position]}


@@ 419,22 421,40 @@
    (when (< (:distance pos house-smoke-pos) 16)
      (goto :game-over))))

(def-system update-music
  {streams [:music]}
  (each [mus] streams
    (update-music-stream (mus :stream))))

(def-system update-wreath-sfx
  {wreaths [:wreath :position]
   streams [:music :wreath-sfx]}
  (each [mus] streams
    (if (empty? wreaths)
      (if (music-stream-playing? (mus :stream))
        (pause-music-stream (mus :stream)))

      (if (not (music-stream-playing? (mus :stream)))
        (resume-music-stream (mus :stream))))))


(crafty-gamestate :main-game
   # Entities
   (let [ldtk-world (create-ldtk-world world
                                       :asset-dir "./assets/"
                                       :filename "./assets/world.ldtk"
                                       :level 22) # 22
         # spawn-point (:get-spawn-point ldtk-world)
                                       :level 59) # 22

        ]
     (create-player world
                    :width 12 :height 12
                    :x 20 #(spawn-point :x)
                    :y 80 #(spawn-point :y)
                    :y 100 #(spawn-point :y)
                    )
     )

   (create-snow-emitter world -100 0 (+ 100 GAME_SCREEN_WIDTH) 1)
   (create-bg-music world)

   # Update Systems
   (register-system world


@@ 454,7 474,8 @@
                    update-player-run-particles
                    transition-between-ldtk-levels
                    check-game-over
                    )
                    update-music
                    update-wreath-sfx)

   # Draw Systems
   (register-system world