still working on rotation, gotta quit going crazy lol
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include "m_block.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -366,4 +365,36 @@ int M_B_Generate_Block_Id(void) {
|
||||
return rand();
|
||||
}
|
||||
|
||||
int M_B_Can_Spawn_Blocks(void) { return _can_spawn_tetromino_flag; }
|
||||
int M_B_Can_Spawn_Blocks(void) { return _can_spawn_tetromino_flag; }
|
||||
|
||||
/* TODO: make this update around point */
|
||||
block_t *M_B_Rotate_Block_Around_Point(block_t *block_to_rotate,
|
||||
point_t rotation_point) {
|
||||
point_offset_t offset, transposed_offset;
|
||||
block_t *updated_block,
|
||||
*origin_block = M_B_Get_Block_At_Point(rotation_point);
|
||||
|
||||
offset.x_offset = block_to_rotate->point.x - rotation_point.x;
|
||||
offset.y_offset = block_to_rotate->point.y - rotation_point.y;
|
||||
|
||||
if (offset.x_offset > 0 || offset.x_offset < 0) {
|
||||
transposed_offset.x_offset = offset.y_offset;
|
||||
transposed_offset.y_offset = offset.x_offset * -1;
|
||||
} else {
|
||||
transposed_offset.x_offset = offset.y_offset;
|
||||
transposed_offset.y_offset = offset.x_offset;
|
||||
}
|
||||
|
||||
printf("Offset: %d,%d\n", transposed_offset.x_offset,
|
||||
transposed_offset.y_offset);
|
||||
|
||||
/* This code is duplicated many places */
|
||||
updated_block = M_B_Get_Block_At_Offset(origin_block, transposed_offset);
|
||||
updated_block->id = block_to_rotate->id;
|
||||
M_B_Set_Block_Type(updated_block, block_to_rotate->type);
|
||||
block_to_rotate->id = -1;
|
||||
M_B_Set_Block_Type(block_to_rotate, bt_Empty);
|
||||
printf("\nAddr %p != %p\n", updated_block, block_to_rotate);
|
||||
|
||||
return updated_block;
|
||||
}
|
||||
|
||||
@@ -29,5 +29,7 @@ void M_B_On_Block_Spawn(void (*callback)(block_t **blocks));
|
||||
int M_B_Point_Intersects_Static_Block(point_t point, int id);
|
||||
int M_B_Generate_Block_Id(void);
|
||||
int M_B_Can_Spawn_Blocks(void);
|
||||
block_t *M_B_Rotate_Block_Around_Point(block_t *block_to_rotate,
|
||||
point_t rotation_point);
|
||||
|
||||
#endif /* M_BLOCK_H_ */
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "m_tetromino.h"
|
||||
#include "m_block.h"
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Blocks are gauranteed to be in order top left to bottom right */
|
||||
block_t *_tetromino_blocks[BLOCKS_WITHIN_A_TETROMINO];
|
||||
point_t origin_point;
|
||||
int registered_flag = 0;
|
||||
|
||||
void M_T_Update_Tetromino(void) { M_T_Tetromino_Fall(); }
|
||||
@@ -14,6 +16,7 @@ void M_T_Tetromino_Fall(void) {
|
||||
for (i = BLOCKS_WITHIN_A_TETROMINO - 1; i >= 0; i--) {
|
||||
_tetromino_blocks[i] = M_B_Move_Block_Down(_tetromino_blocks[i]);
|
||||
}
|
||||
origin_point.y++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,15 +28,16 @@ void M_T_Register_Falling_Blocks(block_t *blocks[BLOCKS_WITHIN_A_TETROMINO]) {
|
||||
for (i = 0; i < BLOCKS_WITHIN_A_TETROMINO; i++) {
|
||||
_tetromino_blocks[i] = blocks[i];
|
||||
}
|
||||
origin_point = _tetromino_blocks[0]->point;
|
||||
}
|
||||
|
||||
void M_T_Move_Tetromino_Left(void) {
|
||||
int i;
|
||||
printf("test");
|
||||
if (registered_flag && M_B_Can_Move_Blocks_Left(_tetromino_blocks)) {
|
||||
for (i = 0; i < BLOCKS_WITHIN_A_TETROMINO; i++) {
|
||||
_tetromino_blocks[i] = M_B_Move_Block_Left(_tetromino_blocks[i]);
|
||||
}
|
||||
origin_point.x--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,5 +47,28 @@ void M_T_Move_Tetromino_Right(void) {
|
||||
for (i = BLOCKS_WITHIN_A_TETROMINO - 1; i >= 0; i--) {
|
||||
_tetromino_blocks[i] = M_B_Move_Block_Right(_tetromino_blocks[i]);
|
||||
}
|
||||
origin_point.x++;
|
||||
}
|
||||
}
|
||||
|
||||
int M_T_Block_Compare_Function(const void *a, const void *b) {
|
||||
const block_t *block_a = a, *block_b = b;
|
||||
return block_a < block_b;
|
||||
}
|
||||
|
||||
void M_T_Rotate_Tetromino(void) {
|
||||
int i;
|
||||
printf("\n\n");
|
||||
for (i = 0; i < BLOCKS_WITHIN_A_TETROMINO; i++) {
|
||||
printf("%d: %p\n", i, (_tetromino_blocks[i]));
|
||||
}
|
||||
if (registered_flag) {
|
||||
for (i = 0; i < BLOCKS_WITHIN_A_TETROMINO; i++) {
|
||||
_tetromino_blocks[i] =
|
||||
M_B_Rotate_Block_Around_Point(_tetromino_blocks[i], origin_point);
|
||||
}
|
||||
qsort(_tetromino_blocks, BLOCKS_WITHIN_A_TETROMINO, sizeof(block_t *),
|
||||
M_T_Block_Compare_Function);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ void M_T_Tetromino_Fall(void);
|
||||
void M_T_Register_Falling_Blocks(block_t **blocks);
|
||||
void M_T_Move_Tetromino_Left(void);
|
||||
void M_T_Move_Tetromino_Right(void);
|
||||
void M_T_Rotate_Tetromino(void);
|
||||
|
||||
#endif /* M_TETROMINO_H_ */
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "m_tetromino.h"
|
||||
#include "raylib.h"
|
||||
|
||||
void TC_Process_Input(void) {
|
||||
void TC_Process_Input_Per_Tick(void) {
|
||||
/* Was having issues with raylib input, wasn't having these
|
||||
issues before but I figured out that I can just cast to
|
||||
a char to get the result I want :)
|
||||
@@ -15,3 +15,9 @@ void TC_Process_Input(void) {
|
||||
M_T_Move_Tetromino_Right();
|
||||
}
|
||||
}
|
||||
|
||||
void TC_Process_Input_Per_Frame(void) {
|
||||
if ((char)IsKeyPressed(KEY_SPACE)) {
|
||||
M_T_Rotate_Tetromino();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef TC_INPUT_H_
|
||||
#define TC_INPUT_H_
|
||||
|
||||
void TC_Process_Input(void);
|
||||
void TC_Process_Input_Per_Tick(void);
|
||||
void TC_Process_Input_Per_Frame(void);
|
||||
|
||||
#endif /* TC_INPUT_H_ */
|
||||
|
||||
@@ -50,8 +50,9 @@ void TC_Game_Loop(void) {
|
||||
while (!TC_Close_Window()) {
|
||||
while (M_B_Can_Spawn_Blocks()) {
|
||||
R_Draw_Ui();
|
||||
TC_Process_Input_Per_Frame();
|
||||
if (tick_rate == 0) {
|
||||
TC_Process_Input();
|
||||
TC_Process_Input_Per_Tick();
|
||||
M_T_Update_Tetromino();
|
||||
M_B_Update_Blocks();
|
||||
updated_blocks = M_B_Get_Blocks(&n_updated_blocks);
|
||||
|
||||
Reference in New Issue
Block a user