Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mis #1

Merged
merged 55 commits into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
cb8fe58
added update coordinates point
glitchcore Oct 3, 2020
cca6b60
player animation
glitchcore Oct 3, 2020
9b77682
merge
glitchcore Oct 3, 2020
1d6e790
add anim
glitchcore Oct 3, 2020
e32aa1b
combo panel
glitchcore Oct 3, 2020
820c55e
label go
glitchcore Oct 3, 2020
7fdf1ad
combo panel input
glitchcore Oct 3, 2020
5a13cad
fix updating text
glitchcore Oct 3, 2020
1e95b0a
add example box
glitchcore Oct 3, 2020
d506036
add vec2
glitchcore Oct 3, 2020
46d49ef
add debug led
glitchcore Oct 3, 2020
515e0e1
add narrative
glitchcore Oct 4, 2020
7471b45
kind of refactoring
glitchcore Oct 4, 2020
3a7bf6b
proper height map
glitchcore Oct 4, 2020
45b12d7
bot instruction
glitchcore Oct 4, 2020
2a76f08
update game state
glitchcore Oct 4, 2020
77c230c
floor fix
glitchcore Oct 4, 2020
5d9fc94
wip
glitchcore Oct 4, 2020
44a8e2e
fix min
glitchcore Oct 4, 2020
f99e0e4
Merge branch 'mis' into sa
glitchcore Oct 4, 2020
3ff552e
change label to OMG
glitchcore Oct 4, 2020
4b57ecf
extract player.c
glitchcore Oct 4, 2020
b907919
split
glitchcore Oct 4, 2020
4a3a99a
cp item
glitchcore Oct 4, 2020
cc2cdb0
glitchy
glitchcore Oct 4, 2020
e501ccb
fix
glitchcore Oct 4, 2020
8777670
Merge branch 'mis' into sa
glitchcore Oct 4, 2020
ddafa13
Merge branch 'sa' into mis
glitchcore Oct 4, 2020
4df9923
is_bondaries
glitchcore Oct 4, 2020
43528a7
Merge branch 'mis' of github.com:glitchcore/floopper-bloopper into mis
glitchcore Oct 4, 2020
666d83f
is_bondaries 2
glitchcore Oct 4, 2020
a59ed47
game stages
glitchcore Oct 4, 2020
533b68e
is_bondaries 3
glitchcore Oct 4, 2020
780aabe
Merge branch 'mis' into sa
glitchcore Oct 4, 2020
fd58440
add progress
glitchcore Oct 4, 2020
d77d1dc
wip
glitchcore Oct 4, 2020
37085da
some changes
glitchcore Oct 4, 2020
6043d86
add progress 2
glitchcore Oct 4, 2020
5f7cfb0
test boundaries
glitchcore Oct 4, 2020
46081dd
fix combo
glitchcore Oct 4, 2020
05465df
initial speed
glitchcore Oct 4, 2020
01423d4
Merge branch 'mis' into sa
glitchcore Oct 4, 2020
c11ea4e
add progress gliphs
glitchcore Oct 4, 2020
0896e6c
ok
glitchcore Oct 4, 2020
729c648
fix combo panel
glitchcore Oct 4, 2020
47edcf2
Merge branch 'sa' into mis
glitchcore Oct 4, 2020
eb964e5
combo
glitchcore Oct 4, 2020
6656d78
Merge branch 'mis' of github.com:glitchcore/floopper-bloopper into mis
glitchcore Oct 4, 2020
c852267
add combo
glitchcore Oct 4, 2020
8ed804c
wip
glitchcore Oct 4, 2020
171095d
Merge branch 'mis' of github.com:glitchcore/floopper-bloopper into mis
glitchcore Oct 4, 2020
dde3d04
fix literal
glitchcore Oct 4, 2020
5cc9a6c
fix combo label
glitchcore Oct 4, 2020
7933ecd
combo description
glitchcore Oct 4, 2020
425e70b
Merge branch 'sa' into mis
glitchcore Oct 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 162 additions & 43 deletions floopper-bloopper.c
Original file line number Diff line number Diff line change
@@ -1,35 +1,150 @@
#include "flipper.h"
#include "u8g2/u8g2.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "floopper-bloopper/floopper-bloopper.h"

void render_graphics(GameState* state, u8g2_t* fb) {
#define MAX_LINES 4

typedef struct {
size_t line_size;
char* lines[MAX_LINES];
} TextBlock;

// narrative
const TextBlock NARRATIVE[] = {
{3, {"Welcome to Game!", "Use < > to move", "Use ^ to jump"}},
{3, {"OMG, it's happened", "again! Wait, I try", "to help you..."}},
{1, {"Please, return back"}},
{3, {"No, you dawn into", "cycle deeply!", " Go back"}},
{2, {"Okay, you stuck...", "try to press jump"}},
{1, {"...then left"}},
{1, {"...then right"}},
{1, {"...left again"}},
{3, {"Damn, it worked", "before. I need to", "read manual"}},
{2, {"Hey! I found", "something helpful!"}},
{3, {"You need to activate", "DCMPA 0x3A77 trigger", "u know what it is?"}},
{3, {"Maybe some part of", "the earth looks", "special"}},
{1, {"Try to jump over it"}},
{1, {"Jump here!"}},
{1, {"No, not here..."}}
};

const int32_t HEIGHT_MAP[WORLD_WIDTH] = {
5000, 5200, 5400, 5600, 5800, 6000, 6200, 6400, 6600, 6800, 7000, 7200, 7400, 7600, 7800, 8000,
8200, 8400, 8600, 8800, 9000, 9200, 9400, 9600, 9800, 10000, 10200, 10400, 10600, 10800, 11000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 4500, 4000, 3500, 3000, 2500, 2000, 1500, 1000, 500, 0, -500, -1000, -2000, -3000, -4000,
-5000, -5000, -5000, -5000, -5000, -5000, -5000, -5000, -5000, -5000, -5000, -5000, -5000, -5000, -5000, -5000,
-4000, -3000, -2500, -2000, -1500, -500, 0, 500, 1200, 1800, 2500, 3000, 3500, 4000, 4500, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000,
};

#include "floopper-bloopper/player.c"
#include "floopper-bloopper/world.c"
#include "floopper-bloopper/game.c"

typedef enum {
ComboInputUp = 0,
ComboInputDown,
ComboInputRight,
ComboInputLeft,
ComboInputEmpty,
} ComboInput;
ComboInput combo[COMBO_LENGTH];

ComboInput COMBO_PATTERNS[PATTERN_LENGTH][COMBO_LENGTH] = {
{ComboInputLeft, ComboInputRight, ComboInputRight, ComboInputDown, ComboInputEmpty, ComboInputEmpty, ComboInputEmpty, ComboInputEmpty}, //text combo <>>!
{ComboInputLeft, ComboInputDown, ComboInputRight, ComboInputDown, ComboInputDown, ComboInputEmpty, ComboInputEmpty, ComboInputEmpty}, //text combo off <!>!!
{ComboInputLeft, ComboInputUp, ComboInputRight, ComboInputDown, ComboInputEmpty, ComboInputEmpty, ComboInputEmpty, ComboInputEmpty},
};

void render_ui(GameState* state, u8g2_t* fb);

void render_graphics(GameState* state, u8g2_t* fb, uint32_t t) {
u8g2_ClearBuffer(fb);

render_ui(state, fb);
render_world(state, fb);
render_world(state, fb, t);
render_player(state, fb);
render_game_state(state, fb);
render_ui(state, fb);
}

void render_player(GameState* state, u8g2_t* fb) {
if (state->player_x < BONDARIES_X_LEFT * SCALE) {
state->player_x = BONDARIES_X_LEFT * SCALE;
} else if (state->player_x > (BONDARIES_X_RIGHT - PLAYER_WIDTH) * SCALE) {
state-> player_x = (BONDARIES_X_RIGHT - PLAYER_WIDTH) * SCALE;
}
void render_ui(GameState* state, u8g2_t* fb) {
if(state->combo_panel_activated) {
u8g2_SetDrawColor(fb, 0);
//combo box background
u8g2_DrawBox(fb, CP_POSITION_X, CP_POSITION_Y, (SCREEN_WIDTH) - CP_POSITION_X * 2, CP_HEIGHT);
u8g2_SetDrawColor(fb, 1);
//progress
u8g2_DrawBox(fb,
CP_POSITION_X,
CP_POSITION_Y - CP_PROGRESS_HEIGHT,
(SCREEN_WIDTH - CP_POSITION_X * 2) * state->combo_progress / ( 100 * SCALE ),
CP_PROGRESS_HEIGHT);
//combo box frame
u8g2_DrawFrame(fb,
CP_POSITION_X,
CP_POSITION_Y,
SCREEN_WIDTH - CP_POSITION_X * 2,
CP_HEIGHT);

u8g2_DrawBox(fb, state->player_x / SCALE, state->player_y / SCALE, PLAYER_WIDTH, PLAYER_HEIGHT);
//combo items
u8g2_SetFont(fb, u8g2_font_unifont_t_symbols);
for(size_t i = 0; i < state->combo_panel_cnt; i++) {
uint16_t item_x = CP_POSITION_X + CP_ITEM_WIDTH + (CP_ITEM_WIDTH + CP_ITEM_SPACE) * i;
uint16_t item_y = CP_POSITION_Y + (CP_HEIGHT + CP_ITEM_HEIGHT) / 2;
switch(combo[i]) {
case ComboInputUp:
u8g2_DrawGlyph(fb, item_x, item_y, 9206);
break;
case ComboInputDown:
u8g2_DrawGlyph(fb, item_x, item_y, 9207);
break;
case ComboInputRight:
u8g2_DrawGlyph(fb, item_x, item_y, 9205);
break;
case ComboInputLeft:
u8g2_DrawGlyph(fb, item_x, item_y, 9204);
break;
default: break;
}
}
}
}

void render_world(GameState* state, u8g2_t* fb) {
u8g2_DrawBox(fb, 0, SCREEN_HEIGHT - 4, SCREEN_WIDTH, 4);

void hadle_combo_input(GameState* state, InputEvent* input) {
if(input->state) {
combo[state->combo_panel_cnt] = input->input;
state->combo_progress = 100 * SCALE;
state->combo_panel_cnt += 1;
state->combo_speed = ((SCREEN_WIDTH - CP_POSITION_X * 2) * 1000 * state->combo_panel_cnt) / COMBO_TIME;
}
}

void render_ui(GameState* state, u8g2_t* fb) {
u8g2_SetFont(fb, u8g2_font_6x10_mf);
u8g2_SetDrawColor(fb, 1);
u8g2_SetFontMode(fb, 1);
u8g2_DrawStr(fb, 2, 12, "Floopper bloopper!");
void update_combo_process(GameState* state, uint32_t dt) {
if(state->combo_panel_activated && (state->combo_progress > 0)) {
state->combo_progress -= state->combo_speed * dt;
} else {
state->combo_panel_activated = false;
if(!memcmp(COMBO_PATTERNS[0], combo, COMBO_LENGTH)) {
state->combo_text = true;
} else if(!memcmp(COMBO_PATTERNS[1], combo, COMBO_LENGTH)) {
state->combo_text = false;
}
}
}

void handle_key(GameState* state, InputEvent* input) {
Expand All @@ -39,41 +154,45 @@ void handle_key(GameState* state, InputEvent* input) {
input->state ? "pressed" : "released"
);

if(input->state) {
if (input->input == InputRight) {
state->player_vx = SPEED_X;
} else if (input->input == InputLeft) {
state->player_vx = -SPEED_X;
}
if(state->combo_panel_activated) {
hadle_combo_input(state, input);
} else {
if (input->input == InputRight || input->input == InputLeft) {
state->player_vx = 0;
handle_player_input(state, input);
}

if(input->input == InputDown) {
if(input->state) {
//for tests
if(state->in_boundaries){
state->in_boundaries = false;
} else {
state->in_boundaries = true;
}
}
}

if(input->input == InputUp) {

if(input->input == InputOk) {
if(input->state) {
state->player_jump = true;
if(!state->combo_panel_activated) {
state->combo_panel_cnt = 0;
state->combo_panel_activated = true;
state->combo_progress = 100 * SCALE;
state->combo_speed = ((SCREEN_WIDTH - CP_POSITION_X * 2) * 1000 * 0.5) / COMBO_TIME;
for(size_t i = 0; i < COMBO_LENGTH; i++){
combo[i] = ComboInputEmpty;
}
} else {
state->combo_panel_activated = false;
}
}
}
}

void handle_tick(GameState* state, uint32_t t, uint32_t dt) {
// printf("t: %d, dt: %d\n", t, dt);

// gravity
if(state->player_jump) {
state->player_y -= 1 * SCALE;
state->player_vy = -60;
state->player_jump = false;
} else {
if(state->player_y > ((SCREEN_HEIGHT - 5 - PLAYER_HEIGHT) * SCALE)) {
state->player_vy = 0;
} else {
state->player_vy += 5;
}
}

state->player_x += state->player_vx * dt;
state->player_y += state->player_vy * dt;
}
update_player_coordinates(state, dt);
update_game_state(state, t, dt);
update_combo_process(state, dt);
}
85 changes: 77 additions & 8 deletions floopper-bloopper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,89 @@
#include "u8g2/u8g2.h"

typedef struct {
int32_t player_x;
int32_t player_y;
int32_t player_vx;
int32_t player_vy;
int32_t x;
int32_t y;
} Vec2;

typedef struct {
Vec2 player;
Vec2 player_global;
Vec2 player_v;

Vec2 screen;

bool in_boundaries;
bool player_jump;
uint8_t player_anim;
GpioPin* green;

bool combo_panel_activated;
uint8_t combo_panel_cnt;
int32_t combo_progress;
uint32_t combo_speed;

size_t label_id;
uint8_t glitch_level;
uint32_t glitch_t;

int32_t player_odo;
uint32_t player_t;

bool combo_text;
} GameState;

// global
#define SCALE 1024

// screen
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define BONDARIES_X_LEFT 20
#define BONDARIES_X_RIGHT 108

#define PLAYER_WIDTH 6
#define PLAYER_HEIGHT 6
#define SCALE 1000
#define SPEED_X 50

// player
#define PLAYER_WIDTH 9
#define PLAYER_HEIGHT 12
#define SPEED_X 40
#define JUMP_SPEED -100

// world
#define WORLD_WIDTH 256
#define WORLD_HEIGHT 64

#define LABEL_X 30 * SCALE
#define LABEL_Y 12 * SCALE
#define LABEL_HEIGHT 8 * SCALE

#define TEST_BOX_SIZE 6

enum {
WELCOME,
OMG,
OMG_HELP,
WRONG,
STUCK,
HELP_1,
HELP_2,
HELP_3,
DAMN,
MANUAL_FOUND,
MANUAL,
TIP_0,
TIP_1,
TIP_HERE,
TIP_NO_HERE,
};

//combo
#define CP_POSITION_X 10
#define CP_POSITION_Y 20
#define CP_HEIGHT 20
#define CP_ITEM_WIDTH 8
#define CP_ITEM_HEIGHT 12
#define CP_ITEM_SPACE 5
#define CP_PROGRESS_HEIGHT 3
#define COMBO_TIME 1000
#define COMBO_LENGTH 8
#define PATTERN_LENGTH 3
Loading