useless-tier commit

This commit is contained in:
Masséna Fezard | Nounouille 2021-03-14 10:13:31 +01:00
parent a5040e9e67
commit e7b3b4a805
2 changed files with 25 additions and 26 deletions

View File

@ -3,18 +3,18 @@
#define LEVEL_SIZE 16
#define TILE_SIZE 12
// struct for a pair of values
/* struct for a pair of values */
typedef struct Vec2 {
int x, y;
} Vec2;
// struct for player's data
/* struct for player's data */
typedef struct Player {
Vec2 pos;
Vec2 spawn;
} Player;
// used for tiles
/* used for tiles */
typedef int tile_t;
Vec2 search(tile_t x, tile_t level[16][16]);

View File

@ -1,18 +1,18 @@
// ZkwuL by Massena
// Optimisation and rewrite thanks to KikooDX
/* ZkwuL by Massena */
/* Optimisation and rewrite thanks to KikooDX */
#include <gint/display.h>
#include <gint/keyboard.h>
#include "main.h"
Vec2 search(tile_t x, tile_t level[16][16]) {
// Search for x in a given matrix.
// If x is found, return it coordinates
/* Search for x in a given matrix. */
/* If x is found, return it coordinates */
Vec2 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
/* idk why m and n are inversed but it works kek */
coordinates.x = n * 12;
coordinates.y = m * 12;
return coordinates;
@ -23,7 +23,7 @@ Vec2 search(tile_t x, tile_t level[16][16]) {
}
int collide_pixel(Vec2 pos, tile_t obj, tile_t level[LEVEL_SIZE][LEVEL_SIZE]) {
// Check if there's something in (x, y)
/* Check if there's something in (x, y) */
if(obj == level[pos.y / TILE_SIZE][pos.x / TILE_SIZE]) {
return 1;
}
@ -33,13 +33,13 @@ int collide_pixel(Vec2 pos, tile_t obj, tile_t level[LEVEL_SIZE][LEVEL_SIZE]) {
}
int collide(Vec2 pos, int h, tile_t obj, tile_t level[LEVEL_SIZE][LEVEL_SIZE]) {
// tl = top left
// br = bottom right
/* tl = top left */
/* br = bottom right */
const Vec2 pos_tl = (Vec2){pos.x + h, pos.y + h};
const Vec2 pos_br = (Vec2){pos.x + TILE_SIZE - h - 1, pos.y + TILE_SIZE - h - 1};
// Check if there's something in
// the square (x + 1, y + 1, x + 11, y + 11)
// The size of the hitbox changes with h
/* Check if there's something in */
/* the square (x + 1, y + 1, x + 11, y + 11) */
/* The size of the hitbox changes with h */
if(collide_pixel(pos_tl, obj, level) ||
collide_pixel(pos_br, obj, level) ||
collide_pixel((Vec2){pos_tl.x, pos_br.y}, obj, level) ||
@ -64,9 +64,9 @@ int main(void) {
extern tile_t level[LEVEL_SIZE][LEVEL_SIZE];
int running = 1;
int timer = 0; // lol
int timer = 0; /* lol */
// player
/* player */
Player player = {
.pos = {0, 0},
.spawn = {0, 0}
@ -74,25 +74,25 @@ int main(void) {
player.spawn = search(2, level);
player = level_reset(player);
// main loop
/* main loop */
while(running) {
dclear(C_BLACK);
// drawing the level
/* drawing the level */
for(int m = 0; m < LEVEL_SIZE; ++m) {
for(int n = 0; n < LEVEL_SIZE; ++n) {
switch(level[n][m]) {
case 1:
// walls
/* walls */
dimage(m * TILE_SIZE, n * TILE_SIZE, &img_wall);
break;
case 3:
// spikes
/* spikes */
dimage(m * TILE_SIZE, n * TILE_SIZE, &img_spike);
break;
case 4:
// end ring
/* end ring */
dsubimage(m * TILE_SIZE, n * TILE_SIZE, &img_end,
((timer / 30) % 4) * 12, 0, 12, 12, 0);
break;
@ -100,19 +100,18 @@ int main(void) {
}
}
// drawing the player
/* drawing the player */
dimage(player.pos.x, player.pos.y, &img_player);
dupdate();
//
Vec2 mov = {
.x = keydown(KEY_RIGHT) - keydown(KEY_LEFT),
.y = keydown(KEY_DOWN) - keydown(KEY_UP)
};
clearevents();
// trying to move the player >w<
/* trying to move the player >w< */
if(!collide((Vec2){player.pos.x + mov.x, player.pos.y}, 0, 1, level)) {
player.pos.x += mov.x;
}
@ -121,7 +120,7 @@ int main(void) {
player.pos.y += mov.y;
}
// d i e
/* d i e */
if(collide(player.pos, 2, 3, level)) {
player = level_reset(player);
}
@ -130,7 +129,7 @@ int main(void) {
running = 0;
}
++timer; // lol^2
++timer; /* lol^2 */
}
return 1;