This commit is contained in:
Masséna Fezard | Nounouille 2021-03-08 18:49:51 +01:00
parent 378eee0ba1
commit 1cc7ebad05
3 changed files with 27 additions and 14 deletions

View File

@ -1 +1,7 @@
int collide(int x, int y, int level[16][16]);
#pragma once
#define LEVEL_SIZE 16
#define TILE_SIZE 12
int collide_pixel(int x, int y, int level[16][16]);
int collide(int x, int y, int level[16][16]);

View File

@ -1,7 +1,7 @@
const int level[16][16] = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},

View File

@ -2,15 +2,22 @@
#include <gint/keyboard.h>
#include "main.h"
int collide(int x, int y, int level[16][16]) {
// Check if there's something in the square (x + 1, y + 1, x + 11, y + 11)
if(!level[x / 12][y / 12]
&& !level[(x + 11) / 12][y / 12]
&& !level[x / 12][(y + 11) / 12]
&& !level[(x + 11) / 12][(y + 11) / 12]) {
return 0;
int collide_pixel(int x, int y, int level[LEVEL_SIZE][LEVEL_SIZE]) {
// Check if there's something in (x, y)
return level[x][y];
}
int collide(int x, int y, int level[LEVEL_SIZE][LEVEL_SIZE]) {
// Check if there's something in
// the square (x + 1, y + 1, x + 11, y + 11)
if( collide_pixel(x / TILE_SIZE, y / TILE_SIZE, level) ||
collide_pixel(x / TILE_SIZE, (y + TILE_SIZE - 1) / TILE_SIZE, level) ||
collide_pixel((x + TILE_SIZE - 1) / TILE_SIZE, y / TILE_SIZE, level) ||
collide_pixel((x + TILE_SIZE - 1) / TILE_SIZE, (y + TILE_SIZE - 1) / TILE_SIZE, level)
) {
return 1;
}
return 1;
return 0;
}
int main(void)
@ -18,7 +25,7 @@ int main(void)
extern bopti_image_t img_player;
extern bopti_image_t img_wall;
extern int level[16][16];
extern int level[LEVEL_SIZE][LEVEL_SIZE];
int running = 1;
@ -35,10 +42,10 @@ int main(void)
dimage(player_x, player_y, &img_player);
// drawing the level
for(int m = 0; m < 16; ++m) {
for(int n = 0; n < 16; ++n) {
for(int m = 0; m < LEVEL_SIZE; ++m) {
for(int n = 0; n < LEVEL_SIZE; ++n) {
if(level[m][n]) {
dimage(m * 12, n * 12, &img_wall);
dimage(m * TILE_SIZE, n * TILE_SIZE, &img_wall);
}
}
}