summaryrefslogtreecommitdiff
path: root/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'core.c')
-rw-r--r--core.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/core.c b/core.c
index 4e2b89e..ab99c35 100644
--- a/core.c
+++ b/core.c
@@ -72,6 +72,16 @@ _ V tetro_draw_col(Tetro t,vec4 c){U8 i;vec2 a;vec2 z={CELL_W,CELL_H};
glm_vec2_add(t.pos,a,a),
graph_quad(a,z);}}
_ V tetro_draw(Tetro t){tetro_draw_col(t,tetros_col[t.i]);}
+_ U8 tetro_in_floor(Tetro t){U8 i;U32 w,x;vec2 a;
+ glm_vec2_sub(t.pos,(vec2){GRID_X,GRID_Y},a),
+ glm_vec2_div(a,(vec2){CELL_W,CELL_H},a);
+ for(i=0;i<4;++i){w=a[1]+t.v[i][1],x=a[0]+t.v[i][0];Q(w>=GRID_H||w<0,R 1)Q(-1!=grid[w][x],R 1)}
+ R 0;}
+_ U8 tetro_in_wall(Tetro t){U8 i;U32 w,x;vec2 a;
+ glm_vec2_sub(t.pos,(vec2){GRID_X,GRID_Y},a),
+ glm_vec2_div(a,(vec2){CELL_W,CELL_H},a);
+ for(i=0;i<4;++i){w=a[1]+t.v[i][1],x=a[0]+t.v[i][0];Q(x>=GRID_W||x<0,R 1)Q(-1!=grid[w][x],R 1)}
+ R 0;}
_ Tetro bag[14];
_ U8 bag_i=14;
@@ -79,15 +89,13 @@ _ V tetro_next(Tetro*t){U8 i,j;Tetro u;
Q(bag_i>=13,bag_i=0,memcpy(bag,tetros,SZ tetros),memcpy(bag+7,tetros,SZ tetros);
for(i=0;i<13;++i)j=i+rand()/(RAND_MAX/(14-i)+1),u=bag[j],bag[j]=bag[i],bag[i]=u;)
OR ++bag_i;*t=bag[bag_i],t->pos[0]=GRID_X+CELL_W*4,t->pos[1]=GRID_Y+CELL_H*(GRID_H-1);}
-_ U8 tetro_in_floor(Tetro t){U8 i;U32 w,x;vec2 a;
- glm_vec2_sub(t.pos,(vec2){GRID_X,GRID_Y},a),
- glm_vec2_div(a,(vec2){CELL_W,CELL_H},a);
- for(i=0;i<4;++i){w=a[1]+t.v[i][1],x=a[0]+t.v[i][0];Q(w>=GRID_H||w<0,R 1)Q(-1!=grid[w][x],R 1)}
- R 0;}
_ V tetro_fall(Tetro*t,F64 dt){_ F64 et=0;U8 q;
t->pos[1]-=CELL_H,q=tetro_in_floor(*t),t->pos[1]+=CELL_H;
Q(q,Q(et>=DELAY_BAKE,tetro_bake(*t),tetro_next(t),et=0)OR et+=dt)
OR tetro_trans(t,(vec2){0,-32});}
+_ V tetro_move(Tetro*t,F64 x){
+ tetro_trans(t,(vec2){x,0});
+ Q(tetro_in_wall(*t),tetro_trans(t,(vec2){-x,0}))}
_ V grid_draw(V){U8 i,j;S8 c;vec2 z={CELL_W,CELL_H},pos={GRID_X,GRID_Y};
graph_shader_use(shader_tetro),
@@ -120,8 +128,6 @@ V core_tick(InputPoint p,InputButtons b,F64 dt){_ F64 et=0;
Q(IB_Z&b.p,tetro_rot(&held, 1))
Q(IB_X&b.p,tetro_rot(&held,-1))
Q(IB_C&b.p,tetro_next(&held))
- Q(IB_L&b.p,tetro_trans(&held,(vec2){-32, 0}))
- Q(IB_R&b.p,tetro_trans(&held,(vec2){ 32, 0}))
- Q(IB_U&b.p,tetro_trans(&held,(vec2){ 0, 32}))
- Q(IB_D&b.p,tetro_trans(&held,(vec2){ 0,-32}))
+ Q(IB_L&b.p,tetro_move(&held,-32))
+ Q(IB_R&b.p,tetro_move(&held, 32))
Q(IB_1&b.p,tetro_bake(held))}