From 0c9e624f86b589e71cfdf33ed453a9571f80ed45 Mon Sep 17 00:00:00 2001 From: kitty piapiac Date: Sun, 23 Apr 2023 22:38:00 -0700 Subject: add ghost blocks for soon-to-be placed --- core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core.c b/core.c index 40f7621..db1f131 100644 --- a/core.c +++ b/core.c @@ -54,16 +54,16 @@ _ V tetro_bake(Tetro t){U8 i;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)grid[(U32)(a[1]+t.v[i][1])][(U32)(a[0]+t.v[i][0])]=t.i;} -_ V tetro_draw_col(Tetro t,vec4 c){U8 i;vec2 a;vec2 z={CELL_W,CELL_H}; +_ V tetro_draw_col(Tetro t,vec4 c,U32 tex){U8 i;vec2 a;vec2 z={CELL_W,CELL_H}; graph_shader_use(shader_tetro), - graph_tex_use(tex_cell_mino,0), + graph_tex_use(tex,0), graph_shader_setM4("proj",proj), graph_shader_setV4("col",c); for(i=0;i<4;++i){ glm_vec2_mul(t.v[i],z,a), glm_vec2_add(t.pos,a,a), graph_quad(a,z);}} -_ V tetro_draw(Tetro t){tetro_draw_col(t,tetros_col[t.i]);} +_ V tetro_draw(Tetro t){tetro_draw_col(t,tetros_col[t.i],tex_cell_mino);} _ 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); @@ -74,6 +74,7 @@ _ U8 tetro_in_wall(Tetro t){U8 i;U32 w,x;vec2 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||w>=GRID_H||w<0,R 1)Q(-1!=grid[w][x],R 1)} R 0;} + _ V tetro_trans(Tetro*t,vec2 m){ glm_vec2_add(t->pos,m,t->pos);} _ V tetro_move(Tetro*t,F64 x){ @@ -91,6 +92,8 @@ _ V tetro_rot(Tetro*t,S8 c){Tetro u=*t; tetro_trans(&u,(vec2){CELL_W,0}); Q(!tetro_in_wall(u),*t=u;R) tetro_trans(&u,(vec2){-2*CELL_W,0}); Q(!tetro_in_wall(u),*t=u;R)} +_ V tetro_soon(Tetro*t){WH(!tetro_in_floor(*t),t->pos[1]-=CELL_H)t->pos[1]+=CELL_H;} + _ Tetro bag[14]; _ U8 bag_i=14; _ V tetro_next(Tetro*t){U8 i,j;Tetro u; @@ -114,7 +117,7 @@ _ V grid_draw(V){U8 i,j;S8 c;vec2 z={CELL_W,CELL_H},pos={GRID_X,GRID_Y}; graph_shader_setV4("col",tetros_col[c]); graph_quad(pos,z);}} -_ Tetro held; +_ Tetro held,soon; V core_init(V){ glm_ortho(0,graph_win_w,0,graph_win_h,0,4,proj), srand(time(0)), @@ -126,6 +129,8 @@ V core_init(V){ tetro_next(&held);} V core_tick(InputPoint p,InputButtons b,F64 dt){_ F64 et=0; glm_ortho(0,graph_win_w,0,graph_win_h,0,4,proj); + soon=held,tetro_soon(&soon); + tetro_draw_col(soon,tetros_col[soon.i],tex_cell_soon); grid_draw(); tetro_draw(held); Q((et+=dt)>=DELAY_FALL,tetro_fall(&held,et),et=0) -- cgit v1.2.3