aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGene Pasquet <dev@etenil.net>2025-05-18 09:53:38 +0100
committerGene Pasquet <dev@etenil.net>2025-05-18 09:53:38 +0100
commitdfaf786c1a7702f83de53d18fc5248117abfebc2 (patch)
tree27ec5f1123e0a6ab52517adf8fb3b84b4243a0dc /src
parente30b2a81b48f5e86474aa2c38d7034d63c0b7c4e (diff)
Licensing etc.
Diffstat (limited to 'src')
-rw-r--r--src/macroknight/entities.hy18
-rw-r--r--src/macroknight/game.hy58
-rw-r--r--src/macroknight/systems.hy15
-rw-r--r--src/macroknight/text.hy15
-rw-r--r--src/macroknight/tiles.hy15
-rw-r--r--src/macroknight/utils.hy15
6 files changed, 125 insertions, 11 deletions
diff --git a/src/macroknight/entities.hy b/src/macroknight/entities.hy
index 2ba77ea..b171069 100644
--- a/src/macroknight/entities.hy
+++ b/src/macroknight/entities.hy
@@ -1,3 +1,18 @@
+;;; Copyright (C) 2025 Gene Pasquet
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
(require hyrule [case])
(import pygame.sprite [Sprite]
pygame [Surface]
@@ -5,6 +20,8 @@
utils [neg merge-moves Direction]
enum [Enum])
+(defclass PlayerKilled [Exception])
+
(defclass Entity [Sprite]
;;; Game entity
(setv _fixed False)
@@ -149,6 +166,7 @@
(when (and self.attacking (> ticks self.animate-end))
(setv self.animate-end 0)
(setv self.attacking False)
+ (raise PlayerKilled)
(.blit self._surf (get self.tiles 0) #(0 0)))
(setv self._disp_surf
diff --git a/src/macroknight/game.hy b/src/macroknight/game.hy
index 7709f41..8675f81 100644
--- a/src/macroknight/game.hy
+++ b/src/macroknight/game.hy
@@ -1,8 +1,23 @@
+;;; Copyright (C) 2025 Gene Pasquet
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
(require hy)
(require hyrule *)
(import pygame
pytmx.util_pygame [load_pygame]
- entities [Player LevelTile Goal Enemy]
+ entities [Player LevelTile Goal Enemy PlayerKilled]
tiles [TileSet draw-tile]
utils [neg]
text [render-text]
@@ -19,14 +34,31 @@
(setv screen (pygame.display.set_mode #((* TILE_SCALING 640) (* TILE_SCALING 480))))
(setv clock (pygame.time.Clock))
(setv tileset (TileSet "assets/monochrome-transparent.png" TILE_SCALING TILE_SIZE TILE_SIZE 1))
-(setv levels [(load_pygame "assets/level-3.tmx")
- (load_pygame "assets/level-0.tmx")
+(setv levels [(load_pygame "assets/level-0.tmx")
(load_pygame "assets/level-1.tmx")
- (load_pygame "assets/level-2.tmx")])
+ (load_pygame "assets/level-2.tmx")
+ (load_pygame "assets/level-3.tmx")])
(setv level-id 0)
+(setv game-won False)
+(setv game-lost False)
(defn abs-to-tile-index [abs-id]
(int (floor (/ abs-id TILE_SIZE))))
+
+(do ;; Help screen
+ (.fill screen "#000000")
+
+ (render-text screen tileset "MACROKNIGHT" 15 10)
+ (render-text screen tileset "GENE AND OWEN PASQUET" 10 2)
+
+ (render-text screen tileset "CONTROLS" 16 22)
+ (render-text screen tileset "WASD TO MOVE" 14 25)
+ (render-text screen tileset "SPACE TO ATTACK" 13 26)
+ (render-text screen tileset "ENTER FOR MACRO" 13 27)
+
+ (pygame.display.flip)
+ (pygame.time.wait 3000))
+
(setv game-running True)
(while game-running
@@ -88,9 +120,9 @@
(setv running False)
(setv game-running False))
(if macro-input-mode
- (when (in event.key [pygame.K_a pygame.K_w pygame.K_a pygame.K_s pygame.K_d pygame.K_RETURN])
+ (when (in event.key [pygame.K_a pygame.K_w pygame.K_a pygame.K_s pygame.K_d pygame.K_SPACE])
(setv (get macro-commands (.index macro-commands None)) event.key))
- (if (and (= event.key pygame.K_SPACE) (= macro-wait-time 0))
+ (if (and (= event.key pygame.K_RETURN) (= macro-wait-time 0))
(setv macro-input-mode True)
(.append ongoing_inputs event.key))))
pygame.KEYUP (when (in event.key ongoing_inputs)
@@ -118,7 +150,7 @@
pygame.K_s (.move player #(0 TILE_SIZE))
pygame.K_w (.move player #(0 (neg (/ player.MAX_JUMPING 2))))
pygame.K_d (.move player #((* 2 TILE_SIZE) 0))
- pygame.K_RETURN (.attack player))
+ pygame.K_SPACE (.attack player))
(if (= command-id (- (len macro-commands) 1))
(do
@@ -136,7 +168,7 @@
pygame.K_d (draw-tile screen tileset 1058 x-pos 5)
pygame.K_s (draw-tile screen tileset 1059 x-pos 5)
pygame.K_a (draw-tile screen tileset 1060 x-pos 5)
- pygame.K_RETURN (draw-tile screen tileset 329 x-pos 5)
+ pygame.K_SPACE (draw-tile screen tileset 329 x-pos 5)
None (draw-tile screen tileset 725 x-pos 5)))))
;; Not in macro mode
@@ -151,7 +183,7 @@
pygame.K_s (.move player #(0 1))
pygame.K_w (.jump player)
pygame.K_d (.move player #(player.SPEED 0))
- pygame.K_RETURN (.attack player)))
+ pygame.K_SPACE (.attack player)))
(try
(when (any ongoing_inputs)
@@ -169,7 +201,11 @@
(except [GoalHit]
(setv level-id (+ level-id 1))
(setv running False)
- (setv game-running (< level-id (len levels)))))
+ (when (>= level-id (len levels))
+ (setv game-running False)
+ (setv game-won True)))
+ (except [PlayerKilled]
+ (setv running False)))
(.flush player)))
@@ -185,7 +221,7 @@
(.tick clock 60)))
-(do
+(when game-won
(.fill screen "#000000")
(render-text screen
diff --git a/src/macroknight/systems.hy b/src/macroknight/systems.hy
index f503642..91d4e8c 100644
--- a/src/macroknight/systems.hy
+++ b/src/macroknight/systems.hy
@@ -1,3 +1,18 @@
+;;; Copyright (C) 2025 Gene Pasquet
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
(import utils [sub-points distance Direction])
;; Define systems here
diff --git a/src/macroknight/text.hy b/src/macroknight/text.hy
index 1b631c1..9608bf9 100644
--- a/src/macroknight/text.hy
+++ b/src/macroknight/text.hy
@@ -1,3 +1,18 @@
+;;; Copyright (C) 2025 Gene Pasquet
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
(import tiles [draw-tile])
(defn render-text [surf tileset text x y]
diff --git a/src/macroknight/tiles.hy b/src/macroknight/tiles.hy
index 2345e17..81e72e5 100644
--- a/src/macroknight/tiles.hy
+++ b/src/macroknight/tiles.hy
@@ -1,3 +1,18 @@
+;;; Copyright (C) 2025 Gene Pasquet
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
(import pygame)
(defclass TileSet []
diff --git a/src/macroknight/utils.hy b/src/macroknight/utils.hy
index 5de8887..05412e8 100644
--- a/src/macroknight/utils.hy
+++ b/src/macroknight/utils.hy
@@ -1,3 +1,18 @@
+;;; Copyright (C) 2025 Gene Pasquet
+;;;
+;;; This program is free software: you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation, either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
(import enum [Enum]
math [sqrt])