ref: 54083e59aaa1cc66f8d12cbb2ffa40c4c1e489fb
parent: d472babe18c4d6f7bd9f04cff0ba93f0d0c078d5
author: qwx <qwx@sciops.net>
date: Sun Mar 16 11:34:52 EDT 2025
add hover time before freezing
--- a/dat.h
+++ b/dat.h
@@ -19,6 +19,7 @@
};
enum{
Fswapped = 1<<0,
+ Fhovering = 1<<1,
};
struct Current{
int x;
@@ -26,7 +27,7 @@
int type;
int rot;
int flags;
- double thover;
+ u64int lastmove;
};
extern Current *cur;
extern int fours[NF][Nrot];
--- a/game.c
+++ b/game.c
@@ -14,6 +14,7 @@
enum{
Nlineperlvl = 10,
Timeinc = BILLION / 10.0,
+ Thover = 400 * MILLION,
};
static vlong ncleared;
static int bfield[Nrow];
@@ -78,9 +79,6 @@
gameover();
}
-/* FIXME: gm4s: freeze: overlapping piece type 2 0,21 at 0,21:
- * and I piece horizontal clipped past the wall to the right prior */
-
int
collide(int x, int y, int rot)
{
@@ -206,13 +204,24 @@
void
step(void)
{
+ u64int t;
+
if(cur == nil){
spawn();
return;
}else if(collide(cur->x, cur->y+1, cur->rot)){
- freeze();
+ t = nanosec();
+ if(cur->lastmove == 0){
+ cur->lastmove = t;
+ cur->flags |= Fhovering;
+ }else if((t - cur->lastmove) >= Thover
+ || collide(cur->x-1, cur->y, cur->rot)
+ && collide(cur->x+1, cur->y, cur->rot))
+ freeze();
return;
}
+ cur->flags &= ~Fhovering;
+ cur->lastmove = 0;
cur->y++;
}
--- a/gm4s.c
+++ b/gm4s.c
@@ -24,6 +24,7 @@
static void
kevent(ulong k)
{
+ int moved;
char r;
static char rr[] = {Left, Up, Right, Down, Left, Up};
@@ -31,17 +32,29 @@
return;
if(k & Khold)
hold();
- if(k & K↓ && !collide(cur->x, cur->y + 1, cur->rot))
+ moved = 0;
+ r = cur->rot;
+ if(k & K↓ && !collide(cur->x, cur->y + 1, r)){
cur->y++;
+ moved = 1;
+ }
if(k & Krotl && !collide(cur->x, cur->y, (r = rr[1+cur->rot-1]))
- || k & Krotr && !collide(cur->x, cur->y, (r = rr[1+cur->rot+1])))
+ || k & Krotr && !collide(cur->x, cur->y, (r = rr[1+cur->rot+1]))){
cur->rot = r;
- if(k & K← && !collide(cur->x - 1, cur->y, cur->rot))
+ moved = 1;
+ }
+ if(k & K← && !collide(cur->x - 1, cur->y, r)){
cur->x--;
- if(k & K→ && !collide(cur->x + 1, cur->y, cur->rot))
+ moved = 1;
+ }
+ if(k & K→ && !collide(cur->x + 1, cur->y, r)){
cur->x++;
+ moved = 1;
+ }
if(k & K↑)
drop();
+ else if(cur->flags & Fhovering && moved)
+ cur->lastmove = nanosec();
}
static void