summaryrefslogtreecommitdiff
path: root/comp/lucas-standen-NEA/writeup2/examples/spaceinvaders.zpy
diff options
context:
space:
mode:
authorthing 1 <thing1@seacrossedlovers.xyz>2024-12-05 12:04:08 +0000
committerthing 1 <thing1@seacrossedlovers.xyz>2024-12-05 12:04:08 +0000
commit68baa2efd72cb150dd6138d7b208b2621bcfc431 (patch)
treefefde42e9df77384f9fa11adfa3efd3af73869d8 /comp/lucas-standen-NEA/writeup2/examples/spaceinvaders.zpy
parent27e2e13679f57eb2bd139175216b1d5989e8dc6a (diff)
made a load of stuff
Diffstat (limited to 'comp/lucas-standen-NEA/writeup2/examples/spaceinvaders.zpy')
-rw-r--r--comp/lucas-standen-NEA/writeup2/examples/spaceinvaders.zpy164
1 files changed, 164 insertions, 0 deletions
diff --git a/comp/lucas-standen-NEA/writeup2/examples/spaceinvaders.zpy b/comp/lucas-standen-NEA/writeup2/examples/spaceinvaders.zpy
new file mode 100644
index 0000000..33036e0
--- /dev/null
+++ b/comp/lucas-standen-NEA/writeup2/examples/spaceinvaders.zpy
@@ -0,0 +1,164 @@
+(struct entity)
+ (def x:int)
+ (def y:int)
+ (def width:int)
+ (def height:int)
+ (def ofx:int)
+ (def ofy:int)
+ (def exists:bool)
+(endstruct)
+
+//# this checks if 2 entitys are touching
+(defun touching bool a:entity* b:entity*)
+ (def r1:Rectangle)
+ (def r2:Rectangle)
+
+ (set r1.x a->x)
+ (set r1.y a->y)
+ (set r1.width a->width)
+ (set r1.height a->height)
+
+ (set r2.x b->x)
+ (set r2.y b->y)
+ (set r2.width b->width)
+ (set r2.height b->height)
+ (return (CheckCollisionRecs r1 r2))
+(endfun)
+
+//# the main loop of the program
+(defun main int)
+ (InitWindow 800 800 "test test")
+ (SetTargetFPS 60)
+
+ (let p:entity* (alloc (sizeof entity)))
+ (set p->x 400)
+ (set p->y 700)
+ (set p->width 50)
+ (set p->height 30)
+ (set p->ofx 25)
+ (set p->ofy 15)
+
+ (let b:entity* (alloc (sizeof entity)))
+ (set b->x 400)
+ (set b->y 700)
+ (set b->width 10)
+ (set b->height 6)
+ (set b->ofx 5)
+ (set b->ofy 3)
+ (set b->exists false)
+
+ (let b2:entity* (alloc (sizeof entity)))
+ (set b2->x 400)
+ (set b2->y 700)
+ (set b2->width 10)
+ (set b2->height 6)
+ (set b2->ofx 5)
+ (set b2->ofy 3)
+ (set b2->exists false)
+
+ (let e:entity* (alloc (sizeof entity)))
+ (set e->x 400)
+ (set e->y 100)
+ (set e->width 60)
+ (set e->height 30)
+ (set e->ofx 30)
+ (set e->ofy 15)
+ (set e->exists true)
+
+ (let ehp:int 5)
+ (let edx:int 1)
+
+ (let reload:int 0)
+
+ (for i:int 0 (= (WindowShouldClose) 0) 0)
+ (if (= ehp 0))
+ (exit 0)
+ (elif (= e->y 700))
+ (exit 1)
+ (endif)
+
+ (if (!= reload 0)
+ (set reload (- reload 1))
+ (endif)
+
+ (BeginDrawing)
+ (ClearBackground BLACK)
+ (DrawRectangle (- p->x p->ofx) (+ p->y p->ofy) p->width p->height GREEN)
+ (if (= b->exists true))
+ (DrawRectangle (- b->x b->ofx) (+ b->y b->ofy) b->width b->height BLUE)
+ (endif)
+ (if (= b2->exists true))
+ (DrawRectangle (- b2->x b2->ofx) (+ b2->y b2->ofy) b2->width b2->height PURPLE)
+ (endif)
+ (if (= e->exists true))
+ (DrawRectangle (- e->x e->ofx) (+ e->y e->ofy) e->width e->height RED)
+ (endif)
+ (EndDrawing)
+
+ (if (IsKeyDown KEY_LEFT))
+ (set p->x (- p->x 6))
+ (elif (IsKeyDown KEY_RIGHT))
+ (set p->x (+ p->x 6))
+ (endif)
+
+ (if (IsKeyPressed KEY_SPACE))
+ (if (= reload 0))
+ (if (!= b->exists true))
+ (set b->exists true)
+ (else)
+ (set b2->exists true)
+ (endif)
+ (set reload 30)
+ (endif)
+ (endif)
+
+ (if (= b->exists true))
+ (set b->y (- b->y 10))
+ (if (< b->y 0))
+ (set b->y 700)
+ (set b->exists false)
+ (endif)
+ (else)
+ (set b->x p->x)
+ (endif)
+
+ (if (touching b e))
+ (set b->y 700)
+ (set b->exists false)
+ (set ehp (- ehp 1)
+ (if (<= ehp 0))
+ (set e->exists false)
+ (endif)
+ (endif)
+
+ (if (= b2->exists true))
+ (set b2->y (- b2->y 10))
+ (if (< b2->y 0))
+ (set b2->y 700)
+ (set b2->exists false)
+ (endif)
+ (else)
+ (set b2->x p->x)
+ (endif)
+
+ (if (touching b2 e))
+ (set b2->y 700)
+ (set b2->exists false)
+ (set ehp (- ehp 1)
+ (if (<= ehp 0))
+ (set e->exists false)
+ (endif)
+ (endif)
+
+ (set e->x (+ (* 4 edx) e->x)
+ (if (= e->x 800))
+ (set edx (* edx -1)
+ (set e->y (+ e->y 10))
+ (elif (= e->x 0))
+ (set edx (* edx -1)
+ (set e->y (+ e->y 10))
+ (endif)
+
+ (endfor)
+ (CloseWindow)
+(endfun)