commit 47c0c1fa80561666524ac6ad54a5acab57d502de
parent 67a549a6320f419a71aec54e8368aaef3fcdb64d
Author: Claudio Alessi <smoppy@gmail.com>
Date: Tue, 19 Jun 2018 22:03:45 +0200
Add a zombie to level 5
Diffstat:
3 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -3,19 +3,20 @@
Object objects[] = {
/* symbol flags ontick argument */
{ VACUUM, OF_OPEN, falling, {0} },
-[1] = {'o', OF_PLAYER|OF_OPEN|OF_FALL, NULL, {.i = 2} },
-[2] = {'a', OF_PLAYER|OF_OPEN|OF_FALL, NULL, {.i = 2} },
- {'_', OF_OPEN|OF_STICK|OF_JUMPFROM, NULL, {0} },
- {'|', 0, NULL, {0} },
- {'*', OF_OPEN, earnenergy, {.i = 2} },
- {')', OF_OPENLEFT|OF_STICK, finish, {0} },
- {'(', OF_OPENRIGHT|OF_STICK, finish, {0} },
- {'t', 0, cannon, {.v = &objects[11]} },
- {'j', 0, cannon, {.v = &objects[12]} },
-[11] = {'.', OF_OPEN, cannonball, {.i = +1} },
-[12] = {',', OF_OPEN, cannonball, {.i = -1} },
- {'#', OF_FALL|OF_PUSHABLE, NULL, {0} },
- {'@', OF_FALL|OF_PUSHABLE, NULL, {0} },
+[1] = {'o', OF_PLAYER|OF_OPEN|OF_FALL, NULL, {.i = 2} },
+[2] = {'a', OF_PLAYER|OF_OPEN|OF_FALL, NULL, {.i = 2} },
+ {'_', OF_OPEN|OF_STICK|OF_JUMPFROM, NULL, {0} },
+ {'|', 0, NULL, {0} },
+ {'*', OF_OPEN, earnenergy, {.i = 2} },
+ {')', OF_OPENLEFT|OF_STICK, finish, {0} },
+ {'(', OF_OPENRIGHT|OF_STICK, finish, {0} },
+ {'t', 0, cannon, {.v = &objects[11]} },
+ {'j', 0, cannon, {.v = &objects[12]} },
+[11] = {'.', OF_OPEN, cannonball, {.i = +1} },
+[12] = {',', OF_OPEN, cannonball, {.i = -1} },
+ {'#', OF_FALL|OF_PUSHABLE, NULL, {0} },
+ {'@', OF_FALL|OF_PUSHABLE, NULL, {0} },
+ {'x', OF_PLAYER|OF_OPEN|OF_FALL, zombie, {.i = 8} },
};
#include "levels.h"
@@ -35,11 +36,11 @@ static Key keys[] = {
/* key function argument */
{ 'q', quit, {.i = 1} },
{ CTRL('c'), quit, {.i = 0} },
+ { 'h', walkleft, {.v = &objects[1]} },
+ { 'n', walkright, {.v = &objects[1]} },
+ { 'c', jump, {.v = &objects[1]} },
+ { 'a', walkleft, {.v = &objects[2]} },
+ { 'e', walkright, {.v = &objects[2]} },
+ { ',', jump, {.v = &objects[2]} },
{ 'r', restart, {0} },
- { 'a', walkleft, {.v = &objects[1]} },
- { 'd', walkright, {.v = &objects[1]} },
- { 'w', jump, {.v = &objects[1]} },
- { 'j', walkleft, {.v = &objects[2]} },
- { 'l', walkright, {.v = &objects[2]} },
- { 'i', jump, {.v = &objects[2]} },
};
diff --git a/globox.c b/globox.c
@@ -65,7 +65,7 @@ char *argv0;
/* enums */
enum { KeyUp = -50, KeyDown, KeyRight, KeyLeft, KeyHome, KeyEnd, KeyDel, KeyPgUp, KeyPgDw };
-enum { DelayFalling, DelayCannon, DelayCannonBall, DelayMax };
+enum { DelayCannon, DelayCannonBall, DelayFalling, DelayZombie, DelayMax };
typedef union {
int i;
@@ -144,6 +144,7 @@ void usage(void);
void walk(Block *blk, int offset);
void walkleft(const Arg *arg);
void walkright(const Arg *arg);
+int zombie(Object *o);
/* variables */
Scene *scene;
@@ -596,7 +597,7 @@ level(int num) {
++x;
}
scene->h = y + 1;
- /* revive the zombies */
+ /* revive the zombies players */
for(b = scene->blocks; b; b = b->next)
if(ISSET(b->o->flags, OF_PLAYER) && !b->energy)
b->energy = b->o->arg.i;
@@ -757,12 +758,29 @@ walkright(const Arg *arg) {
}
int
+zombie(Object *o) {
+ Block *c;
+ int t;
+
+ for(c = scene->blocks; c; c = c->next) {
+ if(c->o->ontick != zombie || DELAY(c, DelayZombie, 4))
+ continue;
+ t = rand() % 3;
+ if(t == 2)
+ t = -1;
+ objwalk(c->o, t);
+ }
+ return 0;
+}
+
+int
main(int argc, char *argv[]) {
ARGBEGIN {
case 'n': lev = atoi(EARGF(usage())); break;
case 'v': die("globox-"VERSION"\n");
default: usage();
} ARGEND;
+ srand(time(NULL));
setup();
level(lev);
run();
diff --git a/levels.h b/levels.h
@@ -45,7 +45,7 @@ char lev5[] = {
"| _ |\n"
"| j\n"
"| _ |\n"
- "t |\n"
+ "t x |\n"
"| @ |\n"
"| _ |\n"
"| |\n"