From f54412679c74279d8bcf21bf8ef8bcd8229dc547 Mon Sep 17 00:00:00 2001 From: kitty piapiac Date: Sun, 23 Apr 2023 18:30:46 -0700 Subject: grab bag --- core.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'core.c') diff --git a/core.c b/core.c index 9ddd354..0a3f73d 100644 --- a/core.c +++ b/core.c @@ -1,4 +1,6 @@ +#include #include +#include #include #include"mino.h" #include"graph.h" @@ -70,6 +72,10 @@ _ 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]);} +_ V tetro_next(Tetro*t){_ Tetro bag[14];_ U8 i=14;U8 j,k;Tetro u; + Q(i>13,i=0,memcpy(bag,tetros,SZ tetros),memcpy(bag+7,tetros,SZ tetros); + for(j=0;j<13;++j)k=j+rand()/(RAND_MAX/(14-j)+1),u=bag[k],bag[k]=bag[j],bag[j]=u;) + OR ++i;t->i=bag[i].i,memcpy(t->org,bag[i].org,SZ(vec2)),memcpy(t->v,bag[i].v,4*SZ(vec2));} _ 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), @@ -83,15 +89,17 @@ _ V grid_draw(V){U8 i,j;S8 c;vec2 z={CELL_W,CELL_H},pos={GRID_X,GRID_Y}; graph_tex_use(tex_cell_mino,0), graph_shader_setV4("col",tetros_col[c]); graph_quad(pos,z);}} + _ Tetro held; V core_init(V){ glm_ortho(0,graph_win_w,0,graph_win_h,0,4,proj), + srand(time(0)), shader_tetro_init(), tex_cell_grid=graph_tex_create("res/tex/cell_grid.png"), tex_cell_mino=graph_tex_create("res/tex/cell_mino.png"), tex_cell_soon=graph_tex_create("res/tex/cell_soon.png"), memset(grid,-1,GRID_W*GRID_H); - held=tetros[3];} + tetro_next(&held);} V core_tick(InputPoint p,InputButtons b){ glm_ortho(0,graph_win_w,0,graph_win_h,0,4,proj); @@ -99,10 +107,9 @@ V core_tick(InputPoint p,InputButtons b){ tetro_draw(held); Q(IB_Z&b.p,tetro_rot(&held, 1)) Q(IB_X&b.p,tetro_rot(&held,-1)) - Q(IB_C&b.p,held=tetros[(held.i+1)%7]) + 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_1&b.p,tetro_bake(held)) -} + Q(IB_1&b.p,tetro_bake(held))} -- cgit v1.2.3