README.md updates and speed option for testing

This commit is contained in:
Cole
2024-01-11 21:36:56 -06:00
parent e818e59037
commit 28642a7342
7 changed files with 42 additions and 22 deletions

View File

@@ -6,6 +6,20 @@ Creating a Tetris clone in C to practice C programming and learn more about Rayl
This game is a clone of the popular game Tetris. This clone features what you would expect from a simplistic version of Tetris, namely: falling blocks, which upon completion of a row disappear, score keeping and levels with incremental difficulty.
Here are some early screenshots of my progress:
![gameplay](screenshots/game_screenshot.png "Gameplay")
![gameover](screenshots/game_over_screenshot.png "Game Over")
Features left to-do:
- Update codebase to use cohesive style (still haven't landed on exactly what I like)
- Re-Implement rotation algorithm; my original algorithm was extremely buggy
- Empty rows that are full should "break"
- Broken rows should cause other rows to shift down without losing ordering
- scoring system
- display upcoming block
- introduce levels and increasing speed/score multiplier
I hope you enjoy!
## Getting Started

7
TODO
View File

@@ -1,7 +0,0 @@
- Re-organize manager.c to match manager.h, add internals to .h and fix code style to match rest of code
- Rotate (Partially Implemented/Buggy. Should try to understand Rotation Matrix better.)
- Empty rows that are full should "break"
- Shift rows down after row "breaks"
- Track and Display Score. During and After game
- display Upcoming block
- Introduce levels/speed up with every level

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@@ -8,17 +8,20 @@
#define TARGET_FPS 60
void a_run(void) {
_a_initialize();
int _a_tick_rate = 0;
void a_run(int tick_rate) {
_a_initialize(tick_rate);
_a_loop();
_a_cleanup();
}
void _a_initialize(void) {
void _a_initialize(int tick_rate) {
_a_initialize_raylib();
m_initialize();
r_initialize();
_a_gameboard_clear();
_a_tick_rate = tick_rate;
}
void _a_initialize_raylib(void) {
@@ -35,25 +38,24 @@ void _a_gameboard_clear(void) {
}
void _a_loop(void) {
int tick_rate = 0; // Guaranteed a better way to do this XD
int tick_rate_counter = 0;
while (!WindowShouldClose()) {
while (m_tetromino_can_spawn()) {
if (WindowShouldClose())
return;
if (m_tetromino_can_spawn()) {
_a_input_process();
if (tick_rate == 0) {
if (tick_rate_counter == 0) {
m_update();
tick_rate = 50;
tick_rate_counter = _a_tick_rate;
}
int number_blocks_updated = 0;
struct TetrominoBlock **blocks_updated =
m_blocks_get_updated(&number_blocks_updated);
r_render_blocks(blocks_updated, number_blocks_updated);
tick_rate--;
}
tick_rate_counter--;
} else {
r_render_game_over(0);
}
}
}
void _a_input_process(void) {
if (IsKeyPressed(KEY_SPACE)) {

View File

@@ -1,9 +1,9 @@
#ifndef TETRIS_CLONE_APP_H_
#define TETRIS_CLONE_APP_H_
void a_run(void);
void a_run(int tick_rate);
void _a_initialize(void);
void _a_initialize(int tick_rate);
void _a_initialize_raylib(void);
void _a_gameboard_clear(void);
void _a_loop(void);

View File

@@ -1,7 +1,18 @@
#include "app.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
a_run();
int main(int argc, char **argv) {
// Not great code if I were to need multiple options, but I just need to be
// able to debug
if (argc > 1) {
if (strcmp(argv[1], "--speed") == 0) {
a_run(atoi(argv[2]));
}
} else {
a_run(50);
}
return 0;
}