format
This commit is contained in:
parent
af0f0c64c9
commit
ca44cc84f5
|
@ -0,0 +1,9 @@
|
|||
BasedOnStyle: LLVM
|
||||
IndentWidth: 8
|
||||
UseTab: AlignWithSpaces
|
||||
BreakBeforeBraces: Linux
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
IndentCaseLabels: false
|
||||
ColumnLimit: 80
|
||||
AlignConsecutiveMacros: true
|
||||
AlwaysBreakAfterReturnType: TopLevelDefinitions
|
|
@ -0,0 +1,11 @@
|
|||
all: format
|
||||
fxsdk build-cg
|
||||
|
||||
format:
|
||||
/usr/bin/clang-format -style=file -i src/**.c include/**.h
|
||||
|
||||
clean:
|
||||
rm -Rf build-cg/
|
||||
rm -f *.g3a
|
||||
|
||||
.PHONY: format clean
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#define PLAYER_SIZE 16
|
||||
|
||||
#define TILE_S 8
|
||||
#define TILE_S 8
|
||||
#define TILESET_W 12
|
||||
#define TILESET_H 6
|
||||
|
||||
|
@ -39,5 +39,3 @@ typedef struct Res_Mov {
|
|||
Player player;
|
||||
Vec2 moved;
|
||||
} Res_Mov;
|
||||
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
#include "main.h"
|
||||
|
||||
#define PLAYER_ACC 0.8
|
||||
#define BASE_FRIC 0.2
|
||||
#define GRAVITY 0.4
|
||||
#define JUMP_H 6
|
||||
#define BASE_FRIC 0.2
|
||||
#define GRAVITY 0.4
|
||||
#define JUMP_H 6
|
||||
|
||||
Player player_reset(Player player, Level level);
|
||||
Vec2 search(tile_t x, Level level);
|
||||
int convert_all(tile_t x, tile_t y, Level level);
|
||||
int collide_pixel(Vec2 pos, tile_t obj, Level level);
|
||||
int collide(Vec2 pos, int h, tile_t obj, Level level);
|
||||
Res_Mov move(Player player, Level level);
|
||||
Player player_reset(Player player, Level level);
|
||||
Vec2 search(tile_t x, Level level);
|
||||
int convert_all(tile_t x, tile_t y, Level level);
|
||||
int collide_pixel(Vec2 pos, tile_t obj, Level level);
|
||||
int collide(Vec2 pos, int h, tile_t obj, Level level);
|
||||
Res_Mov move(Player player, Level level);
|
||||
Player player_reset(Player player, Level level);
|
||||
|
|
225
src/main.c
225
src/main.c
|
@ -2,135 +2,198 @@
|
|||
#include <gint/keyboard.h>
|
||||
#include <gint/std/string.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "input.h"
|
||||
#include "main.h"
|
||||
#include "player.h"
|
||||
|
||||
int main(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
extern bopti_image_t img_tileset;
|
||||
|
||||
Level level = {
|
||||
.width = 50,
|
||||
.height = 28,
|
||||
};
|
||||
|
||||
.width = 50,
|
||||
.height = 28,
|
||||
};
|
||||
|
||||
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, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 50, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 49, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 14, 14, 14, 14,
|
||||
26, 26, 26, 26, 26, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 26, 26, 26, 26, 26,
|
||||
40, 41, 64, 0, 0, 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, 13, 14,
|
||||
14, 38, 2, 2, 2, 2, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 37, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 18, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 13, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 18, 13, 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, 18, 13, 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, 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, 50, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 26, 26, 26, 26, 26, 49, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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
||||
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, 18, 13, 14,
|
||||
14, 14, 14, 14, 14, 14};
|
||||
|
||||
memcpy(level.data, data, sizeof(data));
|
||||
|
||||
|
||||
input_init();
|
||||
|
||||
Player player = {
|
||||
.pos = {50, 50},
|
||||
.spawn = {0, 0},
|
||||
.spd = {0, 0}
|
||||
};
|
||||
Player player = {.pos = {50, 50}, .spawn = {0, 0}, .spd = {0, 0}};
|
||||
|
||||
Vec2 camera = {0, 0};
|
||||
|
||||
|
||||
int running = 1;
|
||||
|
||||
while(running) {
|
||||
while (running) {
|
||||
|
||||
/* camera thing */
|
||||
|
||||
dclear(C_WHITE);
|
||||
|
||||
|
||||
camera.x = player.pos.x - 190;
|
||||
|
||||
if(camera.x < 2) {camera.x = 2;}
|
||||
if(camera.x > level.width * TILE_S - 398) {camera.x = level.width * TILE_S - 398;}
|
||||
if (camera.x < 2) {
|
||||
camera.x = 2;
|
||||
}
|
||||
if (camera.x > level.width * TILE_S - 398) {
|
||||
camera.x = level.width * TILE_S - 398;
|
||||
}
|
||||
camera.y = player.pos.y - 104;
|
||||
|
||||
if(camera.y < 0) {camera.y = 0;}
|
||||
if(camera.y > level.height * TILE_S - 224) {camera.y = level.height * TILE_S - 224;}
|
||||
if (camera.y < 0) {
|
||||
camera.y = 0;
|
||||
}
|
||||
if (camera.y > level.height * TILE_S - 224) {
|
||||
camera.y = level.height * TILE_S - 224;
|
||||
}
|
||||
|
||||
/* debug */
|
||||
Vec2 camera = {0, 0};
|
||||
|
||||
/* debug */
|
||||
Vec2 camera = {0, 0};
|
||||
|
||||
/* tiles */
|
||||
for(int m = 0; m < level.height; ++m) {
|
||||
for(int n = 0; n < level.width; ++n) {
|
||||
for (int m = 0; m < level.height; ++m) {
|
||||
for (int n = 0; n < level.width; ++n) {
|
||||
tile_t tile = level.data[n + m * level.width];
|
||||
dsubimage(n * TILE_S - camera.x, m * TILE_S - camera.y, &img_tileset,
|
||||
((tile - 1) % TILESET_W) * TILE_S,
|
||||
((tile - 1) / TILESET_W) * TILE_S,
|
||||
TILE_S, TILE_S, 0);
|
||||
/* dprint(n * TILE_S - camera.x, m * TILE_S - camera.y,
|
||||
C_BLACK, "%d", tile); */
|
||||
|
||||
dsubimage(n * TILE_S - camera.x,
|
||||
m * TILE_S - camera.y, &img_tileset,
|
||||
((tile - 1) % TILESET_W) * TILE_S,
|
||||
((tile - 1) / TILESET_W) * TILE_S,
|
||||
TILE_S, TILE_S, 0);
|
||||
/* dprint(n * TILE_S - camera.x, m * TILE_S -
|
||||
camera.y, C_BLACK, "%d", tile); */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
player.pos.y + PLAYER_SIZE - camera.y, C_BLACK);
|
||||
|
||||
dprint(10, 10, C_BLACK, "%d", player.pos.x);
|
||||
dprint(10, 30, C_BLACK, "%d", player.pos.y);
|
||||
|
||||
|
||||
/* input */
|
||||
input_step();
|
||||
|
||||
Vec2 mov = {
|
||||
.x = input_down(K_RIGHT) - input_down(K_LEFT),
|
||||
.y = input_down(K_DOWN) - input_down(K_UP),
|
||||
.x = input_down(K_RIGHT) - input_down(K_LEFT),
|
||||
.y = input_down(K_DOWN) - input_down(K_UP),
|
||||
};
|
||||
|
||||
player.spd.x *= (1 - BASE_FRIC); /* friction */
|
||||
player.spd.y *= (1 - BASE_FRIC); /* friction */
|
||||
player.spd.x *= (1 - BASE_FRIC); /* friction */
|
||||
player.spd.y *= (1 - BASE_FRIC); /* friction */
|
||||
player.spd.x += mov.x * PLAYER_ACC; /* idem */
|
||||
player.spd.y += mov.y * PLAYER_ACC; /* idem */
|
||||
|
||||
if(player.spd.x > -0.2 && player.spd.x < 0.2) {player.spd.x = 0;}
|
||||
if(player.spd.y > -0.2 && player.spd.y < 0.2) {player.spd.y = 0;}
|
||||
|
||||
|
||||
if (player.spd.x > -0.2 && player.spd.x < 0.2) {
|
||||
player.spd.x = 0;
|
||||
}
|
||||
if (player.spd.y > -0.2 && player.spd.y < 0.2) {
|
||||
player.spd.y = 0;
|
||||
}
|
||||
|
||||
Res_Mov position = move(player, level); /* i'm crying rn */
|
||||
player = position.player;
|
||||
|
||||
if(position.moved.x) {player.spd.x = 0;}
|
||||
if(position.moved.y) {player.spd.y = 0;}
|
||||
|
||||
player = position.player;
|
||||
|
||||
if (position.moved.x) {
|
||||
player.spd.x = 0;
|
||||
}
|
||||
if (position.moved.y) {
|
||||
player.spd.y = 0;
|
||||
}
|
||||
|
||||
/* exit */
|
||||
if(input_pressed(K_EXIT)) {break;}
|
||||
if (input_pressed(K_EXIT)) {
|
||||
break;
|
||||
}
|
||||
|
||||
dupdate();
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
111
src/player.c
111
src/player.c
|
@ -2,92 +2,119 @@
|
|||
|
||||
#include "player.h"
|
||||
|
||||
int sign(int n) {
|
||||
int
|
||||
sign(int n)
|
||||
{
|
||||
/* I do not know well C lmao */
|
||||
|
||||
if(n > 0) {return 1;}
|
||||
else {return -1;}
|
||||
if (n > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Vec2 search(tile_t x, Level level) {
|
||||
Vec2
|
||||
search(tile_t x, Level level)
|
||||
{
|
||||
/* Search for x in a given matrix. */
|
||||
/* If x is found, return it coordinates */
|
||||
Vec2 coordinates = {0, 0};
|
||||
for(int m = 0; m < level.width; ++m) {
|
||||
for(int n = 0; n < level.height; ++n) {
|
||||
if(level.data[m + n * level.width] == x) {
|
||||
coordinates.x = m * TILE_S;
|
||||
coordinates.y = n * TILE_S;
|
||||
return coordinates;
|
||||
}
|
||||
for (int m = 0; m < level.width; ++m) {
|
||||
for (int n = 0; n < level.height; ++n) {
|
||||
if (level.data[m + n * level.width] == x) {
|
||||
coordinates.x = m * TILE_S;
|
||||
coordinates.y = n * TILE_S;
|
||||
return coordinates;
|
||||
}
|
||||
}
|
||||
}
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
int convert_all(tile_t x, tile_t y, Level level) {
|
||||
int
|
||||
convert_all(tile_t x, tile_t y, Level level)
|
||||
{
|
||||
/* convert all instance of a tile */
|
||||
for(int i = 0; i < level.width * level.height; ++i) {
|
||||
if(level.data[i] == x) {level.data[i] = y;}
|
||||
for (int i = 0; i < level.width * level.height; ++i) {
|
||||
if (level.data[i] == x) {
|
||||
level.data[i] = y;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int collide_pixel(Vec2 pos, tile_t obj, Level level) {
|
||||
int
|
||||
collide_pixel(Vec2 pos, tile_t obj, Level level)
|
||||
{
|
||||
/* Check if there's something in (x, y) */
|
||||
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;}
|
||||
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;
|
||||
}
|
||||
|
||||
/* others */
|
||||
if(obj != 1) {
|
||||
if(uwu == obj) {return position;}
|
||||
else {return 0;}
|
||||
if (obj != 1) {
|
||||
if (uwu == obj) {
|
||||
return position;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* solids */
|
||||
if((uwu - 1 ) % TILESET_W <= 6) {return 1;}
|
||||
else {return 0;}
|
||||
if ((uwu - 1) % TILESET_W <= 6) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int collide(Vec2 pos, int h, tile_t obj, Level level) {
|
||||
int
|
||||
collide(Vec2 pos, int h, tile_t obj, Level level)
|
||||
{
|
||||
/* tl = top left */
|
||||
/* br = bottom right */
|
||||
const Vec2 pos_tl = (Vec2){pos.x + h, pos.y + h};
|
||||
const Vec2 pos_br = (Vec2){pos.x + PLAYER_SIZE - h - 1, pos.y + PLAYER_SIZE - h - 1};
|
||||
const Vec2 pos_br =
|
||||
(Vec2){pos.x + PLAYER_SIZE - h - 1, pos.y + PLAYER_SIZE - h - 1};
|
||||
/* Check if there's something in */
|
||||
/* 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) ||
|
||||
collide_pixel((Vec2){pos_br.x, pos_tl.y}, obj, level))
|
||||
{
|
||||
|
||||
if (collide_pixel(pos_tl, obj, level) ||
|
||||
collide_pixel(pos_br, obj, level) ||
|
||||
collide_pixel((Vec2){pos_tl.x, pos_br.y}, obj, level) ||
|
||||
collide_pixel((Vec2){pos_br.x, pos_tl.y}, obj, level)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Res_Mov move(Player player, Level level) {
|
||||
Res_Mov
|
||||
move(Player player, Level level)
|
||||
{
|
||||
/* move the player */
|
||||
Vec2 moved = {0, 0};
|
||||
|
||||
if(player.spd.x == 0 && player.spd.y == 0) {return (Res_Mov){player, moved};}
|
||||
|
||||
if (player.spd.x == 0 && player.spd.y == 0) {
|
||||
return (Res_Mov){player, moved};
|
||||
}
|
||||
|
||||
int Ispd_x = player.spd.x;
|
||||
player.pos.x += Ispd_x;
|
||||
if(collide(player.pos, 0, 1, level)) {
|
||||
if (collide(player.pos, 0, 1, level)) {
|
||||
float sign_x = sign(player.spd.x);
|
||||
while(collide(player.pos, 0, 1, level) == 1) {
|
||||
while (collide(player.pos, 0, 1, level) == 1) {
|
||||
player.pos.x -= sign_x;
|
||||
}
|
||||
moved.x = 1;
|
||||
|
@ -95,9 +122,9 @@ Res_Mov move(Player player, Level level) {
|
|||
|
||||
int Ispd_y = player.spd.y;
|
||||
player.pos.y += Ispd_y;
|
||||
if(collide(player.pos, 0, 1, level)) {
|
||||
if (collide(player.pos, 0, 1, level)) {
|
||||
float sign_y = sign(player.spd.y);
|
||||
while(collide(player.pos, 0, 1, level) == 1) {
|
||||
while (collide(player.pos, 0, 1, level) == 1) {
|
||||
player.pos.y -= sign_y;
|
||||
}
|
||||
moved.y = 1;
|
||||
|
@ -105,7 +132,9 @@ Res_Mov move(Player player, Level level) {
|
|||
return (Res_Mov){player, moved};
|
||||
}
|
||||
|
||||
Player player_reset(Player player, Level level) {
|
||||
Player
|
||||
player_reset(Player player, Level level)
|
||||
{
|
||||
/* reset the level */
|
||||
player.spawn = search(52, level);
|
||||
player.pos = player.spawn;
|
||||
|
|
Loading…
Reference in New Issue