From 8502841e895cfbcae3446aad59eac2561a2e39b3 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 30 May 2026 20:36:06 +1000 Subject: [PATCH] Zombies follow the player --- Toy | 2 +- assets/main.toy | 17 ++++++++++++++++- source/actor.c | 6 +++++- source/main.c | 2 ++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Toy b/Toy index 75cb1df..a00739f 160000 --- a/Toy +++ b/Toy @@ -1 +1 @@ -Subproject commit 75cb1dfa86487d7f9cb975194210be8b40bee1e2 +Subproject commit a00739f58074500fd683a7341ee9ae646c3f5a2a diff --git a/assets/main.toy b/assets/main.toy index 2660956..2489586 100644 --- a/assets/main.toy +++ b/assets/main.toy @@ -10,10 +10,25 @@ fn wander(actor: Opaque) { actor.setX(actor.x + rand() % 5); actor.setY(actor.y + rand() % 5); + if (playerRef.x > actor.x) { + actor.setX(actor.x + 1); + } + else { + actor.setX(actor.x - 1); + } + + if (playerRef.y > actor.y) { + actor.setY(actor.y + 1); + } + else { + actor.setY(actor.y - 1); + } + counter++; } //player controlled character +var playerRef: Opaque = null; var playerMaxMotion: Int = 5; var playerMotionX: Int = 0; var playerMotionY: Int = 0; @@ -57,7 +72,7 @@ fn onReady() { //spawn the player loadSprite("player", "assets/parvati.png", 32, 32); - spawnActorAt("player", playerOnFrame, 300, 300); + playerRef = spawnActorAt("player", playerOnFrame, 300, 300); } fn onFrame() { diff --git a/source/actor.c b/source/actor.c index 3393a5a..06530c5 100644 --- a/source/actor.c +++ b/source/actor.c @@ -81,7 +81,7 @@ static void api_loadSprite(Toy_VM* vm, Toy_FunctionNative* self) { } static void api_spawnActorAt(Toy_VM* vm, Toy_FunctionNative* self) { - //sprite, onStep, x, y -> void + //sprite, onStep, x, y -> Opaque(Actor) (void)self; //check for initialization @@ -172,6 +172,10 @@ static void api_spawnActorAt(Toy_VM* vm, Toy_FunctionNative* self) { .enabled = true, }; + //leave the actor on the stack + Toy_Value value = TOY_OPAQUE_FROM_POINTER(newActorPtr); + Toy_pushStack(&vm->stack, value); + Toy_freeValue(spriteValue); Toy_freeValue(key); Toy_freeValue(step); diff --git a/source/main.c b/source/main.c index 520a1bc..0e17ff9 100644 --- a/source/main.c +++ b/source/main.c @@ -19,6 +19,7 @@ // #include "bytecode_inspector.h" // #include "bucket_inspector.h" +#include "stack_inspector.h" //utils unsigned char* readFile(char* path, int* size) { @@ -290,6 +291,7 @@ int main() { freeActorAPI(&vm); // inspect_bucket(&vm.memoryBucket); + inspect_stack(vm.stack); Toy_freeVM(&vm); free(entryCode);