Skip to content

Commit

Permalink
Merge pull request #1 from glitchcore/mis
Browse files Browse the repository at this point in the history
Mis
  • Loading branch information
glitchcore authored Oct 4, 2020
2 parents 4f84e3c + 425e70b commit 5983419
Show file tree
Hide file tree
Showing 13 changed files with 627 additions and 57 deletions.
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

0 comments on commit 5983419

Please sign in to comment.