From cbb2602ed9dedf973ddbf6d769b11c666de2ea22 Mon Sep 17 00:00:00 2001 From: Gene Pasquet Date: Thu, 15 May 2025 17:17:54 +0200 Subject: WIP --- src/macroknight/game.hy | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/macroknight/game.hy b/src/macroknight/game.hy index 99dc69f..1c10c95 100644 --- a/src/macroknight/game.hy +++ b/src/macroknight/game.hy @@ -13,6 +13,8 @@ (setv TILE_SCALING 1) (setv TILE_SIZE (* TILE_SCALING 16)) +(setv MACRO_STEP_WAIT 300) +(setv MACRO_COOLDOWN 5000) (setv screen (pygame.display.set_mode #((* TILE_SCALING 640) (* TILE_SCALING 480)))) (setv clock (pygame.time.Clock)) @@ -32,6 +34,7 @@ (setv player (Player 1 (get tileset.tiles 28) TILE_SIZE #* player-pos)) (.append sprites-group player) (setv macro-input-mode False) +(setv macro-wait-time 0) (setv macro-commands [None None None]) (for [tiledef (enumerate (.tiles (get level.layers 0)))] @@ -48,9 +51,9 @@ (if macro-input-mode (when (in event.key [pygame.K_a pygame.K_w pygame.K_a pygame.K_s pygame.K_d]) (setv (get macro-commands (.index macro-commands None)) event.key)) - (case event.key - pygame.K_SPACE (setv macro-input-mode True) - else (.append ongoing_inputs event.key)))) + (if (and (= event.key pygame.K_SPACE) (= macro-wait-time 0)) + (setv macro-input-mode True) + (.append ongoing_inputs event.key)))) pygame.KEYUP (when (in event.key ongoing_inputs) (.remove ongoing_inputs event.key)))) @@ -73,14 +76,16 @@ (do (let [#(command-id command) (get (lfor command (enumerate macro-commands) :if (get command 1) command) 0)] (case command - pygame.K_a (.move player #((neg TILE_SIZE) 0)) - pygame.K_s (.move player #(0 1)) + pygame.K_a (.move player #((neg (* 2 TILE_SIZE)) 0)) + pygame.K_s (.move player #(0 TILE_SIZE)) pygame.K_w (.move player #(0 (neg (/ player.MAX_JUMPING 2)))) - pygame.K_d (.move player #(TILE_SIZE 0))) + pygame.K_d (.move player #((* 2 TILE_SIZE) 0))) (if (= command-id (- (len macro-commands) 1)) (do (setv macro-commands [None None None]) - (setv macro-input-mode False)) - (setv (get macro-commands command-id) None)))) + (setv macro-input-mode False) + (setv macro-wait-time (+ (pygame.time.get_ticks) MACRO_COOLDOWN))) + (setv (get macro-commands command-id) None))) + (pygame.time.wait MACRO_STEP_WAIT)) ;; If there's still space in the commands list (for [#(num command) (enumerate macro-commands)] @@ -93,12 +98,18 @@ None (draw-tile screen tileset 725 x-pos 5))))) ;; Not in macro mode - (do (for [inp ongoing_inputs] - (case inp - pygame.K_a (.move player #((neg player.SPEED) 0)) - pygame.K_s (.move player #(0 1)) - pygame.K_w (.jump player) - pygame.K_d (.move player #(player.SPEED 0)))) + (do + (when (> macro-wait-time 0) + (let [progress (round (* 3 (/ (- (pygame.time.get_ticks) macro-wait-time) MACRO_COOLDOWN)))] + (for [indicator (range 3)] + (draw-tile + screen tileset 725 )))) + (for [inp ongoing_inputs] + (case inp + pygame.K_a (.move player #((neg player.SPEED) 0)) + pygame.K_s (.move player #(0 1)) + pygame.K_w (.jump player) + pygame.K_d (.move player #(player.SPEED 0)))) (when (any ongoing_inputs) (for [sprite sprites-group] @@ -118,6 +129,11 @@ (.blit screen sprite.surf sprite.rect)) (pygame.display.flip) + + (when (or (= 0 macro-wait-time) + (< (- (pygame.time.get_ticks) macro-wait-time) 0)) + (setv macro-wait-time 0)) + (.tick clock 60)) (pygame.quit) -- cgit v1.2.3