mirror of
https://github.com/stevenhowes/CTheEscape.git
synced 2026-05-27 20:13:31 +01:00
Clean up setup, draw player and stars (and tick stars), tick handling, buffer handling and line drawing.
This commit is contained in:
+106
-4
@@ -14,6 +14,41 @@ unsigned char *buffer;
|
||||
extern struct CompositionElement composition[128];
|
||||
extern int current_element;
|
||||
|
||||
#define DISPLAY_MODE 28
|
||||
#define DISPLAY_X 1280
|
||||
#define DISPLAY_Y 960
|
||||
|
||||
#define PLAYER_Y_START 100
|
||||
|
||||
#define MAX_NPCS 5
|
||||
#define MAX_STARS 49
|
||||
|
||||
enum sprite_e{player_ship, durno_ship,player_shipl,player_shipr};
|
||||
char *sprites[] = {"player_ship","durno_ship","player_shipl","player_shipr"};
|
||||
|
||||
struct EntityLocation_s {
|
||||
short int X,Y;
|
||||
};
|
||||
|
||||
struct NPC_s {
|
||||
struct EntityLocation_s location;
|
||||
enum sprite_e sprite;
|
||||
unsigned char velocity;
|
||||
};
|
||||
|
||||
struct Player_s {
|
||||
struct EntityLocation_s location;
|
||||
enum sprite_e sprite;
|
||||
unsigned char velocity;
|
||||
};
|
||||
|
||||
struct NPC_s NPCS[MAX_NPCS];
|
||||
struct Player_s Player;
|
||||
struct EntityLocation_s Stars[MAX_STARS];
|
||||
|
||||
int tick = 0;
|
||||
int lasttick = 0;
|
||||
extern int screen;
|
||||
void intro()
|
||||
{
|
||||
int currentstart = 0;
|
||||
@@ -89,16 +124,83 @@ void intro()
|
||||
}
|
||||
}
|
||||
|
||||
void game_draw_player()
|
||||
{
|
||||
draw_sprite(sprites[Player.sprite], Player.location.X, Player.location.Y);
|
||||
}
|
||||
void game_draw_stars()
|
||||
{
|
||||
unsigned char i;
|
||||
for(i = 0; i <= MAX_STARS; i++)
|
||||
{
|
||||
draw_line(Stars[i].X,Stars[i].Y,Stars[i].X,Stars[i].Y+30);
|
||||
}
|
||||
}
|
||||
|
||||
void game_setup_player()
|
||||
{
|
||||
Player.location.X = DISPLAY_X/2;
|
||||
Player.location.Y = PLAYER_Y_START;
|
||||
Player.sprite = player_ship;
|
||||
}
|
||||
|
||||
void game_tick_stars()
|
||||
{
|
||||
unsigned char i;
|
||||
for(i = 0; i <= MAX_STARS; i++)
|
||||
{
|
||||
Stars[i].Y -= (tick - lasttick) * 2;
|
||||
if(Stars[i].Y <= 0)
|
||||
{
|
||||
Stars[i].X = rand() % DISPLAY_X;
|
||||
Stars[i].Y = DISPLAY_Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void game_setup_stars()
|
||||
{
|
||||
unsigned char i;
|
||||
for(i = 0; i <= MAX_STARS; i++)
|
||||
{
|
||||
Stars[i].X = rand() % DISPLAY_X;
|
||||
Stars[i].Y = rand() % DISPLAY_Y;
|
||||
}
|
||||
}
|
||||
|
||||
void game_setup()
|
||||
{
|
||||
game_setup_stars();
|
||||
game_setup_player();
|
||||
}
|
||||
|
||||
void game_tick()
|
||||
{
|
||||
lasttick = tick;
|
||||
tick = clock();
|
||||
screen_flipbuffer();
|
||||
screen_clear();
|
||||
game_tick_stars();
|
||||
game_draw_stars();
|
||||
game_draw_player();
|
||||
printf("%i - %i",tick - lasttick,screen);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
sound_on();
|
||||
|
||||
// mode 28 80x60 640x480 16 colours
|
||||
display_mode(28);
|
||||
|
||||
display_mode(DISPLAY_MODE);
|
||||
load_sprites("Spr");
|
||||
|
||||
intro();
|
||||
//intro();
|
||||
|
||||
display_mode(DISPLAY_MODE);
|
||||
|
||||
game_setup();
|
||||
|
||||
while(1)
|
||||
game_tick();
|
||||
free(buffer);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user