unnamed-platformer/src/draw.c

45 lines
853 B
C

#include <gint/display.h>
#define PLAYER_SIDES 11
#define BG_COLOR 0
extern image_t img_player; //player texture, 24x24
void draw_player(int old_x, int old_y, int x, int y)
{
if (old_x != x || old_y != y)
{
drect(old_x * 2, old_y * 2, (old_x + PLAYER_SIDES) * 2 + 1,
(old_y + PLAYER_SIDES) * 2 + 1, BG_COLOR);
dimage(x * 2, y * 2, &img_player);
}
}
void draw_level(char level[], int *player_x, int *player_y)
{
extern image_t img_ground; //ground texture, 16x16
unsigned int i = 0;
unsigned int x = 0;
unsigned int y = 0;
while (i != 100)
{
switch (level[i])
{
case '0':
dimage(x * 2, y * 2, &img_ground);
break;
case 's':
*player_x = x + 2;
*player_y = y + 4;
break;
}
x += 8;
if (x == 80)
{
x = 0;
y += 8;
}
i++;
}
}