Level pack selection

This commit is contained in:
KikooDX 2021-04-20 00:40:12 +02:00
parent 632c31a377
commit 08b6741d88
4 changed files with 29 additions and 5 deletions

View File

@ -9,6 +9,7 @@
#define TILESET_WIDTH 16
#define TARGET_FPS 30
#define TARGET_UPS 60
#define LVL_PER_PACK 4
#define ACC_GND 0.1
#define ACC_AIR 0.025
#define MAX_HSPD 3.0

View File

@ -7,11 +7,14 @@ printf '#pragma once\n'
printf '#include <stdint.h>\n\n'
printf 'static const uint16_t filepaths[][64] = {\n'
LEVEL_COUNT=0
cd assets/levels
for PACK in *; do
PACK_NAME="$(basename $PACK)"
cd "$PACK"
for LEVEL in *; do
LEVEL_COUNT="$(($LEVEL_COUNT + 1))"
LEVEL_NAME="$(basename $LEVEL | cut -c2- |
awk -F '.' '{print $1}' |
tr '[:lower:]' '[:upper:]')"
@ -25,6 +28,10 @@ for PACK in *; do
done
cd ..
done
printf '};\n'
printf '};\n\n'
printf 'static const char level_names[][32] = { %s\n};\n' "$LEVEL_NAMES"
printf 'static const char level_names[][32] = {%s\n};\n\n' "$LEVEL_NAMES"
[ "$(($LEVEL_COUNT % 4))" != 0 ] && LEVEL_COUNT="$(($LEVEL_COUNT + 4 - $LEVEL_COUNT % 4))"
printf '#define PACK_COUNT %s\n' "$(($LEVEL_COUNT / 4))"

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#include "filepaths.h"
#include "input.h"
#include "levelselection.h"
#include <gint/keyboard.h>
@ -9,9 +10,17 @@
int levelselection_update(struct LevelSelection *levelselection,
struct Input input)
{
if (input.keystates[K_A] == KS_PRESS) {
/* decrease selected pack id */
if (input.keystates[K_LEFT] == KS_PRESS &&
levelselection->pack_cursor > 0)
levelselection->pack_cursor -= 1;
/* increase selected pack id */
if (input.keystates[K_RIGHT] == KS_PRESS &&
levelselection->pack_cursor < PACK_COUNT - 1)
levelselection->pack_cursor += 1;
/* confirm */
if (input.keystates[K_A] == KS_PRESS)
return 1;
}
return 0;
}

View File

@ -104,8 +104,15 @@ int main(void)
break;
case LevelSelection:
if (levelselection_update(
&levelselection, input))
&levelselection, input)) {
game_state = Playing;
/* set level according to
* selected pack */
level_id =
levelselection.pack_cursor *
LVL_PER_PACK;
LOAD_LEVEL();
}
break;
case Playing:
if (transition.mode == TransitionNone) {