Use gint.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

152 lines
3.9 KiB

#include <gint/display.h>
#include "draw.h"
#define PLAYER_SIDES 11
#define BG_COLOR 0
#define LEVEL_WIDTH 28
#define DRAW_OFFSET_Y -24
#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
extern image_t img_coin; //coin item texture, 16x16
//animated textures
extern image_t img_elevator1, img_elevator2, img_elevator3, img_elevator4;
extern image_t img_elevator5, img_elevator6, img_elevator7, img_elevator8;
extern image_t img_elevator9, img_elevator10, img_elevator11, img_elevator12;
extern image_t img_elevator13, img_elevator14, img_elevator15, img_elevator16;
const 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)
{
if (old_x != x || old_y != y)
{
drect(old_x + DRAW_OFFSET_X, old_y + DRAW_OFFSET_Y,
(old_x + PLAYER_SIDES) + DRAW_OFFSET_X,
(old_y + PLAYER_SIDES) + DRAW_OFFSET_Y, BG_COLOR);
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_player);
}
}
void draw_level(char level[], char upgrades[], char erase_coin)
{
dclear(BG_COLOR);
unsigned int i = 0;
unsigned int x = 0;
unsigned int y = 0;
while (i != LEVEL_WIDTH*16)
{
switch (level[i])
{
case '0':
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_ground);
break;
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_ground);
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_ice);
break;
case '#':
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_ground);
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_glue);
break;
case 'j':
if (upgrades[0]) erase_tile(x, y, level);
break;
case 'c':
if (erase_coin) erase_tile(x, y, level);
break;
case 's':
dimage(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y, &img_ground);
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[(step/2)%16]);
break;
case 'j':
{
unsigned int buffer = (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);
}
break;
case 'c':
{
unsigned int buffer = (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_coin);
}
break;
}
x += 16;
if (x == 16*LEVEL_WIDTH)
{
x = 0;
y += 16;
}
i++;
}
}
void erase_tile(int x, int y, char level[])
{
x = (int)(x/16);
y = (int)(y/16);
level[x + y * LEVEL_WIDTH] = '.';
x *= 16;
y *= 16;
drect(x + DRAW_OFFSET_X, y + DRAW_OFFSET_Y,
x + 15 + DRAW_OFFSET_X,
y + 15 + DRAW_OFFSET_Y, BG_COLOR);
}
void draw_upgrade_message(char item)
{
switch (item)
{
case 'j':
{
extern image_t img_jitem_popup;
dimage(112 + DRAW_OFFSET_X, 88 + DRAW_OFFSET_Y, &img_jitem_popup);
break;
}
}
}
void draw_timer(unsigned int step)
{
dprint(0, 0, C_WHITE, C_BLACK, "%u.%02u", step/60, step%60);
}