This commit is contained in:
Masséna Fezard | Nounouille 2021-03-13 20:35:33 +01:00
parent 5a4269b02f
commit 9face1d63c
4 changed files with 25 additions and 19 deletions

View File

@ -4,4 +4,8 @@ player.png:
wall.png:
type: bopti-image
name: img_wall
name: img_wall
spike.png:
type: bopti-image
name: img_spike

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 B

After

Width:  |  Height:  |  Size: 134 B

View File

@ -3,14 +3,15 @@
#define LEVEL_SIZE 16
#define TILE_SIZE 12
struct Pos {
struct TwoValues {
int x, y;
};
struct Player {
int x, y;
struct TwoValues pos;
struct TwoValues spawn;
};
struct Pos search(int x, int level[16][16]);
struct TwoValues search(int x, int level[16][16]);
int collide_pixel(int x, int y, int obj, int level[16][16]);
int collide(int x, int y, int obj, int level[16][16]);

View File

@ -2,16 +2,16 @@
#include <gint/keyboard.h>
#include "main.h"
struct Pos search(int x, int level[16][16]) {
struct TwoValues search(int x, int level[16][16]) {
// Search for x in a given matrix.
// If x is found, return it coordinates
struct Pos coordinates = {0, 0};
struct TwoValues coordinates = {0, 0};
for(int m = 0; m < LEVEL_SIZE; ++m) {
for(int n = 0; n < LEVEL_SIZE; ++n) {
if(level[m][n] == x) {
// idk why m and n are inversed but it works kek
coordinates.x = n;
coordinates.y = m;
coordinates.x = n * 12;
coordinates.y = m * 12;
return coordinates;
}
}
@ -52,11 +52,12 @@ int main(void)
int running = 1;
// player
struct Player player = {0, 0};
struct Pos spawn = {0, 0};
spawn = search(2, level);
player.x = spawn.x * 12;
player.y = spawn.y * 12;
struct Player player = {
.pos = {0, 0},
.spawn = {0, 0}
};
player.spawn = search(2, level);
player.pos = player.spawn;
// main loop
while(running) {
@ -64,12 +65,12 @@ int main(void)
dclear(C_BLACK);
// drawing the player
dimage(player.x, player.y, &img_player);
dimage(player.pos.x, player.pos.y, &img_player);
// drawing the level
for(int m = 0; m < LEVEL_SIZE; ++m) {
for(int n = 0; n < LEVEL_SIZE; ++n) {
if(level[m][n] == 1) {
if(level[n][m] == 1) {
dimage(m * TILE_SIZE, n * TILE_SIZE, &img_wall);
}
}
@ -81,12 +82,12 @@ int main(void)
clearevents();
// trying to move the player >w<
if(!collide(player.x + mov_x, player.y, 1, level)) {
player.x += mov_x;
if(!collide(player.pos.x + mov_x, player.pos.y, 1, level)) {
player.pos.x += mov_x;
}
if(!collide(player.x, player.y + mov_y, 1, level)) {
player.y += mov_y;
if(!collide(player.pos.x, player.pos.y + mov_y, 1, level)) {
player.pos.y += mov_y;
}
if(keydown(KEY_EXIT)) {running = 0;}