Use walking animation
This commit is contained in:
parent
c5daa136c1
commit
f17530af4a
21
app/main.c
21
app/main.c
@ -30,13 +30,14 @@
|
||||
#define TSCOLS 56
|
||||
|
||||
#define PIDLE_ASSET "/player/idle.png"
|
||||
#define PWALK_ASSET "/player/walk.png"
|
||||
#define PWIDTH 48
|
||||
#define PHEIGHT 64
|
||||
#define PANIMLEN 8
|
||||
|
||||
#define WALKSPEED 72 // pixels per second
|
||||
|
||||
#define BASEANIMPERIOD 200
|
||||
#define BASEANIMPERIOD 100
|
||||
|
||||
typedef enum {
|
||||
SPRITE_DIR_DOWN = 0,
|
||||
@ -58,7 +59,7 @@ typedef struct {
|
||||
static SDL_Window *window;
|
||||
static SDL_Renderer *renderer;
|
||||
static unsigned map[MAPWIDTH][MAPHEIGHT];
|
||||
static SDL_Texture *tstex, *pidle;
|
||||
static SDL_Texture *tstex, *pidle, *pwalk, *ptex;
|
||||
static input_state_t input;
|
||||
|
||||
static inline double mag(dvec_t v)
|
||||
@ -163,12 +164,17 @@ int main(int argc, char *argv[])
|
||||
tstex = IMG_LoadTexture(renderer, path);
|
||||
assert(NULL != tstex);
|
||||
|
||||
// Load player idle spritesheet
|
||||
// Load player spritesheets
|
||||
assert(strlen(argv[1]) + strlen(PIDLE_ASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, argv[1]);
|
||||
strcat(path, PIDLE_ASSET);
|
||||
pidle = IMG_LoadTexture(renderer, path);
|
||||
assert(NULL != pidle);
|
||||
assert(strlen(argv[1]) + strlen(PWALK_ASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, argv[1]);
|
||||
strcat(path, PWALK_ASSET);
|
||||
pwalk = IMG_LoadTexture(renderer, path);
|
||||
assert(NULL != pwalk);
|
||||
|
||||
// Initialize view and player
|
||||
dvec_t vpos = { 512, 0 };
|
||||
@ -176,6 +182,7 @@ int main(int argc, char *argv[])
|
||||
SDL_Rect pdest = { .w = SCALE * PWIDTH, .h = SCALE * PHEIGHT };
|
||||
dvec_t pvel = { 0, 0 }, ppos = { 640, 96 };
|
||||
sprite_dir_t pdir = SPRITE_DIR_DOWN;
|
||||
ptex = pidle;
|
||||
|
||||
SDL_Event event;
|
||||
uint64_t prevt = SDL_GetTicks64();
|
||||
@ -259,6 +266,11 @@ int main(int argc, char *argv[])
|
||||
else
|
||||
pdir = SPRITE_DIR_UP;
|
||||
}
|
||||
|
||||
// Set walkikng texture
|
||||
ptex = pwalk;
|
||||
} else {
|
||||
ptex = pidle;
|
||||
}
|
||||
|
||||
// Update view
|
||||
@ -307,8 +319,7 @@ int main(int argc, char *argv[])
|
||||
psrc.y = PHEIGHT * pdir;
|
||||
pdest.x = SCALE * (int)(ppos.x - vpos.x - PWIDTH / 2);
|
||||
pdest.y = SCALE * (int)(ppos.y - vpos.y - PHEIGHT / 2);
|
||||
SDL_RenderCopy(renderer, pidle, &psrc, &pdest);
|
||||
|
||||
SDL_RenderCopy(renderer, ptex, &psrc, &pdest);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user