Animation system, created elevator animation

This commit is contained in:
KikooDX 2020-02-18 11:48:02 +01:00
parent 7bdaea1ac3
commit f583c69896
21 changed files with 76 additions and 22 deletions

BIN
assets-cg/img/elevator1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

BIN
assets-cg/img/elevator2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

BIN
assets-cg/img/elevator3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

BIN
assets-cg/img/elevator4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

BIN
assets-cg/img/elevator5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

BIN
assets-cg/img/elevator6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

BIN
assets-cg/img/elevator7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

BIN
assets-cg/img/elevator8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

BIN
assets-cg/img/elevator9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

View File

@ -1,4 +1,5 @@
void draw_player(int old_x, int old_y, int x, int y);
void draw_level(char level[], char upgrades[]);
void draw_level_anims(char level[], char upgrades[], unsigned int step);
void erase_tile(int x, int y, char level[]);
void draw_upgrade_message(char item);

View File

@ -19,11 +19,11 @@ levels = {[5049] = [[
-00..000000000000..0000^.00-
-00.00000000000v...0000^.00-
-00..0000000000..000000^.00-
-00..00000000v...000000^.000
-00..00000000v...000000^.00-
-00..00000000..00000000^...-
-000.000000v...00000000^...-
-000.........0000000000^...-
-000....j....000000000000000
-000....j....00000000000000-
-00000000000000000000000000-
-00000000000000000000000000-
----------------------------
@ -32,17 +32,17 @@ levels = {[5049] = [[
----------------------------
-0000000....000000000000000-
-0000000....000000000000000-
-00000000....000000000000000
-00000000....00000000000000-
-00000000..................-
-00000000..................-
-0000000000.....000000000000
-0000000000.....00000000000-
-0000000000.....00000000000-
-00000000..........00000000-
000000.............00000000-
-00000.............00000000-
-.............0000000000000-
-..........0000000000000000-
-.......0000000000000000000-
000000000000000000000000000-
-00000000000000000000000000-
-00000000000000000000000000-
-00000000000000000000000000-
----------------------------
@ -51,10 +51,10 @@ levels = {[5049] = [[
----------------------------
-00000000000000000000000000-
-00000000000000000000000000-
000......................00-
-00......................00-
-........................00-
-........................00-
000......................00-
-00......................00-
-00......................00-
-00.....0...0.000.000....00-
-00.....0...0..0..0.0....00-

Binary file not shown.

View File

@ -7,6 +7,33 @@
#define DRAW_OFFSET_X -27
extern image_t img_player; //player texture, 12x12
extern image_t img_ground; //ground texture, 16x16
extern image_t img_spike; //spike texture, 16x16
extern image_t img_ice; //ice texture, 16x8
extern image_t img_glue; //glue texture, 16x8
extern image_t img_jitem; //jump item texture, 16x16
//animated textures
extern image_t img_elevator1;
extern image_t img_elevator2;
extern image_t img_elevator3;
extern image_t img_elevator4;
extern image_t img_elevator5;
extern image_t img_elevator6;
extern image_t img_elevator7;
extern image_t img_elevator8;
extern image_t img_elevator9;
extern image_t img_elevator10;
extern image_t img_elevator11;
extern image_t img_elevator12;
extern image_t img_elevator13;
extern image_t img_elevator14;
extern image_t img_elevator15;
extern image_t img_elevator16;
image_t* ani_elevator[16] = {&img_elevator1, &img_elevator2, &img_elevator3,
&img_elevator4, &img_elevator5, &img_elevator6, &img_elevator7,
&img_elevator8, &img_elevator9, &img_elevator10, &img_elevator11,
&img_elevator12, &img_elevator13, &img_elevator14, &img_elevator15,
&img_elevator16};
void draw_player(int old_x, int old_y, int x, int y)
{
@ -22,16 +49,10 @@ void draw_player(int old_x, int old_y, int x, int y)
void draw_level(char level[], char upgrades[])
{
dclear(BG_COLOR);
extern image_t img_ground; //ground texture, 16x16
extern image_t img_spike; //spike texture, 16x16
extern image_t img_elevator; //elevator texture, 16x16
extern image_t img_ice; //ice texture, 16x8
extern image_t img_glue; //glue texture, 16x8
extern image_t img_jitem; //jump item texture, 16x16
unsigned int i = 0;
unsigned int x = 0;
unsigned int y = 0;
while (i != LEVEL_WIDTH*17)
while (i != LEVEL_WIDTH*16)
{
switch (level[i])
{
@ -41,9 +62,6 @@ void draw_level(char level[], char upgrades[])
case 'v':
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_spike);
break;
case '^':
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_elevator);
break;
case '~':
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_ground);
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_ice);
@ -52,9 +70,38 @@ void draw_level(char level[], char upgrades[])
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_ground);
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_glue);
break;
}
x += 16;
if (x == 16*LEVEL_WIDTH)
{
x = 0;
y += 16;
}
i++;
}
}
void draw_level_anims(char level[], char upgrades[], unsigned int step)
{
unsigned int i = 0;
unsigned int x = 0;
unsigned int y = 0;
while (i != LEVEL_WIDTH*16)
{
switch (level[i])
{
case '^':
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, ani_elevator[((int)step/2)%16]);
break;
case 'j':
if (!upgrades[0])
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_jitem);
{
unsigned int buffer = ((int)step/20)%4 - 1;
if (buffer == 2) buffer = 0;
drect(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, x + 15 + DRAW_OFFSET_X,
y + 15 + DRAW_OFFSET_Y, BG_COLOR);
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y + buffer, &img_jitem);
}
else level[i] = '.';
break;
}

View File

@ -33,11 +33,11 @@ int main(void)
volatile int has_ticked = 1; //fps cap
char level[477];
int level_id = 5050;
//start upgrades (mostly bools)
//START UPGRADES
char upgrades[] = {
0 //can jump
};
//end upgrades
//END UPGRADES
char jump_pressed = 1; //avoid holding jump
char jump_buffer = 0; //jump buffer, last 3 frames
unsigned int jump_hold = 0; //number of consecutive frames jump has been held
@ -52,8 +52,10 @@ int main(void)
int start_y = 9*16 + 4;
int old_x, old_y;
char spawn_buffer = 0;
unsigned int step = 1;
set_level(level_id, level);
draw_level(level, upgrades);
draw_level_anims(level, upgrades, step);
player_x = start_x;
player_y = start_y;
old_x = player_x + 1; //offset to draw it on first cycle
@ -64,10 +66,14 @@ int main(void)
while (1) {
while(!has_ticked) sleep();
has_ticked = 0;
//START DRAW
step++;
draw_level_anims(level, upgrades, step);
draw_player(old_x, old_y, player_x, player_y);
dupdate();
old_x = player_x;
old_y = player_y;
old_x = player_x;
//END DRAW
clearevents();
//horizontal movement & collision
{