From 67c4d16d9276f1761fcb437cb2ebf1ab52067296 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Wed, 26 Nov 2008 03:24:03 +0000 Subject: [PATCH] Modified ice inertia to be more realistic --- data/levels/level99.dat | 16 ++-- defs.h | 5 ++ rc.c | 181 +++++++++++++++++++++++++++++----------- rc.h | 3 +- 4 files changed, 145 insertions(+), 60 deletions(-) diff --git a/data/levels/level99.dat b/data/levels/level99.dat index 58b24b5..c3d14fc 100644 --- a/data/levels/level99.dat +++ b/data/levels/level99.dat @@ -6,7 +6,7 @@ endhelp monsters 0 5 23 134 37 24 -50 11 23 +6 20 10 endmonsters exitdir 1 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, @@ -17,6 +17,11 @@ exitdir 1 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, +4,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, +4,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, +4,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, +4,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, +4,0,0,0,0,0,0,0,0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,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,4, -4,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,4, -4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, -4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, -4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, -4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, +4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4, layer2 diff --git a/defs.h b/defs.h index f1058d7..8321db8 100644 --- a/defs.h +++ b/defs.h @@ -203,6 +203,11 @@ #define BELLTIME 20 // how long the bell flash lasts #define CLOCKTIME 10 // how many seconds a clock lasts + +// ice +#define ICEACCEL 0.1 +#define ICEDECCEL 0 + // blackcloud #define CLOUDGROWSPEED 25 // lower is faster #define CLOUDGROWAMT 0.01 // lower is faster diff --git a/rc.c b/rc.c index a3fc7cd..5f7127b 100644 --- a/rc.c +++ b/rc.c @@ -1396,7 +1396,6 @@ void jump(sprite_t *s, int dir) { s->jumping = 1; s->dir = -s->jumpdir; // face backwards } else { - // TODO: check this (the * getspeed bit)! //s->jumpdir = s->dir * getspeed(s); s->jumpdir = dir; if (s->jumpdir != 0) { @@ -1449,13 +1448,17 @@ void jump(sprite_t *s, int dir) { if (!haspowerup(s, P_SPEED) == 1) s->jumpdir--; // go fast even if player is slow } } else { + tt= gettileat(s->x, s->y, NULL, NULL); // if on rollers, they add to your inertia // if you are facing their direction - tt= gettileat(s->x, s->y, NULL, NULL); if ((tt->id == T_RIGHT) && (s->jumpdir > 0)) { s->jumpdir++; } else if ((tt->id == T_LEFT) && (s->jumpdir < 0)) { s->jumpdir--; + } else if (isice(tt->id)) { + s->jumpdir = s->xs / getspeed(s); + //if (s->jumpdir > getspeed(s)) s->jumpdir -= getspeed(s); + //if (s->jumpdir < -getspeed(s)) s->jumpdir += getspeed(s); } } @@ -2478,7 +2481,7 @@ int movesprite(sprite_t *s) { } } else if (s->jumping) { if (s->id != P_KINGRAT) { - movex(s, s->jumpdir*getspeed(s)); + movex(s, s->jumpdir*getspeed(s), B_TRUE); } return B_FALSE; } @@ -2964,7 +2967,7 @@ int movesprite(sprite_t *s) { xpoint = (curlevel->powerupx * TILEW) + (TILEW/2); if (s->x <= xpoint) { int rv = B_FALSE; - rv = movex(s, s->speed); + rv = movex(s, s->speed, B_TRUE); } } else { // not in intro sequence if (!s->falling) { @@ -3016,7 +3019,7 @@ int movesprite(sprite_t *s) { /* either move or turn around */ if (move) { - rv = movex(s, s->dir*getspeed(s)); + rv = movex(s, s->dir*getspeed(s), B_TRUE); if (rv) { /* if we couldn't move (hit a wall), turn */ s->dir = -s->dir; @@ -3064,9 +3067,9 @@ int movesprite(sprite_t *s) { tunder = gettileat(s->x ,s->y,NULL,NULL); t2under = gettileat(s->x ,s->y+s->img->h,NULL,NULL); if ((tunder->solid == S_SLOPE) || (t2under->solid == S_SLOPE)) { - movex(s, s->dir*getspeed(s)); + movex(s, s->dir*getspeed(s), B_TRUE); } else if (s->jumpdir) { - movex(s, s->jumpdir*getspeed(s)); + movex(s, s->jumpdir*getspeed(s), B_TRUE); } } } // end if inintro @@ -3103,7 +3106,7 @@ int movesprite(sprite_t *s) { /* either move or turn around */ if (move) { - rv = movex(s, s->dir*getspeed(s)); + rv = movex(s, s->dir*getspeed(s), B_TRUE); if (rv) { /* if we couldn't move (hit a wall), turn */ s->dir = -s->dir; @@ -3149,9 +3152,9 @@ int movesprite(sprite_t *s) { } else { // falling if (s->recoiling) { // fall backwards - rv = movex(s, -s->dir*getspeed(s)); + rv = movex(s, -s->dir*getspeed(s), B_TRUE); } else if (s->jumpdir) { - movex(s, s->jumpdir*getspeed(s)); + movex(s, s->jumpdir*getspeed(s), B_TRUE); } } } else if (s->id == P_SLUG) { @@ -3199,7 +3202,7 @@ int movesprite(sprite_t *s) { /* either move or turn around */ if (move) { - rv = movex(s, s->dir*getspeed(s)); + rv = movex(s, s->dir*getspeed(s), B_TRUE); if (rv) { /* if we couldn't move (hit a wall), turn */ s->dir = -s->dir; @@ -3250,7 +3253,7 @@ int movesprite(sprite_t *s) { } else { // falling int rv; // move forwards - rv = movex(s, s->dir*getspeed(s)); + rv = movex(s, s->dir*getspeed(s), B_TRUE); } } else if (s->id == P_PLANT) { // don't move! @@ -3267,7 +3270,7 @@ int movesprite(sprite_t *s) { int canseeplayer = B_TRUE; int ydis; // move - rv = movex(s, s->dir*getspeed(s)); + rv = movex(s, s->dir*getspeed(s), B_TRUE); if (rv) { /* if we couldn't move (hit a wall), turn */ s->dir = -s->dir; @@ -3341,7 +3344,7 @@ int movesprite(sprite_t *s) { } else if (s->timer1 == KRS_CHARGE) { int rv; // move fast forwards - rv = movex(s, s->dir*KR_CHARGESPEED); + rv = movex(s, s->dir*KR_CHARGESPEED, B_TRUE); if (rv) { // hit a wall - get stunned s->timer1 = KRS_STUN; @@ -3417,7 +3420,7 @@ int movesprite(sprite_t *s) { */ if ((s->timer1 == KSS_WALK1) || (s->timer1 == KSS_WALK2)) { // walk back and forth - rv = movex(s, s->dir*getspeed(s)); + rv = movex(s, s->dir*getspeed(s), B_TRUE); if (rv) { /* if we couldn't move (hit a wall), turn */ s->dir = -s->dir; @@ -3871,7 +3874,7 @@ printf("setting target to y = %d\n",ss->timer2); for (ii = 0; ii < amt; ii++) { //s2->x += dir; - if (movex(s2, dir)) break; + if (movex(s2, dir, B_TRUE)) break; } s2->moved = oldmoved; // so that we don't animate s2->y += ydiff; @@ -3931,7 +3934,7 @@ printf("setting target to y = %d\n",ss->timer2); /* either move or turn around */ if (move) { - rv = movex(s, s->dir*getspeed(s)); + rv = movex(s, s->dir*getspeed(s), B_TRUE); if (rv) { /* if we couldn't move (hit a wall), turn */ s->dir = -s->dir; @@ -3968,7 +3971,7 @@ printf("setting target to y = %d\n",ss->timer2); } } } else { // falling - movex(s, s->jumpdir*getspeed(s)); + movex(s, s->jumpdir*getspeed(s), B_TRUE); } } else if (s->id == P_SNAKE) { /* timer1 loopsfrom 0 - 19 @@ -4070,7 +4073,7 @@ printf("setting target to y = %d\n",ss->timer2); /* either move or turn around */ if (move) { - rv = movex(s, s->dir*getspeed(s)); + rv = movex(s, s->dir*getspeed(s), B_TRUE); if (rv) { /* if we couldn't move (hit a wall), turn */ s->dir = -s->dir; @@ -4112,7 +4115,7 @@ printf("setting target to y = %d\n",ss->timer2); } } } else { // falling - movex(s, s->jumpdir*getspeed(s)); + movex(s, s->jumpdir*getspeed(s), B_TRUE); } } else if (s->id == P_BEE) { @@ -4343,7 +4346,7 @@ printf("setting target to y = %d\n",ss->timer2); /* either move or turn around */ if (move) { - rv = movex(s, s->dir*myspeed); + rv = movex(s, s->dir*myspeed, B_TRUE); if (rv) { /* if we couldn't move (hit a wall), turn */ s->dir = -s->dir; @@ -4394,7 +4397,7 @@ printf("setting target to y = %d\n",ss->timer2); tunder = gettileat(s->x ,s->y,NULL,NULL); t2under = gettileat(s->x ,s->y+s->img->h,NULL,NULL); if ((tunder->solid == S_SLOPE) || (t2under->solid == S_SLOPE)) { - movex(s, s->dir*myspeed); + movex(s, s->dir*myspeed, B_TRUE); // reset walk timer s->timer1 = 0; } @@ -4522,7 +4525,7 @@ printf("setting target to y = %d\n",ss->timer2); /* either move or turn around */ if (move) { - rv = movex(s, s->dir*getspeed(s)); + rv = movex(s, s->dir*getspeed(s), B_TRUE); if (rv) { /* if we couldn't move (hit a wall), turn */ s->dir = -s->dir; @@ -4534,7 +4537,7 @@ printf("setting target to y = %d\n",ss->timer2); } } } else if (s->id == P_SPIT) { - if (movex(s, s->xs)) { + if (movex(s, s->xs, B_TRUE)) { s->dead = D_FINAL; } } else if (s->id == P_PINKCLOUD) { @@ -4818,9 +4821,9 @@ printf("setting target to y = %d\n",ss->timer2); spd = 7 - spd; if (spd > 7) spd = 7; if (who->x > s->x) { - movex(s, spd); + movex(s, spd, B_FALSE); } else if (who->x < s->x) { - movex(s, -spd); + movex(s, -spd, B_FALSE); } } } @@ -4838,9 +4841,9 @@ printf("setting target to y = %d\n",ss->timer2); spd = 7 - spd; if (spd > 7) spd = 7; if (who->x > s->x) { - movex(s, -spd); + movex(s, -spd, B_TRUE); } else if (who->x < s->x) { - movex(s, spd); + movex(s, spd, B_TRUE); } } } @@ -4894,16 +4897,16 @@ void dotileeffects(sprite_t *s) { switch (tt->id) { case T_WATERRIGHT: if (!ismonster(s->id) && !isfruit(s->id)) { - movex(s, 1.5); + movex(s, 1.5, B_TRUE); } else if (s->id == P_PLANT) { - movex(s, 1.5); + movex(s, 1.5, B_TRUE); } break; case T_WATERLEFT: if (!ismonster(s->id) && !isfruit(s->id)) { - movex(s, -1.5); + movex(s, -1.5, B_TRUE); } else if (s->id == P_PLANT) { - movex(s, -1.5); + movex(s, -1.5, B_TRUE); } break; case T_WATERDOWN: @@ -4924,27 +4927,38 @@ void dotileeffects(sprite_t *s) { if (tt->id == T_RIGHT) { if (globpowerup != PW_CLOCK) { if (!ismonster(s->id) && !isfruit(s->id)) { - movex(s, 1.5); + movex(s, 1.5, B_FALSE); } else if (s->id == P_PLANT) { - movex(s, 1.5); + movex(s, 1.5, B_FALSE); } } finished = B_TRUE; } else if (tt->id == T_LEFT) { if (globpowerup != PW_CLOCK) { if (!ismonster(s->id) && !isfruit(s->id)) { - movex(s, -1.5); + movex(s, -1.5, B_FALSE); } else if (s->id == P_PLANT) { - movex(s, -1.5); + movex(s, -1.5, B_FALSE); } } finished = B_TRUE; - } else if ((tt->id == T_ICE) || (tt->id == T_ICETOP)) { + } else if (isice(tt->id)) { if (isplayer(s)) { if (globpowerup != PW_CLOCK) { if (!s->moved) { - movex(s, s->dir*s->speed); - s->moved = MV_ICE; + if (s->xs != 0) { + // slide along the ground + movex(s, s->xs, B_FALSE); + + // slow down + if (s->xs > 0) { + s->xs -= ICEDECCEL; + if (s->xs < 0) s->xs = 0; + } else if (s->xs < 0) { + s->xs += ICEDECCEL; + if (s->xs > 0) s->xs = 0; + } + } } } } @@ -6818,6 +6832,13 @@ void dogravity(sprite_t *s) { } s->falling = B_TRUE; + if (isplayer(s)) { + // stop ice inertia + if (!s->moved) { + s->xs = 0; + } + } + if (s->id == P_FLY) { // constant speed - we are flying down, not falling s->y += getspeed(s); @@ -7231,13 +7252,14 @@ void dogravity(sprite_t *s) { } -int movex(sprite_t *s,double amt) { +int movex(sprite_t *s,double amt,int onpurpose) { double newx,newy; double curx,cury; int tilex,tiley; tiletype_t *tt,*tt2; int newxoff,newgroundy; int newtilex,newtiley; + int domove = B_FALSE; double amtdir; @@ -7260,9 +7282,11 @@ int movex(sprite_t *s,double amt) { newy = cury-TILEH; tt2 = gettileat(newx,newy,&newtilex,&newtiley); if (tt2->solid == S_SOLID) { + s->xs = 0; return B_TRUE; } if (tt2->solid == S_SLOPE && (!candoslopes(s->id))) { + s->xs = 0; return B_TRUE; } } @@ -7273,32 +7297,78 @@ int movex(sprite_t *s,double amt) { newy = cury; tt2 = gettileat(newx,newy,&newtilex,&newtiley); if (tt2->solid == S_SOLID) { + s->xs = 0; return B_TRUE; } if (tt2->solid == S_SLOPE && (!candoslopes(s->id))) { + s->xs = 0; return B_TRUE; } } /* get new position */ - newx = curx + amt; + + if (isplayer(s) && isice(tt->id) && onpurpose) { + double newxs; + // change speed + newxs = s->xs + (s->dir*ICEACCEL); + s->xs += (s->dir*ICEACCEL); + // don't get too fast! + if (newxs > getspeed(s)) newxs = getspeed(s); + if (newxs < -getspeed(s)) newxs = -getspeed(s); + + newx = curx + newxs; + amt = newx - curx; + } else { + newx = curx + amt; + } + + + newy = cury-2; tt2 = gettileat(newx,newy,&newtilex,&newtiley); newxoff = newx - (newtilex*TILEW); newgroundy = newtiley*TILEH + tt2->lowness[newxoff]; /* new block is at least partially solid */ + domove = B_FALSE; if (tt2->solid == S_SOLID) { + s->xs = 0; return B_TRUE; } else if ((tt2->solid == S_SLOPE) && candoslopes(s->id)) { /* we can move, but need to adjust our height */ - s->x += amt; + domove = B_TRUE; } else { /* new block is empty */ - s->x += amt; + domove = B_TRUE; } - s->moved = MV_WALK; + if (domove) { + if (isplayer(s) && isice(tt->id) && onpurpose) { + // change speed + s->xs += (s->dir*ICEACCEL); + // don't get too fast! + if (s->xs > getspeed(s)) s->xs = getspeed(s); + if (s->xs < -getspeed(s)) s->xs = -getspeed(s); + + s->x += s->xs; + s->moved = MV_WALK; + } else { + s->x += amt; + s->xs = amt; + if (!onpurpose) { + if (isice(tt->id)) { + s->moved = MV_ICE; + } else { + s->moved = MV_WALK; + } + } else { + s->moved = MV_WALK; + } + } + } else { + s->xs = 0; + } // rings if (isplayer(s)) { @@ -11842,14 +11912,14 @@ void doplayermovement(sprite_t *pl) { if (moveok) { if (keydown(pnum,KEY_RIGHT)) { if (canmove(pl)) { - movex(pl, getspeed(pl)); + movex(pl, getspeed(pl), B_TRUE); } if (canturn(pl)) { pl->dir = D_RIGHT; } } else if (keydown(pnum,KEY_LEFT)) { if (canmove(pl)) { - movex(pl, -getspeed(pl)); + movex(pl, -getspeed(pl), B_TRUE); } if (canturn(pl)) { pl->dir = D_LEFT; @@ -12106,7 +12176,7 @@ void dointroseq(void) { jump(player, D_RIGHT); player->jumpspeed = 7; } else if (player->falling) { - movex(player, getspeed(player)/2); + movex(player, getspeed(player)/2, B_TRUE); } } if (player2) { @@ -12117,7 +12187,7 @@ void dointroseq(void) { jump(player2, D_LEFT); player2->jumpspeed = 7; } else if (player2->falling) { - movex(player2, -getspeed(player2)/2); + movex(player2, -getspeed(player2)/2, B_TRUE); } } } else { @@ -12125,7 +12195,7 @@ void dointroseq(void) { jump(player2, D_LEFT); player2->jumpspeed = 7; } else if (player2->falling) { - movex(player2, -getspeed(player2)/2); + movex(player2, -getspeed(player2)/2, B_TRUE); } } } @@ -12148,7 +12218,7 @@ void dointroseq(void) { // keep moving until we hit the ground if (player) { if (player->falling) { - movex(player, getspeed(player)); + movex(player, getspeed(player), B_TRUE); } if (introstate == IS_RATS2) { @@ -12160,7 +12230,7 @@ void dointroseq(void) { } if (player2) { if (player2->falling) { - movex(player2, -getspeed(player2)); + movex(player2, -getspeed(player2), B_TRUE); } if (introstate == IS_RATS2) { @@ -12285,3 +12355,12 @@ int countbabies(sprite_t *s, int babytype) { } return numbabies; } + +int isice(int id) { + switch (id) { + case T_ICE: + case T_ICETOP: + return B_TRUE; + } + return B_FALSE; +} diff --git a/rc.h b/rc.h index 56d01db..f27b096 100644 --- a/rc.h +++ b/rc.h @@ -12,7 +12,7 @@ void removenetting(sprite_t *s); void drawnetting(sprite_t *s); void dogravity(sprite_t *s); void dotileeffects(sprite_t *s); -int movex(sprite_t *s,double amt); +int movex(sprite_t *s,double amt,int onpurpose); void bouncesprite(sprite_t *s); int movesprite(sprite_t *s); int isinwater(sprite_t *s); @@ -126,3 +126,4 @@ int addcredit(void); int getpnum(sprite_t *s); int isonplatform(double x, double y); int countbabies(sprite_t *s, int babytype); +int isice(int id);