You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.5 KiB
C
81 lines
1.5 KiB
C
4 years ago
|
#include "buttons.h"
|
||
|
#include "dogs.h"
|
||
|
|
||
|
static const unsigned char bird[] = {
|
||
|
8, 8,
|
||
|
0b00111100,
|
||
|
0b01100110,
|
||
|
0b01000010,
|
||
|
0b01111110,
|
||
|
0b01100110,
|
||
|
0b01000010,
|
||
|
0b11000000,
|
||
|
0b11000000,
|
||
|
};
|
||
|
|
||
|
static int score;
|
||
|
static int t1x, t1o;
|
||
|
static int t2x, t2o;
|
||
|
static int py;
|
||
|
static int vy;
|
||
|
static int counter;
|
||
|
|
||
|
void flapbird_init()
|
||
|
{
|
||
|
score = 0;
|
||
|
t1x = DISP_WIDTH / 2, t1o = 15;
|
||
|
t2x = DISP_WIDTH, t2o = 49;
|
||
|
py = DISP_HEIGHT / 2 - 4;
|
||
|
vy = 0;
|
||
|
counter = 0;
|
||
|
}
|
||
|
|
||
|
int flapbird_loop()
|
||
|
{
|
||
|
// Player logic
|
||
|
if (py > 0) {
|
||
|
py += vy;
|
||
|
if (vy > -3)
|
||
|
vy--;
|
||
|
} else {
|
||
|
if (py < 0)
|
||
|
py = 0;
|
||
|
if (score > 0)
|
||
|
score = 0;
|
||
|
}
|
||
|
|
||
|
if (button_state & BUTTON_2) {
|
||
|
vy = 5;
|
||
|
if (py <= 0)
|
||
|
py = 1;
|
||
|
}
|
||
|
|
||
|
// Rendering
|
||
|
dogs_clear();
|
||
|
|
||
|
draw_rect(t1x, 0, 4, t1o - 10);
|
||
|
draw_rect(t1x, t1o + 10, 4, DISP_HEIGHT - t1o + 10);
|
||
|
draw_rect(t2x, 0, 4, t2o - 10);
|
||
|
draw_rect(t2x, t2o + 10, 4, DISP_HEIGHT - t2o + 10);
|
||
|
draw_bitmap(4, py, bird);
|
||
|
|
||
|
draw_number(DISP_WIDTH - 25, DISP_HEIGHT - 8, score);
|
||
|
dogs_flush();
|
||
|
|
||
|
// Game logic
|
||
|
if (t1x == 4)
|
||
|
score = (py + 2 > t1o - 10 && py + 6 < t1o + 10) ? score + 1 : 0;
|
||
|
if (t2x == 4)
|
||
|
score = (py + 2 > t2o - 10 && py + 6 < t2o + 10) ? score + 1 : 0;
|
||
|
|
||
|
t1x -= 2;
|
||
|
if (t1x <= -5)
|
||
|
t1x = DISP_WIDTH;
|
||
|
t2x -= 2;
|
||
|
if (t2x <= -5)
|
||
|
t2x = DISP_WIDTH;
|
||
|
|
||
|
return 100;
|
||
|
}
|
||
|
|