diff options
Diffstat (limited to 'core.c')
-rw-r--r-- | core.c | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -50,14 +50,6 @@ _ V shader_tetro_init(V){ graph_shader_setV4("col",(vec4){1,1,1,1}), graph_shader_setI("buf",0);} -_ V tetro_trans(Tetro*t,vec2 m){ - glm_vec2_add(t->pos,m,t->pos);} -_ V tetro_rot(Tetro*t,S8 c){U8 i;vec2 a; - for(i=0;i<4;++i){ - glm_vec2_sub(t->org,t->v[i],a), - glm_vec2_rotate(a,GLM_PI_2*(2-c),a), - glm_vec2_add(a,t->org,a), - glm_vec2_copy(a,t->v[i]);}} _ 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); @@ -80,8 +72,24 @@ _ U8 tetro_in_floor(Tetro t){U8 i;U32 w,x;vec2 a; _ 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)} + 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){ + tetro_trans(t,(vec2){x,0}); + Q(tetro_in_wall(*t),tetro_trans(t,(vec2){-x,0}))} + +_ V tetro_rot_raw(Tetro*t,S8 c){U8 i;vec2 a; + for(i=0;i<4;++i){ + glm_vec2_sub(t->org,t->v[i],a), + glm_vec2_rotate(a,GLM_PI_2*(2-c),a), + glm_vec2_add(a,t->org,a), + glm_vec2_copy(a,t->v[i]);}} +_ V tetro_rot(Tetro*t,S8 c){Tetro u=*t; + tetro_rot_raw(&u,c); Q(!tetro_in_wall(u),*t=u;R) + 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)} _ Tetro bag[14]; _ U8 bag_i=14; @@ -93,10 +101,6 @@ _ 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), graph_shader_setM4("proj",proj); |