From 4e723d856f8535e5d364f76e8d15ef9fcf109745 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Mon, 3 Nov 2008 06:06:37 +0000 Subject: [PATCH] Modifications to king snail code --- data/world1/level40.dat | 96 ++++++++++------ defs.h | 22 +++- rc.c | 237 ++++++++++++++++++++++++++++++++++++---- rc.h | 2 +- shared.c | 71 +++++++++++- 5 files changed, 367 insertions(+), 61 deletions(-) diff --git a/data/world1/level40.dat b/data/world1/level40.dat index fb9e7a4..a93c763 100644 --- a/data/world1/level40.dat +++ b/data/world1/level40.dat @@ -5,37 +5,71 @@ help endhelp monsters 0 6 8 -128 19 27 +128 12 27 endmonsters exitdir 1 -56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56, -56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,56,56,56,56,56,56,56,56,56,0,0,0,0,0,56,56,56,56,56,56,56,56,56,56,0,0,0,0,0,56,56,56,56,56,56,56,56,56,56, -56,56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,56,56,56,56,56,56,56,56,56,56,56,56,56,56,0,0,0,0,0,56,56,56,56,56,56,56,56,56,56,56,56,56,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,56,56,56,56,56,56,0,0,0,0,0,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,0,0,0,0,0,56,56,56,56,56,56,56, -56,56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,56,56,56,56,56,56,56,56,56,56,56,56,56,0,0,0,0,0,0,56,56,56,56,56,56,56,56,56,56,56,56,56,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,56,56,56,56,23,23,23,56,56,56,56,56,56,56,56,56,56,56,23,23,23,56,56,56,56,56,56,56,56,56,56,23,23,23,56,56,56,56,56, -56,56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -56,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,11,11,11,11,11,11,11,17,11,11,11,11,11,56, -56,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,56, -56,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,56, +44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44, +44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,45,23,23,23,45,45,45,45,47,0,0,0,0,0,46,45,45,45,23,23,23,45,45,47,0,0,0,0,0,46,45,45,45,45,23,23,23,45,44, +44,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,46,45,45,45,45,45,45,23,23,23,45,45,45,47,0,0,0,0,0,46,45,45,23,23,23,45,45,45,45,45,45,47,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,45,45,45,45,45,47,0,0,0,0,0,46,45,45,45,45,45,23,23,23,23,45,45,45,45,45,47,0,0,0,0,0,46,45,45,45,45,45,44, +44,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,46,45,45,45,23,23,23,45,45,45,45,47,0,0,0,0,0,0,0,0,46,45,45,45,45,23,23,23,45,45,45,47,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,44, +44,45,45,45,45,23,23,23,45,45,45,45,45,45,45,45,45,47,0,0,0,0,46,45,45,45,45,45,45,45,45,45,23,23,23,45,45,45,45,44, +44,44,44,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,44,44,44, +44,44,44,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,44,44,44, +44,44,44,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,44,44,44, +44,44,44,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,44,44,44, +44,44,44,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,44,44,44, +44,44,44,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,44,44,44, +44,44,44,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,44,44,44, +44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44, layer2 +3,27,11 +4,27,11 +5,27,11 +6,27,17 +7,27,11 +8,27,11 +9,27,11 +10,27,11 +11,27,11 +12,27,11 +13,27,11 +14,27,11 +15,27,11 +16,27,11 +17,27,11 +18,27,11 +19,27,17 +20,27,17 +21,27,11 +22,27,11 +23,27,11 +24,27,11 +25,27,11 +26,27,11 +27,27,11 +28,27,11 +29,27,11 +30,27,11 +31,27,11 +32,27,11 +33,27,17 +34,27,11 +35,27,11 +36,27,11 diff --git a/defs.h b/defs.h index fc28772..9209246 100644 --- a/defs.h +++ b/defs.h @@ -159,7 +159,6 @@ // king rat #define KR_WALKTIME 100 #define KR_STUNTIME 150 -//#define KR_WALKTIME 30 #define KR_MAXJUMP 15 // max initial jumpspeed #define KR_NUMJUMPS 5 #define KR_CHARGESPEED 8 @@ -172,6 +171,21 @@ #define KRS_CHARGE 5 #define KRS_STUN 6 +// king snail +#define KS_WALKTIME 300 +#define KS_SHOOTWAIT 80 // how long to pause between shooting +#define KS_JUMPWAIT 30 // how long to pause before jumping +#define KS_RELOADWAIT 100 // how long to pause after jumping +// king snail states +#define KSS_WALK1 0 // walk back & forth +#define KSS_PAUSE1 1 // smoke comes out of shell +#define KSS_SHOOT 2 // shell cracks, shoot out snails +#define KSS_REGEN 3 // shell coming back +#define KSS_WALK2 4 // walks again +#define KSS_PAUSE2 5 // delay before jumping +#define KSS_JUMPING 6 // jumping, snails turn to slugs +#define KSS_PAUSE3 7 // pause after jumping + // bell states #define BELL_DONESOUND 1 @@ -302,7 +316,7 @@ #define S_SLOPE 2 // Sprite types -#define MAXPTYPES 129 +#define MAXPTYPES 130 #define P_PLAYER 0 #define P_RAT 1 #define P_CHEESE 2 @@ -437,6 +451,7 @@ #define P_ZAPPOWERUP 126 #define P_ZAPPER 127 #define P_KINGSNAIL 128 +#define P_KSSHELL 129 // cards #define CARDFONTX 4 @@ -720,6 +735,7 @@ typedef struct sprite_s { int ontramp; // on a trampoline? int trampx; // x,y coords for trampoline we are/were on int trampy; // + int tramplayer; // which layer was the trampoline on? 1 or 2. // player permenant powerups int armour; // does the player have armour? @@ -772,7 +788,7 @@ typedef struct sprite_s { int dropx,dropy;// coords of tile we dropped from int fallspeed; // how fast are we falling? int jumping; // are we jumping? - int jumpdir; //which way are we jumping? + double jumpdir; //which way are we jumping? int jumpspeed; // how fast we are moving upwards int teleporting;// are we inside a teleporter? >0 is entering, <0 is exitting int dead; // is this sprite dead? if so, what dying state? diff --git a/rc.c b/rc.c index 3583b4b..4586e4b 100644 --- a/rc.c +++ b/rc.c @@ -740,7 +740,7 @@ int main (int argc, char **argv) { // create rat if (timer % 10 == 0) { - if (countmonsters() < 8) { // max 7 rats + king rat + if (countmonsters(-1) < 8) { // max 7 rats + king rat puffin(P_RAT, rand() % (640-(TILEW*8))+(TILEW*4), TILEH, "gen_rat",0); } } @@ -1149,11 +1149,16 @@ void jump(sprite_t *s, int dir) { // check for recoiling here, because we always need to be able to // "jump" backwards, even if already jumping if (s->recoiling || isonground(s) || isinwater(s) || isonladder(s) || s->doublejump) { - if (ismonster(s->id)) { + if (ismonster(s->id) || (s->id == P_KSSHELL)) { if (s->recoiling) { // recoiling monsters don't pause before jumping - s->jumpspeed = MONJUMPSPEED; + if (s->id == P_KSSHELL) { + s->jumpspeed = 3; + s->jumpdir = dir*3; + } else { + s->jumpspeed = MONJUMPSPEED; + s->jumpdir = dir; + } s->jumping = 1; - s->jumpdir = dir; s->dir = -s->jumpdir; // face backwards } else { s->jumpdir = dir; @@ -1414,8 +1419,8 @@ void checklevelend(void) { } } -// count monsters on level -int countmonsters(void) { +// count monsters of a given type (-1 for all) on level +int countmonsters(int montype) { sprite_t *s2; int mcount; mcount = 0; @@ -1423,7 +1428,9 @@ int countmonsters(void) { for (s2 = sprite->next ; s2 ; s2 = s2->next) { if (ismonster(s2->id) && !s2->dead) { if (s2->id != P_BLACKCLOUD) { - mcount++; + if ((montype == -1) || (s2->id == montype)) { + mcount++; + } } } } @@ -1842,7 +1849,11 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n"); /* change into a fruit */ s->dead = D_FINAL; //addsprite(s->willbecome, x, y, "Fruit", B_FALSE); - puffin(s->willbecome, x, y, "fruit", 0); + if (boss) { + puffin(-1, x, y, "nothing", 0); + } else { + puffin(s->willbecome, x, y, "fruit", 0); + } //ss = addsprite(P_PUFF, x, y, "Fruit", B_FALSE); //ss->timer3 = s->willbecome; @@ -2011,6 +2022,7 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n"); // is it a boss? if so update boss pointer switch (s->timer3) { case P_KINGRAT: + case P_KINGSNAIL: boss = newsp; } @@ -2429,6 +2441,33 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n"); s->dir = -s->dir; } + // jump? + if (boss) { + if ((player->dead == 0) && (!s->jumping) && (!s->jumptimer)) { + /* if player is above us or at same level...*/ + if (player->y <= (s->y-TILEH)) { + int ydiff = s->y - player->y; + + if ((ydiff >= (TILEH*4)) && (ydiff <= (TILEH*8))) { // player between 4 and 8 tiles above + if (xdiff <= (TILEW*16)) { // if closeish horizontally + /* jump up */ + jump(s, 0); + } + } else if ((xdiff >= (TILEW*1)) && (xdiff <= (TILEW*9))) { // if 1-9 tiles right + if (s->dir == D_RIGHT) { + /* jump right */ + jump(s, D_RIGHT); + } + } else if ((xdiff <= -(TILEW*1)) && (xdiff >= -(TILEW*9))) { // if 1-9 tiles left + if (s->dir == D_LEFT) { + /* jump left */ + jump(s, D_LEFT); + } + } + } + } + } + } else { // falling if (s->recoiling) { // fall backwards @@ -2650,6 +2689,123 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n"); } + } else if (s->id == P_KINGSNAIL) { + /* timer1 is state + + 0 == walk back and forth + + + timer2 counts down, at zero we change state + */ + if ((s->timer1 == KSS_WALK1) || (s->timer1 == KSS_WALK2)) { + // walk back and forth + rv = movex(s, s->dir*getspeed(s)); + if (rv) { + /* if we couldn't move (hit a wall), turn */ + s->dir = -s->dir; + } + // dec timer + s->timer2--; + if (s->timer2 == 0) { + if (player->dead) { + // reset timer + s->timer2 = KR_WALKTIME; + } else { + // release snails or jump, depending on state + + if ((countmonsters(P_SNAIL) == 0) || (s->timer1 == KSS_WALK1)) { // next state is shooting + s->timer1 = KSS_PAUSE1; + s->timer2 = KS_SHOOTWAIT; + } else { // next state is jump + s->timer1 = KSS_PAUSE2; + s->timer2 = KS_JUMPWAIT; + } + } + } + } else if (s->timer1 == KSS_PAUSE1) { + // add puffs on shell + if (timer % 6 == 0) { + puffin(-1, s->x + -s->dir*((s->img->w/4) + (rand() % 7)-3), + s->y-(s->img->h/2) - (rand() % 7) - 3, "nothing", rand() % 5); + } + s->timer2--; + if (s->timer2 == 0) { + sprite_t *newsp; + // shoot! + s->timer1 = KSS_SHOOT; + // shell cracks + newsp = addsprite(P_KSSHELL, s->x + -s->dir*((s->img->w/4) + (rand() % 7)-3), + s->y-(s->img->h/2) - (rand() % 7) - 3, "ksshell"); + + // the shell recoils (other code will kill us off when this is done) + // -become invulnerable temporarily + newsp->invuln = INVULNTIME*2; // make sure this lasts until we die + // -bounce back + newsp->recoiling = B_TRUE; + jump(newsp,-s->dir); // ie. away from king snail + } + + } else if (s->timer1 == KSS_SHOOT) { + // shoot out snails + if (timer % 20 == 0) { + if (countmonsters(-1) < 8) { // max 7 snails + king snail + sprite_t *newsp; + newsp = addsprite(P_SNAIL, s->x + -s->dir*(s->img->w/4), s->y-(s->img->h/2),"babsnail"); + // make it shoot upwards + newsp->jumping = 1; + newsp->jumpspeed = (rand() % 7) + 7; // 7 - 13 + newsp->jumpdir = (((double)(rand() % 110) - 50) / 10); // -5 to 5 + if (rand() % 2) newsp->dir = 1; + else newsp->dir = -1; + } else { + // enough, regenerate shell + s->timer1 = KSS_REGEN; + s->timer3 = 1; // percentage of shell size + } + } + } else if (s->timer1 == KSS_REGEN) { + // shell gets bigger + s->timer3++; + + // wait for shell to finish + if (s->timer3 >= 120) { + // walk again + s->timer1 = KSS_WALK2; + s->timer2 = KS_WALKTIME; + } + + } else if (s->timer1 == KSS_PAUSE2) { + if (!s->jumptimer) { + // delay then jump + s->jumptimer = getjumpdelay(s->id); + s->willjumpspeed = getmonjumpspeed(s); + // next state + s->timer1 = KSS_JUMPING; + } + } else if (s->timer1 == KSS_JUMPING) { + // wait until we land... + if (!s->jumptimer && !s->jumping && !s->falling) { + sprite_t *ss, *nexts; + // snails turn to slugs!! + for (ss = sprite ; ss ; ss = nexts) { + nexts = ss->next; + if ((ss->id == P_SNAIL) && !ss->caughtby && !ss->dead) { + die(ss); + } + } + // now pause a while before moving again + s->timer1 = KSS_PAUSE3; + s->timer2 = KS_RELOADWAIT; + } + } else if (s->timer1 == KSS_PAUSE3) { + s->timer2--; + if (s->timer2 == 0) { + // go back to start! + s->timer1 = KSS_WALK1; + s->timer2 = KS_WALKTIME; + } + } + } else if (s->id == P_TICK) { if (!s->falling) { @@ -3279,7 +3435,7 @@ void dotileeffects(sprite_t *s) { /* check under us */ tt = gettileat(s->x,s->y+3,&tilex,&tiley); - // CHECKS WHICH COUlD APPLY TO TILES UNDER AND SLIGHTLY LEFT/RIGHT OF US + // CHECKS WHICH COULD APPLY TO TILES UNDER AND SLIGHTLY LEFT/RIGHT OF US while (!finished) { if (tt->id == T_RIGHT) { if (player->powerup != PW_CLOCK) { @@ -3312,7 +3468,7 @@ void dotileeffects(sprite_t *s) { } else if (tt->spikes) { if (!isfruit(s->id) ) { if (!s->invuln) { - if (s->id != P_BLACKCLOUD) { + if ((s->id != P_BLACKCLOUD) && (s->id != P_KINGSNAIL)) { die(s); } } @@ -3326,17 +3482,33 @@ void dotileeffects(sprite_t *s) { // a different one? if ((s->trampx != tilex) || (s->trampy != tiley)) { // if a different one, release it - curlevel->map[s->trampy * LEVELW + s->trampx] = getuniq(T_TRAMPUP); + if (s->tramplayer == 1) { + curlevel->map[s->trampy * LEVELW + s->trampx] = getuniq(T_TRAMPUP); + } else { + curlevel->map2[s->trampy * LEVELW + s->trampx] = getuniq(T_TRAMPUP); + } drawtile(temps, s->trampx, s->trampy); } } else { + tiletype_t *temptile; // remember we were on it so it can release s->ontramp = B_TRUE; s->trampx = tilex; s->trampy = tiley; + // which layer was it on? + temptile = gettile(curlevel->map2[s->trampy*LEVELW+s->trampx]); + if (temptile->id == T_TRAMPUP) { + s->tramplayer = 2; + } else { + s->tramplayer = 1; + } // move it down then draw it - curlevel->map[tiley*LEVELW+tilex] = getuniq(T_TRAMPDOWN); + if (s->tramplayer == 1) { + curlevel->map[tiley*LEVELW+tilex] = getuniq(T_TRAMPDOWN); + } else { + curlevel->map2[tiley*LEVELW+tilex] = getuniq(T_TRAMPDOWN); + } drawtile(temps, tilex, tiley); } } @@ -4572,7 +4744,11 @@ void dogravity(sprite_t *s) { if (s->ontramp) { if (s->trampy != tiley) { // change tile type - curlevel->map[s->trampy * LEVELW + s->trampx] = getuniq(T_TRAMPUP); + if (s->tramplayer == 1) { + curlevel->map[s->trampy * LEVELW + s->trampx] = getuniq(T_TRAMPUP); + } else { + curlevel->map2[s->trampy * LEVELW + s->trampx] = getuniq(T_TRAMPUP); + } drawtile(temps, s->trampx, s->trampy); // update sprite settings @@ -4585,7 +4761,9 @@ void dogravity(sprite_t *s) { if (s->dead) return; if (s->flies && !s->iced) return; // no gravity if you fly, but ice cancels flying - if (iseffect(s->id)) return; + if (s->id != P_KSSHELL) { + if (iseffect(s->id)) return; + } if (isbullet(s->id)) return; //if (isonladder(s) && !s->falling && !s->jumping) { @@ -4759,7 +4937,10 @@ void dogravity(sprite_t *s) { s->climbing = B_FALSE; } } else if ((s->id == P_SNAIL) && (s->lives == 0) && s->falling) { - // snail dies + // snail dies - this is actuall the snail's shell + s->dead = D_FINAL; + } else if ((s->id == P_KSSHELL) && s->falling) { + // king snail's shell dies when it hits the ground s->dead = D_FINAL; } else { // everyone else s->dropping = B_FALSE; @@ -5163,15 +5344,19 @@ int movex(sprite_t *s,double amt) { cury = s->y; /* check for blockage to E/W */ - newx = s->x + (amtdir*(s->img->w/2)) ; - //newx = s->x + (amtdir*TILEW/2); - newy = cury-TILEH; - tt2 = gettileat(newx,newy,&newtilex,&newtiley); - if (tt2->solid == S_SOLID) { - return B_TRUE; - } - if (tt2->solid == S_SLOPE && (!candoslopes(s->id))) { - return B_TRUE; + if ((s->id == P_SNAIL) && (s->jumping) && (boss)) { + // unless we're a snail on kingsnail level + } else { + newx = s->x + (amtdir*(s->img->w/2)) ; + //newx = s->x + (amtdir*TILEW/2); + newy = cury-TILEH; + tt2 = gettileat(newx,newy,&newtilex,&newtiley); + if (tt2->solid == S_SOLID) { + return B_TRUE; + } + if (tt2->solid == S_SLOPE && (!candoslopes(s->id))) { + return B_TRUE; + } } // if falling, check the tile directly to our SW/SEtoo */ @@ -6382,6 +6567,8 @@ int getmonjumpspeed(sprite_t *s ) { } else { // jumping horizontally return 3; } + case P_KINGSNAIL: + return 3; default: return MONJUMPSPEED; } @@ -6393,6 +6580,8 @@ int getjumpdelay(int mid) { switch (mid) { case P_SLUG: return 30; + case P_KINGSNAIL: + return 60; default: return 60; } diff --git a/rc.h b/rc.h index 03e274f..fed39c0 100644 --- a/rc.h +++ b/rc.h @@ -45,7 +45,7 @@ void channeldone(int channel); void movetostart(sprite_t *p, int dstx, int dsty, double xspeed,double yspeed); SDL_Surface *grabbehind(sprite_t *s, SDL_Surface *surf); void dumpsprites(void); -int countmonsters(void); +int countmonsters(int montype); int getpoints(int id); int isladder(int tid); char *addcommas(char *buffer, int num); diff --git a/shared.c b/shared.c index 129942f..6307eff 100644 --- a/shared.c +++ b/shared.c @@ -664,6 +664,10 @@ void setdefaults(sprite_t *s) { s->timer1 = 0; s->timer2 = KR_WALKTIME; s->timer3 = 0; + } else if (s->id == P_KINGSNAIL) { + s->timer1 = KSS_WALK1; + s->timer2 = KS_WALKTIME; + s->timer3 = 0; } if (isboss(s->id)) { s->lives = getbosshealth(s->id); // health @@ -1140,11 +1144,17 @@ int loadimagesets(void) { loadspriteimage(P_KINGSNAIL,F_WALK1, "sprites/kingsnail.png"); loadspriteimage(P_KINGSNAIL,F_JUMP, "sprites/kingsnailjump.png"); loadspriteimage(P_KINGSNAIL,F_FALL, "sprites/kingsnailjump.png"); - loadspriteimage(P_KINGSNAIL,F_CAUGHT, "sprites/kingsnailcaught.png"); + loadspriteimage(P_KINGSNAIL,F_CAUGHT, "sprites/kingsnail_broken.png"); loadspriteimage(P_KINGSNAIL,F_DEAD, "sprites/kingsnaildead.png"); /* next 3 are auto genesnailed */ imageset[P_KINGSNAIL].numimages = 8; + loadspriteimage(P_KSSHELL,F_WALK1, "sprites/kingsnail_shell.png"); + imageset[P_KSSHELL].numimages = 1; + // manually do flipped one + imageset[P_KSSHELL].img[MAXFRAMES] = rotozoomSurfaceXY(imageset[P_KSSHELL].img[0], 0, -1,1,0); + + loadspriteimage(P_SNAIL,F_WALK1, "sprites/snail.png"); loadspriteimage(P_SNAIL,F_JUMP, "sprites/snailwalk2.png"); loadspriteimage(P_SNAIL,F_FALL, "sprites/snailwalk2.png"); @@ -1595,6 +1605,8 @@ void drawsprite(sprite_t *s) { } } else if (s->id == P_GLOVE) { frame = F_WALK1; + } else if (s->id == P_KSSHELL) { + frame = F_WALK1; } else if (s->id == P_MACE) { frame = F_WALK1; } else if (s->id == P_CANNON) { @@ -1641,6 +1653,35 @@ void drawsprite(sprite_t *s) { } else { frame = F_DEAD + ((timer/2) % 4); } + } else if (s->id == P_KINGSNAIL) { + // frame based on state + switch (s->timer1) { + case KSS_WALK1: + case KSS_WALK2: + default: + if ((timer/12) % 2 == 0) { + frame = F_WALK1; + } else { + frame = F_JUMP; + } + break; + case KSS_PAUSE1: + case KSS_PAUSE2: + case KSS_PAUSE3: + frame = F_WALK1; + break; + case KSS_SHOOT: + case KSS_REGEN: + if (s->timer3 < 100) { + frame = F_CAUGHT; // ie. broken shell + } else { + frame = F_WALK1; + } + break; + case KSS_JUMPING: + frame = F_JUMP; + break; + } } else if (s->caughtby) { frame = F_CAUGHT; } else if (s->climbing) { @@ -1719,7 +1760,7 @@ void drawsprite(sprite_t *s) { if (s->dir == -1) { frame += MAXFRAMES; } - } else if (s->id == P_GLOVE) { + } else if ((s->id == P_GLOVE) || (s->id == P_KSSHELL)) { if (s->dir == -1) { frame += MAXFRAMES; } @@ -1836,6 +1877,31 @@ void drawsprite(sprite_t *s) { drawplayer(s, &area); } else { doblit(s->img, screen, &area); + // king snail regenerating shell... + if ((s->id == P_KINGSNAIL) && (s->timer1 == KSS_REGEN)) { + SDL_Surface *shellimg, *srcimg; + SDL_Rect newarea; + double pct; + // shell image -left or right? + if (s->dir == 1) { + srcimg = imageset[P_KSSHELL].img[0]; + } else { + srcimg = imageset[P_KSSHELL].img[MAXFRAMES]; + } + // generate new shell at correct size ... + pct = ((double)s->timer3 / 100); + if (pct > 1) pct = 1; + shellimg = rotozoomSurfaceXY(srcimg,0, pct, pct ,0); + // blit it + newarea.x = s->x - (shellimg->w/2) - 21; + newarea.y = s->y - (shellimg->h/2) - 28; + newarea.w = 0; + newarea.h = 0; + SDL_BlitSurface(shellimg, NULL, screen, &newarea); + // free it + SDL_FreeSurface(shellimg); + + } } } @@ -2076,6 +2142,7 @@ int iseffect(int id) { case P_PUFF: case P_SPARKLE: case P_SMASH: + case P_KSSHELL: case P_POWERUPPOS: case P_GLOVE: case P_MACE: