Clean up setup, draw player and stars (and tick stars), tick handling, buffer handling and line drawing.

This commit is contained in:
stevenhowes
2021-03-19 23:04:23 +00:00
parent dac8e5fd32
commit 4fd5fa0123
4 changed files with 166 additions and 17 deletions
BIN
View File
Binary file not shown.
+21 -12
View File
@@ -25,25 +25,34 @@ Linkflags = -aif -o $@
cc $(ccflags) -o @.o.Input @.c.Input
# 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:h.swis
o.Sound: C:h.kernel
o.Sound: C:h.kernel
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:h.swis
o.CTheEscape: C:h.kernel
o.CTheEscape: C:h.kernel
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
+106 -4
View File
@@ -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;
+39 -1
View File
@@ -7,7 +7,7 @@ extern _kernel_swi_regs inreg;
extern _kernel_swi_regs outreg;
extern unsigned char *buffer;
unsigned char screen = 1;
// Loads sprite file into buffer
void load_sprites(char* filename)
@@ -66,6 +66,17 @@ void display_mode(int mode)
_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)
{
// 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
_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);
}