Skip to content

Commit

Permalink
chore: update hy version to latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
pkulev committed Jul 23, 2022
1 parent b03de50 commit d62acfc
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 38 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ tanki = "tanki.__main__:main"

[tool.poetry.dependencies]
python = ">=3.9,<3.11"
hy = {version = "1.0a4", allow-prereleases = true}
hy = "^0.24.0"
raylib = "^4.0.0"
hyrule = "^0.1"
hyrule = "^0.2"

[tool.poetry.dev-dependencies]
jedhy = "^1"
Expand Down
2 changes: 1 addition & 1 deletion tanki/common.hy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(setv *resolution* (, 1024 768)
(setv *resolution* #(1024 768)
[*width* *height*] *resolution*
*debug* False
*music* True)
Expand Down
22 changes: 11 additions & 11 deletions tanki/controls.hy
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
;; ActionSet is mapping of some context/scheme identificator to allowed set of
;; actions in the terms of game. It can be created dynamically too (in future).

#@(dataclass
(defclass Action []
(setv ^str name None)))
(defclass [dataclass] Action []
(setv #^str name None))


(setv *controls*
Expand All @@ -25,12 +24,12 @@

:in-game
{:jump 7 #_pr.GAMEPAD-BUTTON-RIGHT-FACE-LEFT
:restart (, 8 :button :released)
:restart #(8 :button :released)
:pause "B"}}

"keyboard"
{:global
{:toggle-debug "D"
{:toggle-debug pr.KEY_D
:toggle-music "M"}

:menu
Expand All @@ -39,8 +38,9 @@

:in-game
{:jump pr.KEY_LEFT_SHIFT
:restart (, pr.KEY_R :key :released)
:toggle-pause pr.KEY_P}}})
:restart #( pr.KEY_R :key :released)
:toggle-device #( pr.KEY_I :key :released)
:toggle-pause #( pr.KEY_P :key :released)}}})


(defclass Device [])
Expand All @@ -56,8 +56,8 @@
(pr.is-key-released key))

(defn key? [self key mode]
(cond [(= mode :released) (self.key-released? key)]
[True (self.key-pressed? key)])))
(cond (= mode :released) (self.key-released? key)
True (self.key-pressed? key))))


(defclass Gamepad [Device]
Expand All @@ -74,8 +74,8 @@
;; (when (!= (pr.get-gamepad-button-pressed) -1)
;; (print (pr.get-gamepad-button-pressed)))
(print (pr.get-gamepad-button-pressed))
(cond [(= mode :released) (self.button-released? key)]
[True (self.button-pressed? key)])))
(cond (= mode :released) (self.button-released? key)
True (self.button-pressed? key))))


(defclass InputSystem []
Expand Down
4 changes: 2 additions & 2 deletions tanki/game.hy
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
(when (pr.is-key-released pr.KEY_D)
(setv common.*debug* (not common.*debug*)))

(when (pr.is-key-released pr.KEY_I)
(when (self.input.action? ':toggle-device ':in-game)
(self.input.set-next-device))

(when (pr.is-key-released pr.KEY_P)
(when (self.input.action? ':toggle-pause ':in-game)
(self.level.toggle-pause))

(when (self.input.action? ':restart ':in-game)
Expand Down
10 changes: 5 additions & 5 deletions tanki/level.hy
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
self.score 0
self.max-score 0

self.prepare-countdown (TextCountdown (, (, 0.4 "3")
(, 0.8 "2")
(, 1.2 "1")
(, 1.6 "GO")))
self.prepare-countdown (TextCountdown #(#(0.4 "3")
#(0.8 "2")
#(1.2 "1")
#(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"))
Expand Down Expand Up @@ -100,7 +100,7 @@
(self.obstacles.update)
(self.player.update)

(when (or (> (+ self.player.pos.y (* self.player.texture.height 2/3)) *height*)
(when (or (> (+ self.player.pos.y (* self.player.texture.height (/ 2 3))) *height*)
(self.collision-with-obstacle))
(setv self.game-over? True)
(when (> self.score (self.get-max-score))
Expand Down
22 changes: 9 additions & 13 deletions tanki/obstacles.hy
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
self.width width
self.height height))

#@(property
(defn rect [self]
(pr.Rectangle self.pos.x self.pos.y self.width self.height)))
(defn [property] rect [self]
(pr.Rectangle self.pos.x self.pos.y self.width self.height))

#@(property
(defn collision-rect [self]
self.rect))
(defn [property] collision-rect [self]
self.rect)

(defn randomize-size [self min-height max-height]
(setv self.height (random.randint min-height max-height)))
Expand Down Expand Up @@ -47,14 +45,12 @@
self.checked? False)
(self.randomize-sizes))

#@(property
(defn x [self]
self.bottom.pos.x))
(defn [property] x [self]
self.bottom.pos.x)

#@(x.setter
(defn x [self new-x]
(setv self.top.pos.x new-x
self.bottom.pos.x new-x)))
(defn [x.setter] x [self new-x]
(setv self.top.pos.x new-x
self.bottom.pos.x new-x))

(defn randomize-top [self]
(self.top.randomize-size self.min-top-height self.max-top-height))
Expand Down
6 changes: 3 additions & 3 deletions tanki/player.hy
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
self.weapon-ready? True)))

(defn get-fuel-consumption [self]
(cond [(< self.fuel 10) 1.2]
[(< self.fuel 70) 1.4]
[True 1.5]))
(cond (< self.fuel 10) 1.2
(< self.fuel 70) 1.4
True 1.5))

(defn set-fuel-depleted [self val]
"Updates fuel meter color to denote that engine is not working."
Expand Down
2 changes: 1 addition & 1 deletion tanki/ui.hy
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
self.label label
self.font-size font-size
self.label-color label-color
self.label-size-x (if label (pr.measure-text label font-size))
self.label-size-x (when label (pr.measure-text label font-size))
self.spacing spacing))

(defn update [self val]
Expand Down

0 comments on commit d62acfc

Please sign in to comment.