games: 30 fps render loop + immediate Snake turns

Switched both games to a 30 fps render cap (FRAME_MS = 33 ms) for smoother,
more predictable frame pacing. Snake base speed raised to 150 px/sec (~60 ms
per step at cell=9) so turn commands take effect at the next step without
perceived lag. The buffered-direction model (latest keypress wins) is
unchanged — turns apply at the next step, which is immediate in snake terms.

Progressive difficulty (+1 px/sec per 5 food in Snake, +1 px/sec per 10 lines
in Tetris), edge wrap, Gameboy-style beveled blocks, and all controls are
unchanged.
This commit is contained in:
Luxferre
2026-10-24 08:54:25 +03:00
parent 9d4ca2e3a6
commit 8ccfdb8d44
6 changed files with 5 additions and 5 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -4
View File
@@ -107,7 +107,7 @@ static int foodx, foody;
static int score = 0;
static int best = 0;
static int speed = 90; // ms per step (derived from pps below)
static int pps = 100; // base speed px/sec; +1 px/sec per 5 food eaten
static int pps = 150; // base speed px/sec; +1 px/sec per 5 food eaten
static unsigned long nextTick = 0;
static bool running = true;
static unsigned long now_ms() {
@@ -165,7 +165,7 @@ static void reset_game() {
dirx = 1; diry = 0;
ndirx = 1; ndiry = 0;
score = 0;
pps = 100;
pps = 150;
update_speed();
place_food();
state = PLAYING;
@@ -202,7 +202,7 @@ static void step() {
score += 10;
if (score > best) best = score;
int food = score / 10; // food items eaten so far
pps = 100 + food / 5; // +1 px/sec per 5 food eaten (progressive difficulty)
pps = 150 + food / 5; // +1 px/sec per 5 food eaten (progressive difficulty)
update_speed();
place_food();
}
@@ -375,7 +375,7 @@ int main() {
render();
int xfd = ConnectionNumber(dpy);
const unsigned long FRAME_MS = 1000 / 60; // 60 fps rendering
const unsigned long FRAME_MS = 1000 / 30; // 30 fps rendering
unsigned long lastFrame = now_ms();
while (running) {
+1 -1
View File
@@ -499,7 +499,7 @@ int main() {
render();
int xfd = ConnectionNumber(dpy);
const unsigned long FRAME_MS = 1000 / 60; // 60 fps rendering
const unsigned long FRAME_MS = 1000 / 30; // 30 fps rendering
unsigned long lastFrame = now_ms();
while (running) {