Change line limit from 72 to 80

Lot of files were messy because of the small limit
This commit is contained in:
KikooDX 2021-04-20 00:40:52 +02:00
parent 08b6741d88
commit fb0ded84f5
19 changed files with 104 additions and 159 deletions

View File

@ -4,5 +4,5 @@ UseTab: AlignWithSpaces
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 72
ColumnLimit: 80
AlignConsecutiveMacros: true

View File

@ -2,10 +2,4 @@
/* Copyright (C) 2021 KikooDX */
#pragma once
enum GameState {
TitleScreen,
MainMenu,
LevelSelection,
Playing,
PackDone
};
enum GameState { TitleScreen, MainMenu, LevelSelection, Playing, PackDone };

View File

@ -22,6 +22,5 @@ struct Particle {
void particles_init(void);
void particles_update(void);
void particles_draw(void);
void particle_create(bopti_image_t *texture, int x, int y,
int frame_width, int frame_duration,
int particles);
void particle_create(bopti_image_t *texture, int x, int y, int frame_width,
int frame_duration, int particles);

View File

@ -33,8 +33,7 @@ struct Player player_init(void);
void player_draw(struct Player player);
/* return 1 if exit reached, -1 on death/reset and 0 otherwise */
int player_update(struct Player *player, struct Input input);
void player_collide(Tile collisions[COLLIDE_POINTS], int x, int y,
int margin);
void player_collide(Tile collisions[COLLIDE_POINTS], int x, int y, int margin);
int player_collide_tile(Tile collisions[COLLIDE_POINTS], int x, int y,
Tile tile, int margin, int update);
int player_collide_solid(int x, int y);

View File

@ -10,6 +10,5 @@ struct TitleScreen {
struct TitleScreen titlescreen_init(void);
/* Return 1 if game state should change. */
int titlescreen_update(struct TitleScreen *titlescreen,
struct Input input);
int titlescreen_update(struct TitleScreen *titlescreen, struct Input input);
void titlescreen_draw(struct TitleScreen titlescreen);

View File

@ -7,8 +7,7 @@
struct Input input_init(void)
{
struct Input input = {
.keycodes = {KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN,
KEY_SHIFT},
.keycodes = {KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_SHIFT},
};
int i = KEYS_COUNT;
while (i-- > 0)

View File

@ -15,11 +15,10 @@ void level_draw(void)
i = level.height * level.width;
while (i-- > 0) {
const struct VisualTile *visual_tile =
&level.visual_data[i];
const struct VisualTile *visual_tile = &level.visual_data[i];
if (visual_tile->visible) {
dsubimage(visual_tile->x, visual_tile->y,
&bimg_tileset, visual_tile->texture_x,
dsubimage(visual_tile->x, visual_tile->y, &bimg_tileset,
visual_tile->texture_x,
visual_tile->texture_y, TILE_WIDTH,
TILE_HEIGHT, DIMAGE_NOCLIP);
}

View File

@ -9,11 +9,11 @@
#include <gint/std/stdlib.h>
#include <stdint.h>
#define assert(condition, error_msg) \
if (!(condition)) { \
fatal_error = -1; \
fatal_error_msg = error_msg; \
return; \
#define assert(condition, error_msg) \
if (!(condition)) { \
fatal_error = -1; \
fatal_error_msg = error_msg; \
return; \
}
/* globals are needed when using gint_switch() */
@ -52,8 +52,7 @@ void level_load(void)
/* get tile size (in bytes) */
tile_size = read_byte(file);
assert(tile_size >= 0, "can't read tile size");
assert((unsigned int)tile_size <= sizeof(Tile),
"tiles are too heavy");
assert((unsigned int)tile_size <= sizeof(Tile), "tiles are too heavy");
/* assert than width and height are correct */
level.width = read_merge_bytes(file, 2);
@ -105,24 +104,19 @@ void level_load(void)
visual_data.y = y * TILE_HEIGHT;
visual_data.visible = tile != TILE_START;
if (tile == TILE_SOLID) {
const int autotile =
autotile_value(x, y);
visual_data.texture_x =
autotile * TILE_WIDTH;
const int autotile = autotile_value(x, y);
visual_data.texture_x = autotile * TILE_WIDTH;
visual_data.texture_y = TILE_HEIGHT;
visual_data.visible = autotile != 15;
} else if (tile != TILE_VOID) {
visual_data.texture_x =
(int)(tile % TILESET_WIDTH) *
TILE_WIDTH;
(int)(tile % TILESET_WIDTH) * TILE_WIDTH;
visual_data.texture_y =
(int)(tile / TILESET_WIDTH) *
TILE_HEIGHT;
(int)(tile / TILESET_WIDTH) * TILE_HEIGHT;
} else {
visual_data.visible = 0;
}
level.visual_data[x + y * level.width] =
visual_data;
level.visual_data[x + y * level.width] = visual_data;
}
}

View File

@ -7,6 +7,5 @@
void levelselection_draw(struct LevelSelection levelselection)
{
dprint(0, 0, C_WHITE, ".pack_cursor=%d",
levelselection.pack_cursor);
dprint(0, 0, C_WHITE, ".pack_cursor=%d", levelselection.pack_cursor);
}

View File

@ -16,23 +16,22 @@
#include <gint/keyboard.h>
#include <gint/timer.h>
#define PANIC(msg) \
do { \
dclear(C_BLACK); \
dprint_opt(DWIDTH / 2, DHEIGHT / 2, C_RED, C_NONE, \
DTEXT_CENTER, DTEXT_MIDDLE, "ERROR: %s", \
msg); \
dupdate(); \
getkey(); \
return 0; \
#define PANIC(msg) \
do { \
dclear(C_BLACK); \
dprint_opt(DWIDTH / 2, DHEIGHT / 2, C_RED, C_NONE, \
DTEXT_CENTER, DTEXT_MIDDLE, "ERROR: %s", msg); \
dupdate(); \
getkey(); \
return 0; \
} while (0);
#define LOAD_LEVEL() \
do { \
gint_switch(level_load); \
if (fatal_error == -1) \
PANIC(fatal_error_msg); \
particles_init(); \
player = player_init(); \
#define LOAD_LEVEL() \
do { \
gint_switch(level_load); \
if (fatal_error == -1) \
PANIC(fatal_error_msg); \
particles_init(); \
player = player_init(); \
} while (0);
extern struct Level level;
@ -71,8 +70,8 @@ int main(void)
if (fatal_error == -1)
PANIC(fatal_error_msg);
/* timer setup */
timer = timer_setup(TIMER_ANY, 1000000 / TARGET_UPS, callback,
&has_ticked);
timer =
timer_setup(TIMER_ANY, 1000000 / TARGET_UPS, callback, &has_ticked);
if (timer == -1)
PANIC("timer_setup failed");
timer_start(timer);
@ -95,22 +94,20 @@ int main(void)
switch (game_state) {
case TitleScreen:
if (titlescreen_update(&titlescreen,
input))
if (titlescreen_update(&titlescreen, input))
game_state = MainMenu;
break;
case MainMenu:
game_state = LevelSelection;
break;
case LevelSelection:
if (levelselection_update(
&levelselection, input)) {
if (levelselection_update(&levelselection,
input)) {
game_state = Playing;
/* set level according to
* selected pack */
level_id =
levelselection.pack_cursor *
LVL_PER_PACK;
level_id = levelselection.pack_cursor *
LVL_PER_PACK;
LOAD_LEVEL();
}
break;
@ -118,23 +115,18 @@ int main(void)
if (transition.mode == TransitionNone) {
particles_update();
player_return_code =
player_update(&player,
input);
player_update(&player, input);
switch (player_return_code) {
case 1:
level_id += 1;
transition =
transition_init(
H_TRANS_SPD,
C_BLUE,
TransitionHOut);
transition = transition_init(
H_TRANS_SPD, C_BLUE,
TransitionHOut);
break;
case -1:
transition =
transition_init(
V_TRANS_SPD,
C_RED,
TransitionVOut);
transition = transition_init(
V_TRANS_SPD, C_RED,
TransitionVOut);
break;
default:
break;
@ -147,8 +139,7 @@ int main(void)
transition.mode &&
transition_previous_mode !=
TransitionNone) {
switch (
transition_previous_mode) {
switch (transition_previous_mode) {
case TransitionNone:
break;
case TransitionHIn:
@ -156,32 +147,24 @@ int main(void)
case TransitionHOut:
/* end level pack */
if (level_id % 4 == 0) {
game_state =
PackDone;
game_state = PackDone;
level_pack_beaten =
level_id /
4;
level_id / 4;
}
LOAD_LEVEL();
transition =
transition_init(
transition
.speed,
transition
.color,
TransitionHIn);
transition = transition_init(
transition.speed,
transition.color,
TransitionHIn);
break;
case TransitionVIn:
break;
case TransitionVOut:
LOAD_LEVEL();
transition =
transition_init(
transition
.speed,
transition
.color,
TransitionVIn);
transition = transition_init(
transition.speed,
transition.color,
TransitionVIn);
break;
default:
break;
@ -192,8 +175,7 @@ int main(void)
game_state = LevelSelection;
break;
default:
PANIC(
"missing game_state case (update)");
PANIC("missing game_state case (update)");
break;
}
}

View File

@ -6,8 +6,8 @@
extern struct Particle particles[MAX_PARTICLES];
void particle_create(bopti_image_t *texture, int x, int y,
int frame_width, int frame_duration, int looping)
void particle_create(bopti_image_t *texture, int x, int y, int frame_width,
int frame_duration, int looping)
{
/* find unused slot */
int i = MAX_PARTICLES;
@ -23,8 +23,7 @@ void particle_create(bopti_image_t *texture, int x, int y,
particle->frame_height = texture->height;
particle->frame_duration = frame_duration;
particle->frame = 0;
particle->life_ini =
frame_duration * texture->width / frame_width;
particle->life_ini = frame_duration * texture->width / frame_width;
particle->life = particle->life_ini;
particle->looping = looping;
}

View File

@ -22,6 +22,5 @@ static void particle_draw(struct Particle particle)
dsubimage(particle.x, particle.y, particle.texture,
particle.frame * particle.frame_width, 0,
particle.frame_width, particle.frame_height,
DIMAGE_NOCLIP);
particle.frame_width, particle.frame_height, DIMAGE_NOCLIP);
}

View File

@ -19,8 +19,7 @@ extern bopti_image_t bimg_exit_unlock_particle;
static Tile collide_single(int x, int y);
static int collide_sub_single(int x, int y, Tile sub, Tile rep);
void player_collide(Tile collisions[COLLIDE_POINTS], int x, int y,
int margin)
void player_collide(Tile collisions[COLLIDE_POINTS], int x, int y, int margin)
{
const int lx = x + margin;
const int rx = x + PLAYER_WIDTH - 1 - margin;
@ -77,8 +76,7 @@ static int collide_sub_single(int x, int y, Tile sub, Tile rep)
{
if (collide_single(x, y) == sub) {
const int tile_index =
(int)(x / TILE_WIDTH) +
(int)(y / TILE_WIDTH) * level.width;
(int)(x / TILE_WIDTH) + (int)(y / TILE_WIDTH) * level.width;
const int px = (int)(x / TILE_WIDTH) * TILE_WIDTH;
const int py = (int)(y / TILE_HEIGHT) * TILE_HEIGHT;
@ -90,13 +88,13 @@ static int collide_sub_single(int x, int y, Tile sub, Tile rep)
/* spawn animations */
switch (sub) {
case TILE_GOLD:
particle_create(&bimg_coin_particle, px, py,
TILE_WIDTH, 2, 0);
particle_create(&bimg_coin_particle, px, py, TILE_WIDTH,
2, 0);
break;
case TILE_SWITCH:
/* still image */
particle_create(&bimg_switch_activated_particle,
px, py, TILE_WIDTH, 1, 1);
particle_create(&bimg_switch_activated_particle, px, py,
TILE_WIDTH, 1, 1);
/* activation animation */
particle_create(&bimg_switch_particle, px, py,
TILE_WIDTH, 8, 0);
@ -109,9 +107,7 @@ static int collide_sub_single(int x, int y, Tile sub, Tile rep)
while (tx-- > 0) {
if (level.data
[tx +
ty *
level
.width] ==
ty * level.width] ==
TILE_EXIT)
goto found;
}
@ -119,12 +115,10 @@ static int collide_sub_single(int x, int y, Tile sub, Tile rep)
found:
tx *= TILE_WIDTH;
ty *= TILE_HEIGHT;
particle_create(
&bimg_exit_active_particle, tx, ty,
TILE_WIDTH, 2, 1);
particle_create(
&bimg_exit_unlock_particle, tx, ty,
TILE_WIDTH, 4, 0);
particle_create(&bimg_exit_active_particle, tx,
ty, TILE_WIDTH, 2, 1);
particle_create(&bimg_exit_unlock_particle, tx,
ty, TILE_WIDTH, 4, 0);
}
break;
default:

View File

@ -15,8 +15,7 @@ extern bopti_image_t bimg_burst;
void player_draw(struct Player player)
{
dimage(player.x, player.y, &bimg_player);
if (player.air_state == AirRising &&
player.jumps_left < AIR_JUMPS)
if (player.air_state == AirRising && player.jumps_left < AIR_JUMPS)
dimage(player.x, player.y + PLAYER_HEIGHT, &bimg_burst);
/* print level name
* this shouldn't be in player code */

View File

@ -28,14 +28,12 @@ struct Player player_init(void)
while (x-- > 0) {
y = level.height;
while (y-- > 0) {
if (level.data[x + y * level.width] ==
TILE_START) {
if (level.data[x + y * level.width] == TILE_START) {
/* set player position */
player.x =
x * TILE_WIDTH +
(TILE_WIDTH - PLAYER_WIDTH) / 2;
player.y = y * TILE_HEIGHT +
TILE_HEIGHT - PLAYER_HEIGHT;
player.x = x * TILE_WIDTH +
(TILE_WIDTH - PLAYER_WIDTH) / 2;
player.y = y * TILE_HEIGHT + TILE_HEIGHT -
PLAYER_HEIGHT;
return player;
}
}

View File

@ -16,8 +16,7 @@ extern struct Level level;
int player_update(struct Player *player, struct Input input)
{
Tile collisions[COLLIDE_POINTS];
const int on_ground =
player_collide_solid(player->x, player->y + 1);
const int on_ground = player_collide_solid(player->x, player->y + 1);
/* process input */
const int k_left = input.keystates[K_LEFT] != KS_UP;
@ -52,13 +51,11 @@ int player_update(struct Player *player, struct Input input)
player->spd_y *= 1 - AIR_RES;
if (!on_ground) {
/* smooth jump apex */
const float abs_spd_y = (player->spd_y > 0.0)
? (player->spd_y)
: (-player->spd_y);
const float abs_spd_y =
(player->spd_y > 0.0) ? (player->spd_y) : (-player->spd_y);
float factor = 1.0;
if (abs_spd_y < 1.0)
factor =
0.5 + 0.5 * (player->spd_y * player->spd_y);
factor = 0.5 + 0.5 * (player->spd_y * player->spd_y);
if (player->air_state == AirBreaking)
factor *= AIR_BREAKING_FACTOR;
player->spd_y += GRAVITY * factor;
@ -108,23 +105,23 @@ int player_update(struct Player *player, struct Input input)
player_move(player, spd_x, 0);
/* get gold ($$$) */
level.gold -= player_collide_sub(
player->x, player->y, TILE_GOLD, TILE_VOID, MARGIN_GOLD);
level.gold -= player_collide_sub(player->x, player->y, TILE_GOLD,
TILE_VOID, MARGIN_GOLD);
/* unlock exit */
if (level.exit_locked &&
player_collide_sub(player->x, player->y, TILE_SWITCH,
TILE_VOID, MARGIN_SWITCH))
player_collide_sub(player->x, player->y, TILE_SWITCH, TILE_VOID,
MARGIN_SWITCH))
level.exit_locked = 0;
/* check for death and exit */
if (!level.exit_locked &&
player_collide_tile(collisions, player->x, player->y,
TILE_EXIT, 0, 1)) {
player_collide_tile(collisions, player->x, player->y, TILE_EXIT, 0,
1)) {
return 1;
}
if (player_collide_tile(collisions, player->x, player->y,
TILE_LETAL, MARGIN_LETAL, 1)) {
if (player_collide_tile(collisions, player->x, player->y, TILE_LETAL,
MARGIN_LETAL, 1)) {
return -1;
}
return 0;

View File

@ -7,11 +7,10 @@
void titlescreen_draw(struct TitleScreen titlescreen)
{
dprint_opt(DWIDTH / 2, DHEIGHT * 1 / 3, C_WHITE, C_NONE,
DTEXT_CENTER, DTEXT_MIDDLE, GAME_NAME);
dprint_opt(DWIDTH / 2, DHEIGHT * 2 / 3, C_WHITE, C_NONE,
DTEXT_CENTER, DTEXT_MIDDLE, "Press Shift");
dprint_opt(DWIDTH / 2, DHEIGHT - 2, C_WHITE, C_NONE,
DTEXT_CENTER, DTEXT_BOTTOM,
"Game by KikooDX (2021) - " VERSION);
dprint_opt(DWIDTH / 2, DHEIGHT * 1 / 3, C_WHITE, C_NONE, DTEXT_CENTER,
DTEXT_MIDDLE, GAME_NAME);
dprint_opt(DWIDTH / 2, DHEIGHT * 2 / 3, C_WHITE, C_NONE, DTEXT_CENTER,
DTEXT_MIDDLE, "Press Shift");
dprint_opt(DWIDTH / 2, DHEIGHT - 2, C_WHITE, C_NONE, DTEXT_CENTER,
DTEXT_BOTTOM, "Game by KikooDX (2021) - " VERSION);
}

View File

@ -3,7 +3,4 @@
#include "titlescreen.h"
struct TitleScreen titlescreen_init(void)
{
return (struct TitleScreen){0};
}
struct TitleScreen titlescreen_init(void) { return (struct TitleScreen){0}; }

View File

@ -6,8 +6,7 @@
#include <gint/keyboard.h>
/* Return 1 if game state should change. */
int titlescreen_update(struct TitleScreen *titlescreen,
struct Input input)
int titlescreen_update(struct TitleScreen *titlescreen, struct Input input)
{
if (input.keystates[K_A] == KS_PRESS) {
return 1;