mirror of
https://github.com/stevenhowes/CTheEscape.git
synced 2026-05-26 15:53:29 +01:00
Clean up setup, draw player and stars (and tick stars), tick handling, buffer handling and line drawing.
This commit is contained in:
Binary file not shown.
+21
-12
@@ -25,25 +25,34 @@ Linkflags = -aif -o $@
|
|||||||
cc $(ccflags) -o @.o.Input @.c.Input
|
cc $(ccflags) -o @.o.Input @.c.Input
|
||||||
|
|
||||||
# Dynamic dependencies:
|
# Dynamic dependencies:
|
||||||
o.Graphics: c.Graphics
|
|
||||||
o.Graphics: C:h.swis
|
|
||||||
o.Graphics: C:h.kernel
|
|
||||||
o.Graphics: C:h.kernel
|
|
||||||
o.Sound: c.Sound
|
o.Sound: c.Sound
|
||||||
o.Sound: C:h.swis
|
o.Sound: C:h.swis
|
||||||
o.Sound: C:h.kernel
|
o.Sound: C:h.kernel
|
||||||
o.Sound: C:h.kernel
|
o.Sound: C:h.kernel
|
||||||
o.Sound: h.Sound
|
o.Sound: h.Sound
|
||||||
|
o.Input: c.Input
|
||||||
|
o.Input: C:h.swis
|
||||||
|
o.Input: C:h.kernel
|
||||||
|
o.Input: C:h.kernel
|
||||||
|
o.Input: c.Input
|
||||||
|
o.Input: C:h.swis
|
||||||
|
o.Input: C:h.kernel
|
||||||
|
o.Input: C:h.kernel
|
||||||
|
o.Graphics: c.Graphics
|
||||||
|
o.Graphics: C:h.swis
|
||||||
|
o.Graphics: C:h.kernel
|
||||||
|
o.Graphics: C:h.kernel
|
||||||
|
o.Graphics: c.Graphics
|
||||||
|
o.Graphics: C:h.swis
|
||||||
|
o.Graphics: C:h.kernel
|
||||||
|
o.Graphics: C:h.kernel
|
||||||
|
o.CTheEscape: c.CTheEscape
|
||||||
|
o.CTheEscape: C:h.swis
|
||||||
|
o.CTheEscape: C:h.kernel
|
||||||
|
o.CTheEscape: C:h.kernel
|
||||||
|
o.CTheEscape: h.Sound
|
||||||
o.CTheEscape: c.CTheEscape
|
o.CTheEscape: c.CTheEscape
|
||||||
o.CTheEscape: C:h.swis
|
o.CTheEscape: C:h.swis
|
||||||
o.CTheEscape: C:h.kernel
|
o.CTheEscape: C:h.kernel
|
||||||
o.CTheEscape: C:h.kernel
|
o.CTheEscape: C:h.kernel
|
||||||
o.CTheEscape: h.Sound
|
o.CTheEscape: h.Sound
|
||||||
o.Input: c.Input
|
|
||||||
o.Input: C:h.swis
|
|
||||||
o.Input: C:h.kernel
|
|
||||||
o.Input: C:h.kernel
|
|
||||||
o.Input: c.Input
|
|
||||||
o.Input: C:h.swis
|
|
||||||
o.Input: C:h.kernel
|
|
||||||
o.Input: C:h.kernel
|
|
||||||
|
|||||||
+105
-3
@@ -14,6 +14,41 @@ unsigned char *buffer;
|
|||||||
extern struct CompositionElement composition[128];
|
extern struct CompositionElement composition[128];
|
||||||
extern int current_element;
|
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()
|
void intro()
|
||||||
{
|
{
|
||||||
int currentstart = 0;
|
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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
sound_on();
|
sound_on();
|
||||||
|
|
||||||
// mode 28 80x60 640x480 16 colours
|
display_mode(DISPLAY_MODE);
|
||||||
display_mode(28);
|
|
||||||
load_sprites("Spr");
|
load_sprites("Spr");
|
||||||
|
|
||||||
intro();
|
//intro();
|
||||||
|
|
||||||
|
display_mode(DISPLAY_MODE);
|
||||||
|
|
||||||
|
game_setup();
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
game_tick();
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+39
-1
@@ -7,7 +7,7 @@ extern _kernel_swi_regs inreg;
|
|||||||
extern _kernel_swi_regs outreg;
|
extern _kernel_swi_regs outreg;
|
||||||
|
|
||||||
extern unsigned char *buffer;
|
extern unsigned char *buffer;
|
||||||
|
unsigned char screen = 1;
|
||||||
|
|
||||||
// Loads sprite file into buffer
|
// Loads sprite file into buffer
|
||||||
void load_sprites(char* filename)
|
void load_sprites(char* filename)
|
||||||
@@ -66,6 +66,17 @@ void display_mode(int mode)
|
|||||||
_kernel_swi(OS_ScreenMode,&inreg,&outreg);
|
_kernel_swi(OS_ScreenMode,&inreg,&outreg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_line(int x1,int y1,int x2,int y2)
|
||||||
|
{
|
||||||
|
inreg.r[0] = 4;
|
||||||
|
inreg.r[1] = x1;
|
||||||
|
inreg.r[2] = y1;
|
||||||
|
_kernel_swi(OS_Plot,&inreg,&outreg);
|
||||||
|
inreg.r[0] = 5;
|
||||||
|
inreg.r[1] = x2;
|
||||||
|
inreg.r[2] = y2;
|
||||||
|
_kernel_swi(OS_Plot,&inreg,&outreg);
|
||||||
|
}
|
||||||
void draw_sprite(char* spritename,int x, int y)
|
void draw_sprite(char* spritename,int x, int y)
|
||||||
{
|
{
|
||||||
// SpriteOp 34 to put sprite at a location
|
// SpriteOp 34 to put sprite at a location
|
||||||
@@ -77,3 +88,30 @@ void draw_sprite(char* spritename,int x, int y)
|
|||||||
inreg.r[5] = 8; // GCOL dest=source and sprite mask
|
inreg.r[5] = 8; // GCOL dest=source and sprite mask
|
||||||
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
_kernel_swi(OS_SpriteOp,&inreg,&outreg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void screen_flipbuffer()
|
||||||
|
{
|
||||||
|
inreg.r[0] = 19;
|
||||||
|
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||||
|
|
||||||
|
/* inreg.r[0] = 114;
|
||||||
|
inreg.r[1] = 1;
|
||||||
|
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||||
|
|
||||||
|
inreg.r[0] = 113;
|
||||||
|
inreg.r[1] = screen;
|
||||||
|
_kernel_swi(OS_Byte,&inreg,&outreg);
|
||||||
|
|
||||||
|
screen++;
|
||||||
|
if(screen > 3)
|
||||||
|
screen = 1;
|
||||||
|
inreg.r[0] = 112;
|
||||||
|
inreg.r[1] = screen;
|
||||||
|
_kernel_swi(OS_Byte,&inreg,&outreg);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void screen_clear()
|
||||||
|
{
|
||||||
|
inreg.r[0] = 12;
|
||||||
|
_kernel_swi(OS_WriteC,&inreg,&outreg);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user