This commit is contained in:
Masséna Fezard | Nounouille 2021-12-20 16:17:34 +01:00
parent ca44cc84f5
commit e2d4f32a90
3 changed files with 8 additions and 16 deletions

View File

@ -31,7 +31,7 @@ typedef struct Player {
/* dynamic level data */
typedef struct Level {
int width, height;
tile_t data[];
tile_t *data;
} Level;
/* struct for rem movement and collision check */

View File

@ -1,6 +1,7 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <gint/std/string.h>
#include <stdlib.h>
#include "input.h"
#include "main.h"
@ -16,6 +17,10 @@ main(void)
.height = 28,
};
/* dynamic level size */
level.data =
(tile_t *)malloc(level.width * level.height * sizeof(tile_t));
tile_t data[] = {
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
@ -104,11 +109,8 @@ main(void)
memcpy(level.data, data, sizeof(data));
input_init();
Player player = {.pos = {50, 50}, .spawn = {0, 0}, .spd = {0, 0}};
Vec2 camera = {0, 0};
int running = 1;
while (running) {
@ -134,9 +136,6 @@ main(void)
camera.y = level.height * TILE_S - 224;
}
/* debug */
Vec2 camera = {0, 0};
/* tiles */
for (int m = 0; m < level.height; ++m) {
for (int n = 0; n < level.width; ++n) {
@ -152,8 +151,8 @@ main(void)
}
drect(player.pos.x - camera.x, player.pos.y - camera.y,
player.pos.x + PLAYER_SIZE - camera.x,
player.pos.y + PLAYER_SIZE - camera.y, C_BLACK);
player.pos.x + PLAYER_SIZE - camera.x - 1,
player.pos.y + PLAYER_SIZE - camera.y - 1, C_BLACK);
dprint(10, 10, C_BLACK, "%d", player.pos.x);
dprint(10, 30, C_BLACK, "%d", player.pos.y);

View File

@ -51,10 +51,6 @@ collide_pixel(Vec2 pos, tile_t obj, Level level)
const int position = pos.x / TILE_S + pos.y / TILE_S * level.width;
const int uwu = level.data[position];
/* debug */
drect(pos.x / TILE_S * 8, pos.y / TILE_S * 8, pos.x / TILE_S * 8 + 8,
pos.y / TILE_S * 8 + 8, C_BLUE);
if (position < 0 || position > level.width * level.height || uwu == 0) {
return 0;
}
@ -88,9 +84,6 @@ collide(Vec2 pos, int h, tile_t obj, Level level)
/* the square (x, y, x + 15, y + 15) */
/* The size of the hitbox changes with h */
/* debug */
drect(pos_tl.x, pos_tl.y, pos_br.x, pos_br.y, C_RED);
if (collide_pixel(pos_tl, obj, level) ||
collide_pixel(pos_br, obj, level) ||
collide_pixel((Vec2){pos_tl.x, pos_br.y}, obj, level) ||