Commit a228c66a authored by Max Kobelt's avatar Max Kobelt
Browse files

Create global frames count

parent 5b9c185d
......@@ -7,10 +7,9 @@
#define ALIEN_OFFSET 5
extern const int GAME_SCREEN_WIDTH, LASER_CANON_SPEED, FRAME_RATE;
extern int FRAMES_COUNT;
extern Texture2D ALIEN_UP, ALIEN_DOWN, ALIEN_SHOOT;
size_t framesCount = 0;
Aliens *spawnAliens() {
Aliens *aliens = malloc(sizeof *aliens);
aliens->pos = (Vector2) { 0, 0 };
......@@ -34,7 +33,7 @@ void drawAliens(Aliens *aliens) {
for (int j = 0; j < ALIEN_COLS; ++j) {
for (int i = 0; i < ALIEN_ROWS; ++i) {
if (aliens->instances[j][i]) {
bool up = (i + j) % 2 == (framesCount++ / (FRAME_RATE * 7)) % 2;
bool up = (i + j) % 2 == (FRAMES_COUNT / FRAME_RATE) % 2;
DrawTexture(up ? ALIEN_UP : ALIEN_DOWN, aliens->pos.x + j * (ALIEN_SIZE + ALIEN_OFFSET), aliens->pos.y + i * (ALIEN_SIZE + ALIEN_OFFSET), WHITE);
}
}
......
......@@ -8,6 +8,7 @@
#define min(a, b) ((a)<(b)? (a) : (b))
const int GAME_SCREEN_WIDTH = 400, GAME_SCREEN_HEIGHT = 400, FRAME_RATE = 60;
int FRAMES_COUNT = 0;
int main() {
SetConfigFlags(FLAG_VSYNC_HINT);
......@@ -63,6 +64,8 @@ int main() {
(Rectangle) { (GetScreenWidth() - ((float) GAME_SCREEN_WIDTH * scale)) * 0.5, (GetScreenHeight() - ((float) GAME_SCREEN_HEIGHT * scale)) * 0.5,
(float) GAME_SCREEN_WIDTH * scale, (float) GAME_SCREEN_HEIGHT * scale }, (Vector2){ 0, 0 }, 0.0f, WHITE);
EndDrawing();
++FRAMES_COUNT;
}
destructGame();
......
......@@ -8,15 +8,14 @@
#define TEXT_SIDE_MARGIN (NAME_FONT_SIZE / 3)
extern const int GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT, FRAME_RATE;
extern int FRAMES_COUNT;
char name[MAX_INPUT_CHARS + 1] = "\0";
size_t letterCount, framesCount;
int letterCount = 0;
Rectangle inputBox;
Vector2 playBtnPos;
void initMenu() {
letterCount = framesCount = 0;
int inputBoxWidth = GAME_SCREEN_WIDTH / 2;
inputBox = (Rectangle) { ((float) GAME_SCREEN_WIDTH - inputBoxWidth) / 2, (float) GAME_SCREEN_HEIGHT / 2, (float) inputBoxWidth, (float) GAME_SCREEN_HEIGHT / 7 };
playBtnPos = (Vector2) { (GAME_SCREEN_WIDTH - (float) MeasureText("PLAY", PLAY_FONT_SIZE)) / 2, (float) GAME_SCREEN_HEIGHT / 5 };
......@@ -47,7 +46,7 @@ void drawMenu() {
NAME_FONT_SIZE,
RED
);
if ((++framesCount / (FRAME_RATE / 2)) % 2 && letterCount <= MAX_INPUT_CHARS - 1) {
if ((FRAMES_COUNT / (FRAME_RATE / 2)) % 2 && letterCount <= MAX_INPUT_CHARS - 1) {
DrawText("_",
inputBox.x + (letterCount ? 1.5 : 1) * TEXT_SIDE_MARGIN + MeasureText(name, NAME_FONT_SIZE),
inputBox.y + inputBox.height - NAME_FONT_SIZE,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment