Skip to content

Commit

Permalink
main: Improve memory usage and performance in a couple of places
Browse files Browse the repository at this point in the history
  • Loading branch information
daviwil committed Apr 6, 2022
1 parent 62a8155 commit 8e7cefc
Showing 1 changed file with 53 additions and 48 deletions.
101 changes: 53 additions & 48 deletions modules/main.msc
Original file line number Diff line number Diff line change
Expand Up @@ -215,45 +215,46 @@

(if (not (equal? (player-state (game-player current-game))
'alive))
(end-game current-game (player-state (game-player current-game))))

;; Update bullets
(game-bullets-set! current-game
(update-bullets (game-bullets current-game)
time-delta))

;; Spawn and update enemies
(game-enemies-set! current-game
(spawn-enemies (game-enemies current-game)
(game-level-time current-game)
max-level-time
time-delta
window))
(game-enemies-set! current-game
(update-enemies (game-enemies current-game)
(lambda (bullet)
(game-bullets-set! current-game
(cons bullet
(game-bullets current-game))))
time-delta
window))

;; Siphon energy if necessary
(if (controller-siphon (game-controller current-game))
(siphon-energy current-game
(game-player current-game)
(game-enemies current-game)
time-delta))

;; Check for collisions
(check-collisions (game-player current-game)
(game-enemies current-game)
(game-bullets current-game)
(lambda (enemy)
;; Give the player some score
(game-score-total-set! current-game
(+ (game-score-total current-game)
(enemy-score enemy)))))
(end-game current-game (player-state (game-player current-game)))
(begin

;; Update bullets
(game-bullets-set! current-game
(update-bullets (game-bullets current-game)
time-delta))

;; Spawn and update enemies
(game-enemies-set! current-game
(spawn-enemies (game-enemies current-game)
(game-level-time current-game)
max-level-time
time-delta
window))
(game-enemies-set! current-game
(update-enemies (game-enemies current-game)
(lambda (bullet)
(game-bullets-set! current-game
(cons bullet
(game-bullets current-game))))
time-delta
window))

;; Siphon energy if necessary
(if (controller-siphon (game-controller current-game))
(siphon-energy current-game
(game-player current-game)
(game-enemies current-game)
time-delta))

;; Check for collisions
(check-collisions (game-player current-game)
(game-enemies current-game)
(game-bullets current-game)
(lambda (enemy)
;; Give the player some score
(game-score-total-set! current-game
(+ (game-score-total current-game)
(enemy-score enemy)))))))

;; Update the HUD
(update-hud current-game time-delta))
Expand Down Expand Up @@ -341,6 +342,14 @@
(next-event (input-event-take input-state)))
t)))

(define menu-screen-lines
(list "Instructions:"
"WSAD moves your ship"
"J siphons energy / K fires the weapon"
"All actions drain energy, try not to deplete!"
""
"(C) 2022 By David Wilson / Flux Harmonic"))

(define (menu-renderer renderer)
(render-text renderer
result-font
Expand All @@ -363,22 +372,18 @@
(/ quit-width 2))
350)

(let next-line ((y 400)
(lines
(list "Instructions:"
"WSAD moves your ship"
"J siphons energy / K fires the weapon"
"All actions drain energy, try not to deplete!"
""
"(C) 2022 By David Wilson / Flux Harmonic")))
(let next-line ((renderer renderer)
(y 400)
(lines menu-screen-lines))
(if (pair? lines)
(begin
(render-text renderer
small-font
(car lines)
200
y)
(next-line (+ y 50)
(next-line renderer
(+ y 50)
(cdr lines))))))

(define current-updater menu-updater)
Expand Down

0 comments on commit 8e7cefc

Please sign in to comment.