commit 6fd8defac556bc81f1d638f190005b6952492a00
parent bcbc8858ab29cda780143eceeeda5875e1ff8027
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 23 Dec 2022 16:35:21 +0900
test collision
Diffstat:
M | main.c | | | 33 | +++++++++++++++------------------ |
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/main.c b/main.c
@@ -11,7 +11,7 @@
#define INIT_WIDTH 800
#define INIT_HEIGHT 600
#define FPS 60
-#define BLOCK_COUNT 100
+#define BLOCK_COUNT 3
/* variables */
@@ -154,10 +154,9 @@ game_init(void)
clock_gettime(CLOCK_REALTIME, &t);
srand(t.tv_nsec);
if(!blocks[i]) // not allocated
- if(!(blocks[i] = obj_create((float)rand()*win_width/(float)RAND_MAX,
- (float)rand()*win_height/(float)RAND_MAX,
- rand()*300.0/RAND_MAX - 150,
- rand()*300.0/RAND_MAX - 150,
+ if(!(blocks[i] = obj_create((i + 1) * 100,
+ 200,
+ 0, 0,
0, 0, 100, 10, 10))){
fprintf(stderr, "couldn't create object: block");
exit(1);
@@ -209,6 +208,7 @@ game_play(void)
XClearArea(display, window, 0, 0, win_width, win_height, False);
draw_object(square, pgc);
for (int i = 0; i < BLOCK_COUNT; i++){
+ XSetForeground(display, bgc, 255 << 8 * i);
draw_object(blocks[i], bgc);
}
//XDrawString(display, window, fgc, square->px, square->py, "player", 6);
@@ -289,28 +289,25 @@ handle_inputs(void)
}
}
+ square->vx = 0;
if (key_state[Key_D] == Key_Down)
- square->vx += 300;
+ square->vx += 100;
else
- square->vx -= 300;
+ square->vx -= 100;
if (key_state[Key_A] == Key_Down)
- square->vx += -300;
+ square->vx += -100;
else
- square->vx -= -300;
+ square->vx -= -100;
+ square->vy = 0;
if (key_state[Key_S] == Key_Down)
- square->vy += 300;
+ square->vy += 100;
else
- square->vy -= 300;
+ square->vy -= 100;
if (key_state[Key_W] == Key_Down)
- square->vy += -300;
+ square->vy += -100;
else
- square->vy -= -300;
-
- if (square->vx > 300) square->vx = 300;
- if (square->vx < -300) square->vx = -300;
- if (square->vy > 300) square->vy = 300;
- if (square->vy < -300) square->vy = -300;
+ square->vy -= -100;
}
void