the end (nope)

This commit is contained in:
Masséna Fezard | Nounouille 2021-03-14 10:09:00 +01:00
parent 6c37e1270c
commit a5040e9e67
6 changed files with 29 additions and 24 deletions

View File

@ -27,6 +27,7 @@ set(ASSETS_cg
assets-cg/img/player.png
assets-cg/img/wall.png
assets-cg/img/spike.png
assets-cg/img/end.png
# ...
)

BIN
assets-cg/img/end.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

View File

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

View File

@ -3,32 +3,21 @@
#define LEVEL_SIZE 16
#define TILE_SIZE 12
/* see we use a typedef like bellow
* its lazy and allow you to type
* Vec2 instead of struct TwoValues */
// struct for a pair of values
typedef struct Vec2 {
int x, y;
} Vec2;
/* we do da same with player cause laziness never killed nobody
* wait */
// struct for player's data
typedef struct Player {
Vec2 pos;
Vec2 spawn;
} Player;
/* using a typedef is what cool kids do at least i think
* you might no remember what `int x` is :(
* if x is declared with `tile_t x` you know x is some tile :)
* knowledge is power and cool
* as bonus it looks cool in function declaration
* cool stuff told u :D */
// used for tiles
typedef int tile_t;
Vec2 search(tile_t x, tile_t level[16][16]);
/* here u can see i replaced x and y arguments with your twovalues struct
* u made smthing use it
* it will be handy in the future and makes better looking code */
int collide_pixel(Vec2 pos, tile_t obj, tile_t level[16][16]);
int collide(Vec2 pos, int h, tile_t obj, tile_t level[16][16]);
Player level_reset(Player player);

View File

@ -1,12 +1,10 @@
#include "main.h"
/* see use tile_t cause these stuff are tiles
* would you believe it? */
const tile_t level[16][16] = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 3, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 4, 0, 0, 1},
{1, 0, 0, 1, 3, 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, 1, 1, 0, 0, 0, 1, 1, 1, 1},

View File

@ -1,3 +1,6 @@
// ZkwuL by Massena
// Optimisation and rewrite thanks to KikooDX
#include <gint/display.h>
#include <gint/keyboard.h>
#include "main.h"
@ -21,7 +24,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)
if(obj == level[pos.x / TILE_SIZE][pos.y / TILE_SIZE]) {
if(obj == level[pos.y / TILE_SIZE][pos.x / TILE_SIZE]) {
return 1;
}
else {
@ -30,9 +33,8 @@ 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
* avoid repetition later on ezier to work on */
// 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
@ -57,10 +59,12 @@ int main(void) {
extern bopti_image_t img_player;
extern bopti_image_t img_wall;
extern bopti_image_t img_spike;
extern bopti_image_t img_end;
extern tile_t level[LEVEL_SIZE][LEVEL_SIZE];
int running = 1;
int timer = 0; // lol
// player
Player player = {
@ -87,6 +91,11 @@ int main(void) {
// spikes
dimage(m * TILE_SIZE, n * TILE_SIZE, &img_spike);
break;
case 4:
// end ring
dsubimage(m * TILE_SIZE, n * TILE_SIZE, &img_end,
((timer / 30) % 4) * 12, 0, 12, 12, 0);
break;
}
}
}
@ -96,7 +105,7 @@ int main(void) {
dupdate();
/* if something has x and y, you probably want to use your Vec2 struct */
//
Vec2 mov = {
.x = keydown(KEY_RIGHT) - keydown(KEY_LEFT),
.y = keydown(KEY_DOWN) - keydown(KEY_UP)
@ -117,7 +126,11 @@ int main(void) {
player = level_reset(player);
}
if(keydown(KEY_EXIT)) running = 0;
if(keydown(KEY_EXIT) || collide(player.pos, 0, 4, level)) {
running = 0;
}
++timer; // lol^2
}
return 1;