check other objects working now
This commit is contained in:
parent
e73f486116
commit
202f86331b
64
test01.c
64
test01.c
@ -17,6 +17,8 @@ uint8_t canvas[CANVAS_WIDTH][CANVAS_HEIGHT];
|
||||
#define I_COLOR 2
|
||||
|
||||
typedef enum {e_O, e_I} t_shape;
|
||||
typedef enum {e_Null, e_Down, e_Left, e_Right} t_direction;
|
||||
typedef enum {e_12oClock, e_3oClock, e_6oClock, e_9oClock} t_rotation;
|
||||
|
||||
typedef struct {
|
||||
t_shape shape;
|
||||
@ -29,11 +31,13 @@ typedef struct {
|
||||
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t rotation; // 0 = 12 o'clock, 1 = 3 o'clock, 2 = 6 o'clock, 3 = 9 o'clock
|
||||
t_rotation rotation;
|
||||
|
||||
uint8_t last_x;
|
||||
uint8_t last_y;
|
||||
uint8_t last_rotation;
|
||||
t_rotation last_rotation;
|
||||
|
||||
t_direction direction;
|
||||
|
||||
union {
|
||||
uint8_t O[O_WIDTH][O_HEIGHT];
|
||||
@ -43,7 +47,6 @@ typedef struct {
|
||||
|
||||
t_object object;
|
||||
|
||||
typedef enum {e_Down, e_Left, e_Right} t_direction;
|
||||
|
||||
|
||||
void showCanvas() {
|
||||
@ -69,11 +72,12 @@ void initObject(t_shape shape, uint8_t x, uint8_t y) {
|
||||
object.shape = shape;
|
||||
object.x = x;
|
||||
object.y = y;
|
||||
object.rotation = 0;
|
||||
object.rotation = e_12oClock;
|
||||
object.last_x = 0;
|
||||
object.last_y = 0;
|
||||
object.last_rotation = 0;
|
||||
object.last_rotation = e_12oClock;
|
||||
object.initial = 1;
|
||||
object.direction = e_Null;
|
||||
|
||||
switch (shape) {
|
||||
case e_O:
|
||||
@ -96,7 +100,7 @@ void drawObject() {
|
||||
switch (object.shape) {
|
||||
case e_O:
|
||||
switch (object.last_rotation) {
|
||||
case 0:
|
||||
case e_12oClock:
|
||||
canvas[object.last_x][object.last_y] = 0 | 0x80;
|
||||
canvas[object.last_x][object.last_y+1] = 0 | 0x80;
|
||||
canvas[object.last_x+1][object.last_y] = 0 | 0x80;
|
||||
@ -106,7 +110,7 @@ void drawObject() {
|
||||
break;
|
||||
case e_I:
|
||||
switch (object.last_rotation) {
|
||||
case 0:
|
||||
case e_12oClock:
|
||||
canvas[object.last_x][object.last_y] = 0 | 0x80;
|
||||
canvas[object.last_x][object.last_y+1] = 0 | 0x80;
|
||||
canvas[object.last_x][object.last_y+2] = 0 | 0x80;
|
||||
@ -120,7 +124,7 @@ void drawObject() {
|
||||
switch (object.shape) {
|
||||
case e_O:
|
||||
switch (object.rotation) {
|
||||
case 0:
|
||||
case e_12oClock:
|
||||
canvas[object.x][object.y] = object.O[0][0] | 0x80;
|
||||
canvas[object.x][object.y+1] = object.O[0][1] | 0x80;
|
||||
canvas[object.x+1][object.y] = object.O[1][0] | 0x80;
|
||||
@ -130,7 +134,7 @@ void drawObject() {
|
||||
break;
|
||||
case e_I:
|
||||
switch (object.rotation) {
|
||||
case 0:
|
||||
case e_12oClock:
|
||||
canvas[object.x][object.y] = object.O[0][0] | 0x80;
|
||||
canvas[object.x][object.y+1] = object.O[0][1] | 0x80;
|
||||
canvas[object.x][object.y+2] = object.O[0][2] | 0x80;
|
||||
@ -148,6 +152,8 @@ void moveObject(t_direction direction) {
|
||||
object.last_y = object.y;
|
||||
object.last_rotation = object.rotation;
|
||||
|
||||
object.direction = direction;
|
||||
|
||||
switch (direction) {
|
||||
case e_Down:
|
||||
object.y = object.y + 1;
|
||||
@ -158,6 +164,8 @@ void moveObject(t_direction direction) {
|
||||
case e_Right:
|
||||
object.x = object.x + 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,32 +181,50 @@ int checkCanvasBordersForObject() {
|
||||
}
|
||||
|
||||
int checkOtherObjectsTouchedForObject() {
|
||||
return 0;
|
||||
// return true if another object is touched
|
||||
int res = 0;
|
||||
|
||||
// BROKEN! That doesn't work, pixels of the moving object would also be considered.
|
||||
// The direction must be considered, only the first pixels in the moving direction
|
||||
// must be checked.
|
||||
switch (object.shape) {
|
||||
case e_O:
|
||||
switch (object.rotation) {
|
||||
case 0:
|
||||
res = (canvas[object.x][object.y] != 0) ||
|
||||
(canvas[object.x][object.y+1] != 0) ||
|
||||
(canvas[object.x+1][object.y] != 0) ||
|
||||
case e_12oClock:
|
||||
switch (object.direction) {
|
||||
case e_Down:
|
||||
res = (canvas[object.x][object.y+1] != 0) ||
|
||||
(canvas[object.x+1][object.y+1] != 0);
|
||||
break;
|
||||
case e_Left:
|
||||
res = (canvas[object.x][object.y] != 0) ||
|
||||
(canvas[object.x][object.y+1] != 0);
|
||||
break;
|
||||
case e_Right:
|
||||
res = (canvas[object.x+1][object.y] != 0) ||
|
||||
(canvas[object.x+1][object.y+1] != 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case e_I:
|
||||
switch (object.rotation) {
|
||||
case 0:
|
||||
case e_12oClock:
|
||||
switch (object.direction) {
|
||||
case e_Down:
|
||||
res = (canvas[object.x][object.y+3] != 0);
|
||||
break;
|
||||
case e_Left:
|
||||
case e_Right:
|
||||
res = (canvas[object.x][object.y] != 0) ||
|
||||
(canvas[object.x][object.y+1] != 0) ||
|
||||
(canvas[object.x][object.y+2] != 0) ||
|
||||
(canvas[object.x][object.y+3] != 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -318,5 +344,7 @@ int main(int argc, char *argv[]) {
|
||||
showCanvas();
|
||||
}
|
||||
|
||||
showCanvas();
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user