Movement tweaking
This commit is contained in:
parent
6045f2ffed
commit
22deb49a43
|
@ -18,7 +18,7 @@ bg 0
|
|||
*~0000000000000000r0000000000000000000=*
|
||||
*00000000000000~~~~~~~~~~0000000000000=*
|
||||
*0000000000000000000000000000000000000=*
|
||||
*>>>00000000000000000000000000000000<<<*
|
||||
*>>>00000000000000000000000000000000<<~*
|
||||
****>0000000000000000r0000000000000<000*
|
||||
*****>000000000~~~~~~~~~~000000000<0000*
|
||||
******>>>0000000000000000000000<<<00000*
|
||||
|
|
71
rc.c
71
rc.c
|
@ -139,21 +139,33 @@ int main (int argc, char **argv) {
|
|||
if (keys[SDLK_UP]) {
|
||||
if (isonladder(player) || isladderabove(player)) {
|
||||
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 (!player->jumping) {
|
||||
if (!player->falling) {
|
||||
if (isonground(player) || isonladder(player)) {
|
||||
player->jumping = 1;
|
||||
int whichway;
|
||||
player->climbing = B_FALSE;
|
||||
if (keys[SDLK_RIGHT]) {
|
||||
player->jumpdir = 1;
|
||||
whichway = 1;
|
||||
} else if (keys[SDLK_LEFT]) {
|
||||
player->jumpdir = -1;
|
||||
whichway = -1;
|
||||
} 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) {
|
||||
sprite_t *s2;
|
||||
/* release anything we've caught */
|
||||
|
@ -464,9 +487,11 @@ void movesprite(sprite_t *s) {
|
|||
|
||||
if (isonground(s)) {
|
||||
if ((!s->falling) && (!s->jumping)) {
|
||||
if (!s->climbing) {
|
||||
adjustheight(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s->id == P_RAT) {
|
||||
if (!s->falling) {
|
||||
|
@ -491,13 +516,9 @@ void movesprite(sprite_t *s) {
|
|||
} else if (player->y == s->y) {
|
||||
/* if player is at same level and close, jump */
|
||||
if ((s->dir == 1) && (xdiff > 0) && (xdiff <= (TILEW*7))) {
|
||||
s->jumping = 1;
|
||||
s->jumpdir = 1;
|
||||
s->jumpspeed = 5;
|
||||
jump(s,1);
|
||||
} else if ((s->dir == -1) && (xdiff < 0) && (xdiff >= -(TILEW*7))) {
|
||||
s->jumping = 1;
|
||||
s->jumpdir = -1;
|
||||
s->jumpspeed = 5;
|
||||
jump(s,-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -520,31 +541,25 @@ void movesprite(sprite_t *s) {
|
|||
if (player->y < s->y) {
|
||||
if ((xdiff >= (TILEW*2)) && (xdiff <= (TILEW*3))) {
|
||||
/* jump right */
|
||||
s->jumpdir = 1;
|
||||
s->jumping = 1;
|
||||
s->jumpspeed = 5;
|
||||
jump(s, 1);
|
||||
} else if ((xdiff <= -(TILEW*2)) && (xdiff >= -(TILEW*3))) {
|
||||
/* jump left */
|
||||
s->jumpdir = -1;
|
||||
s->jumping = 1;
|
||||
s->jumpspeed = 5;
|
||||
jump(s, -1);
|
||||
} else if (s->y - player->y <= (TILEH*6)) {
|
||||
if ((xdiff >= 0) && (xdiff < (TILEW*2))) {
|
||||
/* jump up */
|
||||
s->jumpdir = 0;
|
||||
s->jumping = 1;
|
||||
s->jumpspeed = 5;
|
||||
jump(s, 0);
|
||||
} else if ((xdiff <= 0) && (xdiff > -(TILEW*2))) {
|
||||
/* jump up */
|
||||
s->jumpdir = 0;
|
||||
s->jumping = 1;
|
||||
s->jumpspeed = 5;
|
||||
jump(s, 0);
|
||||
}
|
||||
} else {
|
||||
/* jump whichever way we're facing */
|
||||
/*
|
||||
s->jumpdir = s->dir;
|
||||
s->jumping = 1;
|
||||
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_DEAD] = IMG_Load("dwarfdie.png");
|
||||
/* 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_JUMP] = IMG_Load("ratjump.bmp");
|
||||
|
@ -1077,6 +1094,7 @@ void killtext(text_t *t) {
|
|||
|
||||
void setdefaults(sprite_t *s) {
|
||||
s->speed = getspeed(s->id);
|
||||
s->climbing = 0;
|
||||
s->jumping = 0;
|
||||
s->jumpdir = 1;
|
||||
s->netting = 0;
|
||||
|
@ -1234,6 +1252,8 @@ void drawsprite(sprite_t *s) {
|
|||
}
|
||||
} else if (s->caughtby) {
|
||||
frame = F_CAUGHT;
|
||||
} else if (s->climbing) {
|
||||
frame = F_CLIMB1 + ((timer/12) % 2);
|
||||
} else if (s->jumping) {
|
||||
frame = F_JUMP;
|
||||
} else if (s->falling) {
|
||||
|
@ -1443,6 +1463,7 @@ void dogravity(sprite_t *s) {
|
|||
sprite_t *s2;
|
||||
|
||||
if (s->dead) return;
|
||||
|
||||
if (isonladder(s) && !s->falling && !s->jumping) {
|
||||
s->falling = B_FALSE;
|
||||
return;
|
||||
|
@ -1463,13 +1484,13 @@ void dogravity(sprite_t *s) {
|
|||
} else {
|
||||
if (isonground(s)) {
|
||||
s->falling = B_FALSE;
|
||||
s->climbing = B_FALSE;
|
||||
} else {
|
||||
if (s->falling == B_FALSE) {
|
||||
s->fallspeed = 1;
|
||||
}
|
||||
s->falling = B_TRUE;
|
||||
s->y += s->fallspeed;
|
||||
//adjustheight(s);
|
||||
if ((timer % 10 == 0) && (s->fallspeed < FALLSPEED)) {
|
||||
s->fallspeed++;
|
||||
}
|
||||
|
|
8
rc.h
8
rc.h
|
@ -11,7 +11,7 @@
|
|||
#define MAXLETTERHEIGHT 100
|
||||
|
||||
#define MAXPTYPES 3
|
||||
#define MAXFRAMES 8
|
||||
#define MAXFRAMES 10
|
||||
|
||||
#define TILEH 16
|
||||
#define TILEW 16
|
||||
|
@ -89,6 +89,7 @@ typedef struct sprite_s {
|
|||
int caughtstate;
|
||||
|
||||
int jumpspeed;
|
||||
int climbing;
|
||||
int slamming;
|
||||
double slamangle;
|
||||
int netting;
|
||||
|
@ -151,6 +152,8 @@ int isfruit(int id);
|
|||
int ismonster(int id);
|
||||
void killsprite(sprite_t *s);
|
||||
void checkcollide(sprite_t *s);
|
||||
void die(sprite_t *s);
|
||||
void jump(sprite_t *s, int dir);
|
||||
double getspeed(int id);
|
||||
void adjustheight(sprite_t *s);
|
||||
void setdefaults(sprite_t *s);
|
||||
|
@ -171,6 +174,8 @@ void setdefaults(sprite_t *s);
|
|||
#define F_DEAD2 5
|
||||
#define F_DEAD3 6
|
||||
#define F_DEAD4 7
|
||||
#define F_CLIMB1 8
|
||||
#define F_CLIMB2 9
|
||||
|
||||
#define T_BLANK 0
|
||||
#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 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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue