first-try-semi-functionnal-collisions

This commit is contained in:
Masséna Fezard | Nounouille 2021-03-08 16:51:00 +01:00
parent c1001437b2
commit d750bf2d8c
3 changed files with 24 additions and 4 deletions

View File

@ -7,6 +7,7 @@ project(zkuwl)
include(GenerateG1A)
include(GenerateG3A)
include(Fxconv)
include_directories(include)
find_package(Gint 2.1 REQUIRED)
set(SOURCES

1
include/main.h Normal file
View File

@ -0,0 +1 @@
int collide(int x, int y, int level[16][16]);

View File

@ -1,5 +1,16 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include "main.h"
int collide(int x, int y, int level[16][16]) {
if(!level[x / 12][y / 12]
&& !level[(x + 12) / 12][y / 12]
&& !level[x / 12][(y + 12) / 12]
&& !level[(x + 12) / 12][(y + 12) / 12]) {
return 0;
}
return 1;
}
int main(void)
{
@ -32,12 +43,19 @@ int main(void)
}
dupdate();
int mov_x = keydown(KEY_RIGHT) - keydown(KEY_LEFT);
int mov_y = keydown(KEY_DOWN) - keydown(KEY_UP);
clearevents();
// trying to move the player >w<
player_x += keydown(KEY_RIGHT) - keydown(KEY_LEFT);
player_y += keydown(KEY_DOWN) - keydown(KEY_UP);
// trying to move the player >w<
if(!collide(player_x + mov_x, player_y, level)) {
player_x += mov_x;
}
if(!collide(player_x, player_y + mov_y, level)) {
player_y += mov_y;
}
if(keydown(KEY_EXIT)) {running = 0;}
}