Movement tweaking

This commit is contained in:
Rob Pearce 2006-01-29 22:08:01 +00:00
parent 6045f2ffed
commit 22deb49a43
3 changed files with 54 additions and 29 deletions

View File

@ -18,7 +18,7 @@ bg 0
*~0000000000000000r0000000000000000000=* *~0000000000000000r0000000000000000000=*
*00000000000000~~~~~~~~~~0000000000000=* *00000000000000~~~~~~~~~~0000000000000=*
*0000000000000000000000000000000000000=* *0000000000000000000000000000000000000=*
*>>>00000000000000000000000000000000<<<* *>>>00000000000000000000000000000000<<~*
****>0000000000000000r0000000000000<000* ****>0000000000000000r0000000000000<000*
*****>000000000~~~~~~~~~~000000000<0000* *****>000000000~~~~~~~~~~000000000<0000*
******>>>0000000000000000000000<<<00000* ******>>>0000000000000000000000<<<00000*

73
rc.c
View File

@ -139,21 +139,33 @@ int main (int argc, char **argv) {
if (keys[SDLK_UP]) { if (keys[SDLK_UP]) {
if (isonladder(player) || isladderabove(player)) { if (isonladder(player) || isladderabove(player)) {
player->y -= player->speed; player->y -= player->speed;
player->jumping = 0;
player->falling = 0;
player->climbing = B_TRUE;
}
}
if (keys[SDLK_DOWN]) {
if (isonladder(player)) {
player->y += player->speed;
player->jumping = 0;
player->falling = 0;
player->climbing = B_TRUE;
} }
} }
if (keys[SDLK_x]) { if (keys[SDLK_x]) {
if (!player->jumping) { if (!player->jumping) {
if (!player->falling) { if (!player->falling) {
if (isonground(player) || isonladder(player)) { if (isonground(player) || isonladder(player)) {
player->jumping = 1; int whichway;
player->climbing = B_FALSE;
if (keys[SDLK_RIGHT]) { if (keys[SDLK_RIGHT]) {
player->jumpdir = 1; whichway = 1;
} else if (keys[SDLK_LEFT]) { } else if (keys[SDLK_LEFT]) {
player->jumpdir = -1; whichway = -1;
} else { } else {
player->jumpdir = 0; whichway = 0;
} }
player->jumpspeed = 5; jump(player, whichway);
} }
} }
} }
@ -221,6 +233,17 @@ int main (int argc, char **argv) {
} }
void jump(sprite_t *s, int dir) {
if (isonground(s)) {
s->jumpdir = dir;
if (s->jumpdir != 0) {
s->dir = s->jumpdir;
}
s->jumping = 1;
s->jumpspeed = 5;
}
}
void die(sprite_t *s) { void die(sprite_t *s) {
sprite_t *s2; sprite_t *s2;
/* release anything we've caught */ /* release anything we've caught */
@ -464,7 +487,9 @@ void movesprite(sprite_t *s) {
if (isonground(s)) { if (isonground(s)) {
if ((!s->falling) && (!s->jumping)) { if ((!s->falling) && (!s->jumping)) {
adjustheight(s); if (!s->climbing) {
adjustheight(s);
}
} }
} }
@ -491,13 +516,9 @@ void movesprite(sprite_t *s) {
} else if (player->y == s->y) { } else if (player->y == s->y) {
/* if player is at same level and close, jump */ /* if player is at same level and close, jump */
if ((s->dir == 1) && (xdiff > 0) && (xdiff <= (TILEW*7))) { if ((s->dir == 1) && (xdiff > 0) && (xdiff <= (TILEW*7))) {
s->jumping = 1; jump(s,1);
s->jumpdir = 1;
s->jumpspeed = 5;
} else if ((s->dir == -1) && (xdiff < 0) && (xdiff >= -(TILEW*7))) { } else if ((s->dir == -1) && (xdiff < 0) && (xdiff >= -(TILEW*7))) {
s->jumping = 1; jump(s,-1);
s->jumpdir = -1;
s->jumpspeed = 5;
} }
} }
} else { } else {
@ -520,31 +541,25 @@ void movesprite(sprite_t *s) {
if (player->y < s->y) { if (player->y < s->y) {
if ((xdiff >= (TILEW*2)) && (xdiff <= (TILEW*3))) { if ((xdiff >= (TILEW*2)) && (xdiff <= (TILEW*3))) {
/* jump right */ /* jump right */
s->jumpdir = 1; jump(s, 1);
s->jumping = 1;
s->jumpspeed = 5;
} else if ((xdiff <= -(TILEW*2)) && (xdiff >= -(TILEW*3))) { } else if ((xdiff <= -(TILEW*2)) && (xdiff >= -(TILEW*3))) {
/* jump left */ /* jump left */
s->jumpdir = -1; jump(s, -1);
s->jumping = 1;
s->jumpspeed = 5;
} else if (s->y - player->y <= (TILEH*6)) { } else if (s->y - player->y <= (TILEH*6)) {
if ((xdiff >= 0) && (xdiff < (TILEW*2))) { if ((xdiff >= 0) && (xdiff < (TILEW*2))) {
/* jump up */ /* jump up */
s->jumpdir = 0; jump(s, 0);
s->jumping = 1;
s->jumpspeed = 5;
} else if ((xdiff <= 0) && (xdiff > -(TILEW*2))) { } else if ((xdiff <= 0) && (xdiff > -(TILEW*2))) {
/* jump up */ /* jump up */
s->jumpdir = 0; jump(s, 0);
s->jumping = 1;
s->jumpspeed = 5;
} }
} else { } else {
/* jump whichever way we're facing */ /* jump whichever way we're facing */
/*
s->jumpdir = s->dir; s->jumpdir = s->dir;
s->jumping = 1; s->jumping = 1;
s->jumpspeed = 5; s->jumpspeed = 5;
*/
} }
} }
} }
@ -895,7 +910,9 @@ int loadimagesets(void) {
imageset[P_PLAYER].img[F_CAUGHT] = IMG_Load("pdwarf.png"); imageset[P_PLAYER].img[F_CAUGHT] = IMG_Load("pdwarf.png");
imageset[P_PLAYER].img[F_DEAD] = IMG_Load("dwarfdie.png"); imageset[P_PLAYER].img[F_DEAD] = IMG_Load("dwarfdie.png");
/* next 3 are auto generated */ /* next 3 are auto generated */
imageset[P_PLAYER].numimages = 8; imageset[P_PLAYER].img[F_CLIMB1] = IMG_Load("dclimb1.png");
imageset[P_PLAYER].img[F_CLIMB2] = IMG_Load("dclimb2.png");
imageset[P_PLAYER].numimages = 10;
imageset[P_RAT].img[F_WALK1] = IMG_Load("rat.bmp"); imageset[P_RAT].img[F_WALK1] = IMG_Load("rat.bmp");
imageset[P_RAT].img[F_JUMP] = IMG_Load("ratjump.bmp"); imageset[P_RAT].img[F_JUMP] = IMG_Load("ratjump.bmp");
@ -1077,6 +1094,7 @@ void killtext(text_t *t) {
void setdefaults(sprite_t *s) { void setdefaults(sprite_t *s) {
s->speed = getspeed(s->id); s->speed = getspeed(s->id);
s->climbing = 0;
s->jumping = 0; s->jumping = 0;
s->jumpdir = 1; s->jumpdir = 1;
s->netting = 0; s->netting = 0;
@ -1234,6 +1252,8 @@ void drawsprite(sprite_t *s) {
} }
} else if (s->caughtby) { } else if (s->caughtby) {
frame = F_CAUGHT; frame = F_CAUGHT;
} else if (s->climbing) {
frame = F_CLIMB1 + ((timer/12) % 2);
} else if (s->jumping) { } else if (s->jumping) {
frame = F_JUMP; frame = F_JUMP;
} else if (s->falling) { } else if (s->falling) {
@ -1443,6 +1463,7 @@ void dogravity(sprite_t *s) {
sprite_t *s2; sprite_t *s2;
if (s->dead) return; if (s->dead) return;
if (isonladder(s) && !s->falling && !s->jumping) { if (isonladder(s) && !s->falling && !s->jumping) {
s->falling = B_FALSE; s->falling = B_FALSE;
return; return;
@ -1463,13 +1484,13 @@ void dogravity(sprite_t *s) {
} else { } else {
if (isonground(s)) { if (isonground(s)) {
s->falling = B_FALSE; s->falling = B_FALSE;
s->climbing = B_FALSE;
} else { } else {
if (s->falling == B_FALSE) { if (s->falling == B_FALSE) {
s->fallspeed = 1; s->fallspeed = 1;
} }
s->falling = B_TRUE; s->falling = B_TRUE;
s->y += s->fallspeed; s->y += s->fallspeed;
//adjustheight(s);
if ((timer % 10 == 0) && (s->fallspeed < FALLSPEED)) { if ((timer % 10 == 0) && (s->fallspeed < FALLSPEED)) {
s->fallspeed++; s->fallspeed++;
} }

8
rc.h
View File

@ -11,7 +11,7 @@
#define MAXLETTERHEIGHT 100 #define MAXLETTERHEIGHT 100
#define MAXPTYPES 3 #define MAXPTYPES 3
#define MAXFRAMES 8 #define MAXFRAMES 10
#define TILEH 16 #define TILEH 16
#define TILEW 16 #define TILEW 16
@ -89,6 +89,7 @@ typedef struct sprite_s {
int caughtstate; int caughtstate;
int jumpspeed; int jumpspeed;
int climbing;
int slamming; int slamming;
double slamangle; double slamangle;
int netting; int netting;
@ -151,6 +152,8 @@ int isfruit(int id);
int ismonster(int id); int ismonster(int id);
void killsprite(sprite_t *s); void killsprite(sprite_t *s);
void checkcollide(sprite_t *s); void checkcollide(sprite_t *s);
void die(sprite_t *s);
void jump(sprite_t *s, int dir);
double getspeed(int id); double getspeed(int id);
void adjustheight(sprite_t *s); void adjustheight(sprite_t *s);
void setdefaults(sprite_t *s); void setdefaults(sprite_t *s);
@ -171,6 +174,8 @@ void setdefaults(sprite_t *s);
#define F_DEAD2 5 #define F_DEAD2 5
#define F_DEAD3 6 #define F_DEAD3 6
#define F_DEAD4 7 #define F_DEAD4 7
#define F_CLIMB1 8
#define F_CLIMB2 9
#define T_BLANK 0 #define T_BLANK 0
#define T_LAND 1 #define T_LAND 1
@ -188,4 +193,3 @@ void setdefaults(sprite_t *s);
inline void drawpixel16(SDL_Surface *screen, int x, int y, SDL_Color c); inline void drawpixel16(SDL_Surface *screen, int x, int y, SDL_Color c);
inline void drawbox16(SDL_Surface *screen, int x1,int y1,int x2,int y2,SDL_Color *c,SDL_Color *fc); inline void drawbox16(SDL_Surface *screen, int x1,int y1,int x2,int y2,SDL_Color *c,SDL_Color *fc);
void drawline16(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c); void drawline16(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c);