Skip to content

Commit

Permalink
Fix incorrect paths for resources
Browse files Browse the repository at this point in the history
  • Loading branch information
pkulev committed Jan 6, 2025
1 parent ed92c05 commit 721d681
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
8 changes: 5 additions & 3 deletions tanki/background.hy
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(import pyray :as pr)

(import tanki.common :as tc)

(defclass Background []
"Background with parallax."

Expand All @@ -9,9 +11,9 @@
self.scrolling-mid 0.0
self.scrolling-fore 0.0

self.background (pr.load-texture f"assets/gfx/background-{name}.png")
self.midround (pr.load-texture f"assets/gfx/midground-{name}.png")
self.foreground (pr.load-texture f"assets/gfx/foreground-{name}.png")))
self.background (tc.load-texture f"background-{name}.png")
self.midround (tc.load-texture f"midground-{name}.png")
self.foreground (tc.load-texture f"foreground-{name}.png")))

(defn reset [self]
(setv self.scrolling-back 0.0
Expand Down
20 changes: 19 additions & 1 deletion tanki/common.hy
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
(import pathlib [Path])

(import pyray :as pr)


(setv *resolution* #(1024 768)
[*width* *height*] *resolution*
*debug* False
*music* True)
*music* True
*assets-dir* (/ (. (Path __file__) parent parent) "assets"))

(defn clamp [val min-val max-val]
(get (sorted [min-val val max-val]) 1))

(defn res [#* parts]
(/ *assets-dir* #* parts))

(defn load-texture [#* parts]
(pr.load-texture (str (res "gfx" #* parts))))

(defn load-sound [#* parts]
(pr.load-sound (str (res "snd" #* parts))))

(defn load-music-stream [#* parts]
(pr.load-music-stream (str (res "snd" #* parts))))
3 changes: 2 additions & 1 deletion tanki/game.hy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(import tanki [common]
tanki.background [Background]
tanki.common [*width* *height*]
tanki.common :as tc
tanki.controls [InputSystem]
tanki.level [Level]
tanki.player [Player])
Expand All @@ -23,7 +24,7 @@
(setv self.state :in-game
self.input (InputSystem)
self.level (Level (get self.level-names 0))
self.music (pr.load-music-stream "assets/snd/theme.wav")))
self.music (tc.load-music-stream "theme.wav")))

(defn restart-level [self]
(setv self.level (Level self.level.name)))
Expand Down
3 changes: 2 additions & 1 deletion tanki/level.hy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

(import tanki.background [Background]
tanki.common [*width* *height*]
tanki.common :as tc
tanki.obstacles [ObstaclePool]
tanki.player [Player])

Expand Down Expand Up @@ -64,7 +65,7 @@
#(1.6 "GO")))
self.obstacles (ObstaclePool :gap (int (+ self.player.texture.height
(/ self.player.texture.height 2))))
self.collision-sound (pr.load-sound "assets/snd/take-damage.wav"))
self.collision-sound (tc.load-sound "take-damage.wav"))
(pr.set-sound-volume self.collision-sound 0.2))

;; save to file
Expand Down
15 changes: 8 additions & 7 deletions tanki/player.hy
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(import pyray :as pr)

(import tanki [common ui])
(import tanki [ui])
(import tanki.common :as tc)


(defclass JetpackSound []

(defn __init__ [self]
(setv self.sound (pr.load-music-stream "assets/snd/jetpack-cut.wav")
(setv self.sound (tc.load-music-stream "jetpack-cut.wav")
self.length (pr.get-music-time-length self.sound))
(pr.set-music-volume self.sound 0.1)
(pr.play-music-stream self.sound)
Expand Down Expand Up @@ -42,8 +43,8 @@
self.fall-speed 4
self.jump-speed 10
self.weapon-cooldown 10
self.texture (pr.load-texture "assets/gfx/player.png")
self.fuel-depletion-sound (pr.load-sound "assets/snd/select.wav")
self.texture (tc.load-texture "player.png")
self.fuel-depletion-sound (tc.load-sound "select.wav")
self.jetpack-sound (JetpackSound)
self.collision-rect (pr.Rectangle (+ pos.x 10)
(+ pos.y 10)
Expand Down Expand Up @@ -81,7 +82,7 @@
(defn update [self]
(+= self.pos.y self.fall-speed)

(setv self.fuel (common.clamp (+ self.fuel 0.55) 0 100))
(setv self.fuel (tc.clamp (+ self.fuel 0.55) 0 100))
;; Recharched!
(when (> self.fuel 25)
(self.set-fuel-depleted False))
Expand Down Expand Up @@ -127,7 +128,7 @@
(when (> self.fuel 0)
(self.jetpack-sound.resume)
(-= self.pos.y self.jump-speed)
(setv self.fuel (common.clamp (- self.fuel (self.get-fuel-consumption)) 0 100)))
(setv self.fuel (tc.clamp (- self.fuel (self.get-fuel-consumption)) 0 100)))

;; TODO: add depletion sound
(when (= self.fuel 0)
Expand All @@ -141,5 +142,5 @@
(pr.draw-texture-ex self.texture self.pos self.rotation 1.0 pr.RAYWHITE)
(self.fuel-bar.render)

(when common.*debug*
(when tc.*debug*
(pr.draw-rectangle-lines-ex self.collision-rect 1 pr.RED))))

0 comments on commit 721d681

Please sign in to comment.