70 lines
1.9 KiB
Plaintext
70 lines
1.9 KiB
Plaintext
//quick and dirty RNG
|
|
var randi: Int = 69420;
|
|
fn rand() {
|
|
return randi = randi * 1664525 + 1013904223; //overflows to a negative, which is fine
|
|
}
|
|
|
|
//wander like a zombie
|
|
var counter = 0;
|
|
fn wander(actor: Opaque) {
|
|
actor.setX(actor.x + rand() % 5);
|
|
actor.setY(actor.y + rand() % 5);
|
|
|
|
counter++;
|
|
}
|
|
|
|
//player controlled character
|
|
var playerMaxMotion: Int = 5;
|
|
var playerMotionX: Int = 0;
|
|
var playerMotionY: Int = 0;
|
|
|
|
fn playerOnFrame(player: Opaque) {
|
|
//handle keyboard input
|
|
if (KeyPressed.UP) playerMotionY -= 5;
|
|
if (KeyPressed.DOWN) playerMotionY += 5;
|
|
if (KeyPressed.LEFT) playerMotionX -= 5;
|
|
if (KeyPressed.RIGHT) playerMotionX += 5;
|
|
|
|
if (KeyReleased.UP) playerMotionY = min(playerMotionY + 5, 0);
|
|
if (KeyReleased.DOWN) playerMotionY = max(playerMotionY - 5, 0);
|
|
if (KeyReleased.LEFT) playerMotionX = min(playerMotionX + 5, 0);
|
|
if (KeyReleased.RIGHT) playerMotionX = max(playerMotionX - 5, 0);
|
|
|
|
//cap the max speed
|
|
playerMotionX = min(max(playerMotionX, -playerMaxMotion), playerMaxMotion);
|
|
playerMotionY = min(max(playerMotionY, -playerMaxMotion), playerMaxMotion);
|
|
|
|
//shortcut for normalized diagonal movement
|
|
var mod = 1;
|
|
if (playerMotionX != 0 && playerMotionY != 0) {
|
|
mod = 0.707;
|
|
}
|
|
|
|
//move the player
|
|
player.setX(player.x + floor(playerMotionX * mod));
|
|
player.setY(player.y + floor(playerMotionY * mod));
|
|
}
|
|
|
|
//when the game is ready, load the "zombie" sprite
|
|
fn onReady() {
|
|
loadSprite("zombie", "assets/parvati.png", 32, 32);
|
|
|
|
//spawn some "zombies" looking for brains
|
|
spawnActorAt("zombie", wander, 250, 250);
|
|
spawnActorAt("zombie", wander, 250, 500);
|
|
spawnActorAt("zombie", wander, 500, 250);
|
|
spawnActorAt("zombie", wander, 500, 500);
|
|
|
|
//spawn the player
|
|
loadSprite("player", "assets/parvati.png", 32, 32);
|
|
spawnActorAt("player", playerOnFrame, 300, 300);
|
|
}
|
|
|
|
fn onFrame() {
|
|
//debug
|
|
}
|
|
|
|
//example API for the game
|
|
initScreen(1280, 720, "Oh no, Zombies!");
|
|
initLoop(onReady, onFrame, null);
|