v.0.1-4
This commit is contained in:
parent
249b433d43
commit
c094aa2605
|
@ -31,6 +31,8 @@ set(ASSETS_fx
|
|||
assets-fx/timer/3.png
|
||||
assets-fx/timer/2.png
|
||||
assets-fx/timer/1.png
|
||||
assets-fx/score_bar.png
|
||||
assets-fx/milifont.png
|
||||
# ...
|
||||
)
|
||||
|
||||
|
|
|
@ -7,3 +7,15 @@ game_over.png:
|
|||
you_won.png:
|
||||
type: bopti-image
|
||||
name: you_won
|
||||
score_bar.png:
|
||||
type: bopti-image
|
||||
name: score_bar
|
||||
|
||||
milifont.png:
|
||||
name: milifont
|
||||
type: font
|
||||
charset: print
|
||||
width: 3
|
||||
grid.size: 3x5
|
||||
grid.padding: 1
|
||||
proportional: true
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 537 B |
Binary file not shown.
After Width: | Height: | Size: 125 B |
75
src/core.c
75
src/core.c
|
@ -20,30 +20,33 @@
|
|||
#include "includes.h"
|
||||
|
||||
Ship ship;
|
||||
static Vector smoke_cubes[5];
|
||||
|
||||
extern bopti_image_t map_1;
|
||||
extern bopti_image_t timer_3;
|
||||
extern bopti_image_t timer_2;
|
||||
extern bopti_image_t timer_1;
|
||||
extern bopti_image_t score_bar;
|
||||
|
||||
int dgetpixel(int x, int y) // Thanks to Lephenixnoir
|
||||
{
|
||||
int offset = (y << 2) + (x >> 5);
|
||||
return (int)(gint_vram[offset] << (x & 31)) < 0 ? C_BLACK : C_WHITE;
|
||||
}
|
||||
int score_delay;
|
||||
|
||||
int play_game(void)
|
||||
{
|
||||
int collision = 0, ticks = 0, timer = 3;
|
||||
int collision = 0, timer = 3, ticks = 0;
|
||||
ship.score = 0;
|
||||
init_ship();
|
||||
ship.scrolling.x = 0;
|
||||
ship.scrolling.y = 0;
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
smoke_cubes[i].x = 0;
|
||||
smoke_cubes[i].y = 0;
|
||||
}
|
||||
while(timer != 0){
|
||||
dclear(C_WHITE);
|
||||
int i;
|
||||
dimage(-ship.scrolling.x, 0, &map_1);
|
||||
calculate_tops();
|
||||
for(i = 0; i != 3; i++)
|
||||
dline(ship.tops[i].x, ship.tops[i].y, ship.tops[(i + 1) % 3].x, ship.tops[(i + 1) % 3].y, C_BLACK);
|
||||
dimage(-ship.scrolling.x, 0, &map_1);
|
||||
draw();
|
||||
if(timer == 3){
|
||||
dimage(59, 25, &timer_3);
|
||||
}else if(timer == 2){
|
||||
|
@ -56,6 +59,9 @@ int play_game(void)
|
|||
timer--;
|
||||
}
|
||||
|
||||
score_delay = 0;
|
||||
ship.score = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
clearevents();
|
||||
|
@ -69,28 +75,54 @@ int play_game(void)
|
|||
calculate_tops();
|
||||
dclear(C_WHITE);
|
||||
collision = move();
|
||||
draw();
|
||||
ship.thrust = true;
|
||||
clearevents();
|
||||
if(ship.scrolling.x >= 3328){
|
||||
return 1;
|
||||
}
|
||||
if(collision == 1){
|
||||
return 0;
|
||||
}
|
||||
draw();
|
||||
dupdate();
|
||||
ship.thrust = true;
|
||||
clearevents();
|
||||
ticks++;
|
||||
score_delay++;
|
||||
if(ticks>=SMOKE_CUBES_SPACING)
|
||||
{
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
smoke_cubes[i].x = smoke_cubes[i+1].x;
|
||||
smoke_cubes[i].y = smoke_cubes[i+1].y;
|
||||
}
|
||||
smoke_cubes[4].x = ship.scrolling.x + MARGIN;
|
||||
smoke_cubes[4].y = ship.position.y;
|
||||
ticks = 0;
|
||||
}
|
||||
|
||||
if(score_delay>=SCORE_DELAY)
|
||||
{
|
||||
ship.score++;
|
||||
score_delay=0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void draw(void)
|
||||
{
|
||||
static Vector smoke_cubes[5];
|
||||
int i;
|
||||
|
||||
for(i = 0; i != 3; i++)
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
dline(ship.tops[i].x, ship.tops[i].y, ship.tops[(i + 1) % 3].x, ship.tops[(i + 1) % 3].y, C_BLACK);
|
||||
}
|
||||
|
||||
dupdate();
|
||||
for(i = 0; i < 5; i++)
|
||||
{
|
||||
drect_border(smoke_cubes[i].x-1 - ship.scrolling.x, smoke_cubes[i].y-1, smoke_cubes[i].x+1 - ship.scrolling.x, smoke_cubes[i].y+1, C_WHITE, 1, C_BLACK);
|
||||
}
|
||||
dimage(0, 0, &score_bar);
|
||||
dprint_opt(1, 1, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "Score : %d", ship.score);
|
||||
}
|
||||
|
||||
int move(void)
|
||||
|
@ -104,13 +136,14 @@ int move(void)
|
|||
|
||||
ship.position.x += ship.speed.x;
|
||||
ship.position.y += ship.speed.y;
|
||||
|
||||
|
||||
ship.scrolling.x = ship.position.x;
|
||||
|
||||
|
||||
dimage(-ship.scrolling.x, 0, &map_1);
|
||||
|
||||
|
||||
// collision
|
||||
for(i=0;i!=3;i++){
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
if(dgetpixel(ship.tops[i].x, ship.tops[i].y) == C_BLACK){
|
||||
return 1;
|
||||
}
|
||||
|
@ -132,7 +165,7 @@ void calculate_tops(void)
|
|||
|
||||
init_tops();
|
||||
|
||||
for(i = 0; i != 3; i++)
|
||||
for(i = 0; i < 3; i++)
|
||||
{
|
||||
tmp.x = ship.tops[i].x;
|
||||
tmp.y = ship.tops[i].y;
|
||||
|
|
|
@ -37,6 +37,13 @@
|
|||
// Margin before the ship
|
||||
#define MARGIN 32
|
||||
|
||||
// Time between the smoke cubes
|
||||
#define SMOKE_CUBES_SPACING 8
|
||||
|
||||
|
||||
// Increment score_delay after SCORE_DELAY frames.
|
||||
#define SCORE_DELAY 16
|
||||
|
||||
// Relative position of tops of the ship
|
||||
/*#define SHIP_TOP_1_X 10
|
||||
#define SHIP_TOP_1_Y 0
|
||||
|
@ -72,6 +79,8 @@ typedef struct
|
|||
bool thrust;
|
||||
|
||||
Vector tops[3];
|
||||
|
||||
int score;
|
||||
} Ship;
|
||||
|
||||
typedef struct
|
||||
|
|
|
@ -29,6 +29,10 @@ extern bopti_image_t menu_play_inv;
|
|||
extern bopti_image_t menu_quit;
|
||||
extern bopti_image_t menu_quit_inv;
|
||||
|
||||
extern font_t milifont;
|
||||
|
||||
extern Ship ship;
|
||||
|
||||
void waitkey(int key){
|
||||
clearevents();
|
||||
while(keydown(key)){
|
||||
|
@ -43,6 +47,7 @@ void end(){
|
|||
}else if(stat == 1){
|
||||
dimage(0, 0, &you_won);
|
||||
}
|
||||
dprint_opt(57, 30, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "Score : %d", ship.score);
|
||||
if(stat == 0 || stat == 1){
|
||||
dupdate();
|
||||
stat = 0;
|
||||
|
@ -63,6 +68,7 @@ void end(){
|
|||
|
||||
int main(void)
|
||||
{
|
||||
dfont(&milifont);
|
||||
selection = PLAY;
|
||||
stat = 0;
|
||||
while(1){
|
||||
|
|
Loading…
Reference in New Issue