diff options
author | thing1 <thing1@seacrossedlovers.xyz> | 2024-10-01 08:55:32 +0100 |
---|---|---|
committer | thing1 <thing1@seacrossedlovers.xyz> | 2024-10-01 08:55:32 +0100 |
commit | ef8cf00bbf9f74eb3b6aabc1d99f5358e81741c7 (patch) | |
tree | 3479ca1b82573426151cb270c63a588af737d3c0 /comp/lucas-standen-NEA/code2/examples | |
parent | dc7732b6f073d5450657d94c815ca445a1a08fbd (diff) |
added some cool examples to zpy and got electronics working
Diffstat (limited to 'comp/lucas-standen-NEA/code2/examples')
-rw-r--r-- | comp/lucas-standen-NEA/code2/examples/Makefile | 3 | ||||
-rwxr-xr-x | comp/lucas-standen-NEA/code2/examples/fib_example | bin | 24488 -> 25496 bytes | |||
-rwxr-xr-x | comp/lucas-standen-NEA/code2/examples/raylib_example | bin | 1085488 -> 1086488 bytes | |||
-rw-r--r-- | comp/lucas-standen-NEA/code2/examples/raylib_example.zpy | 12 | ||||
-rwxr-xr-x | comp/lucas-standen-NEA/code2/examples/spaceinvaders | bin | 0 -> 1086520 bytes | |||
-rw-r--r-- | comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy | 161 | ||||
-rwxr-xr-x | comp/lucas-standen-NEA/code2/examples/str_example | bin | 24856 -> 25952 bytes | |||
-rw-r--r-- | comp/lucas-standen-NEA/code2/examples/str_example.zpy | 14 |
8 files changed, 180 insertions, 10 deletions
diff --git a/comp/lucas-standen-NEA/code2/examples/Makefile b/comp/lucas-standen-NEA/code2/examples/Makefile index 13178a5..cbdcda1 100644 --- a/comp/lucas-standen-NEA/code2/examples/Makefile +++ b/comp/lucas-standen-NEA/code2/examples/Makefile @@ -1,6 +1,7 @@ all: zpy raylib_example.zpy -o raylib_example -f -lraylib -f -lm -i raylib.h + zpy spaceinvaders.zpy -o spaceinvaders -f -lraylib -f -lm -i raylib.h zpy fib_example.zpy -o fib_example -f -ggdb zpy str_example.zpy -o str_example -f -ggdb clean: - rm -rf fib_example raylib_example str_example + rm -rf fib_example raylib_example str_example spaceinvaders diff --git a/comp/lucas-standen-NEA/code2/examples/fib_example b/comp/lucas-standen-NEA/code2/examples/fib_example Binary files differindex e7d4958..bdd94ec 100755 --- a/comp/lucas-standen-NEA/code2/examples/fib_example +++ b/comp/lucas-standen-NEA/code2/examples/fib_example diff --git a/comp/lucas-standen-NEA/code2/examples/raylib_example b/comp/lucas-standen-NEA/code2/examples/raylib_example Binary files differindex 74d52ed..08ea8fd 100755 --- a/comp/lucas-standen-NEA/code2/examples/raylib_example +++ b/comp/lucas-standen-NEA/code2/examples/raylib_example diff --git a/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy b/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy index 90ef8b8..7c6e599 100644 --- a/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy +++ b/comp/lucas-standen-NEA/code2/examples/raylib_example.zpy @@ -1,15 +1,15 @@ (defun main int) - (InitWindow 800 800 "test_test") - (SetTargetFPS 30) + (InitWindow 800 800 "test test") + (SetTargetFPS 60) (let img:Image (LoadImage "dvd.png")) (let tex:Texture (LoadTextureFromImage img)) (UnloadImage img) - (let x:int (randint 1 9)) - (let y:int (randint 1 9)) - (let xd:int (randint 1 5)) - (let yd:int (randint 1 5)) + (let x:int (randint 4 9)) + (let y:int (randint 4 9)) + (let xd:int (randint 3 5)) + (let yd:int (randint 3 5)) (for i:int 0 (= (WindowShouldClose) 0) 0) (BeginDrawing) diff --git a/comp/lucas-standen-NEA/code2/examples/spaceinvaders b/comp/lucas-standen-NEA/code2/examples/spaceinvaders Binary files differnew file mode 100755 index 0000000..ec88002 --- /dev/null +++ b/comp/lucas-standen-NEA/code2/examples/spaceinvaders diff --git a/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy b/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy new file mode 100644 index 0000000..698999a --- /dev/null +++ b/comp/lucas-standen-NEA/code2/examples/spaceinvaders.zpy @@ -0,0 +1,161 @@ +(struct entity) + (def x:int) + (def y:int) + (def width:int) + (def height:int) + (def ofx:int) + (def ofy:int) + (def exists:bool) +(endstruct) + +(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) + +(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) diff --git a/comp/lucas-standen-NEA/code2/examples/str_example b/comp/lucas-standen-NEA/code2/examples/str_example Binary files differindex 8f86844..c543ab7 100755 --- a/comp/lucas-standen-NEA/code2/examples/str_example +++ b/comp/lucas-standen-NEA/code2/examples/str_example diff --git a/comp/lucas-standen-NEA/code2/examples/str_example.zpy b/comp/lucas-standen-NEA/code2/examples/str_example.zpy index 7311660..bffc3f0 100644 --- a/comp/lucas-standen-NEA/code2/examples/str_example.zpy +++ b/comp/lucas-standen-NEA/code2/examples/str_example.zpy @@ -1,6 +1,14 @@ (defun main int) - (let str:string* (String "hello")) - (printchar str->_str[0]) + (let str:string* (String "hello_world")) + (printstr str->_str) + (printchar '\n') + + (let strs:string** (str->split str '_')) + + (printstr strs[0]->_str) + (printchar '\n') + (printstr strs[1]->_str) + (printchar '\n') + (str->free str) - (printstr "<first_letter\n") (endfun) |