multiple levels
This commit is contained in:
parent
0018a0a451
commit
e1d8a89e8c
19
include/level/level2.data.h
Normal file
19
include/level/level2.data.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_src_level_level2_data_start __asm("_binary_src_level_level2_data_start");
|
||||
extern uint32_t _binary_src_level_level2_data_end __asm("_binary_src_level_level2_data_end");
|
||||
extern uint32_t _binary_src_level_level2_data_size __asm("_binary_src_level_level2_data_size");
|
||||
|
||||
#define src_level_level2_data_start ((const char *)&_binary_src_level_level2_data_start)
|
||||
#define src_level_level2_data_end ((const char *)&_binary_src_level_level2_data_end)
|
||||
#define src_level_level2_data_size (src_level_level2_data_end - src_level_level2_data_start)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
19
include/level/level2.data.pal.h
Normal file
19
include/level/level2.data.pal.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_src_level_level2_data_pal_start __asm("_binary_src_level_level2_data_pal_start");
|
||||
extern uint32_t _binary_src_level_level2_data_pal_end __asm("_binary_src_level_level2_data_pal_end");
|
||||
extern uint32_t _binary_src_level_level2_data_pal_size __asm("_binary_src_level_level2_data_pal_size");
|
||||
|
||||
#define src_level_level2_data_pal_start ((const char *)&_binary_src_level_level2_data_pal_start)
|
||||
#define src_level_level2_data_pal_end ((const char *)&_binary_src_level_level2_data_pal_end)
|
||||
#define src_level_level2_data_pal_size (src_level_level2_data_pal_end - src_level_level2_data_pal_start)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
19
include/level/level3.data.h
Normal file
19
include/level/level3.data.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_src_level_level3_data_start __asm("_binary_src_level_level3_data_start");
|
||||
extern uint32_t _binary_src_level_level3_data_end __asm("_binary_src_level_level3_data_end");
|
||||
extern uint32_t _binary_src_level_level3_data_size __asm("_binary_src_level_level3_data_size");
|
||||
|
||||
#define src_level_level3_data_start ((const char *)&_binary_src_level_level3_data_start)
|
||||
#define src_level_level3_data_end ((const char *)&_binary_src_level_level3_data_end)
|
||||
#define src_level_level3_data_size (src_level_level3_data_end - src_level_level3_data_start)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
19
include/level/level3.data.pal.h
Normal file
19
include/level/level3.data.pal.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_src_level_level3_data_pal_start __asm("_binary_src_level_level3_data_pal_start");
|
||||
extern uint32_t _binary_src_level_level3_data_pal_end __asm("_binary_src_level_level3_data_pal_end");
|
||||
extern uint32_t _binary_src_level_level3_data_pal_size __asm("_binary_src_level_level3_data_pal_size");
|
||||
|
||||
#define src_level_level3_data_pal_start ((const char *)&_binary_src_level_level3_data_pal_start)
|
||||
#define src_level_level3_data_pal_end ((const char *)&_binary_src_level_level3_data_pal_end)
|
||||
#define src_level_level3_data_pal_size (src_level_level3_data_pal_end - src_level_level3_data_pal_start)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
19
include/level/level4.data.h
Normal file
19
include/level/level4.data.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_src_level_level4_data_start __asm("_binary_src_level_level4_data_start");
|
||||
extern uint32_t _binary_src_level_level4_data_end __asm("_binary_src_level_level4_data_end");
|
||||
extern uint32_t _binary_src_level_level4_data_size __asm("_binary_src_level_level4_data_size");
|
||||
|
||||
#define src_level_level4_data_start ((const char *)&_binary_src_level_level4_data_start)
|
||||
#define src_level_level4_data_end ((const char *)&_binary_src_level_level4_data_end)
|
||||
#define src_level_level4_data_size (src_level_level4_data_end - src_level_level4_data_start)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
19
include/level/level4.data.pal.h
Normal file
19
include/level/level4.data.pal.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_src_level_level4_data_pal_start __asm("_binary_src_level_level4_data_pal_start");
|
||||
extern uint32_t _binary_src_level_level4_data_pal_end __asm("_binary_src_level_level4_data_pal_end");
|
||||
extern uint32_t _binary_src_level_level4_data_pal_size __asm("_binary_src_level_level4_data_pal_size");
|
||||
|
||||
#define src_level_level4_data_pal_start ((const char *)&_binary_src_level_level4_data_pal_start)
|
||||
#define src_level_level4_data_pal_end ((const char *)&_binary_src_level_level4_data_pal_end)
|
||||
#define src_level_level4_data_pal_size (src_level_level4_data_pal_end - src_level_level4_data_pal_start)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
19
include/level/level5.data.h
Normal file
19
include/level/level5.data.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_src_level_level5_data_start __asm("_binary_src_level_level5_data_start");
|
||||
extern uint32_t _binary_src_level_level5_data_end __asm("_binary_src_level_level5_data_end");
|
||||
extern uint32_t _binary_src_level_level5_data_size __asm("_binary_src_level_level5_data_size");
|
||||
|
||||
#define src_level_level5_data_start ((const char *)&_binary_src_level_level5_data_start)
|
||||
#define src_level_level5_data_end ((const char *)&_binary_src_level_level5_data_end)
|
||||
#define src_level_level5_data_size (src_level_level5_data_end - src_level_level5_data_start)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
19
include/level/level5.data.pal.h
Normal file
19
include/level/level5.data.pal.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern uint32_t _binary_src_level_level5_data_pal_start __asm("_binary_src_level_level5_data_pal_start");
|
||||
extern uint32_t _binary_src_level_level5_data_pal_end __asm("_binary_src_level_level5_data_pal_end");
|
||||
extern uint32_t _binary_src_level_level5_data_pal_size __asm("_binary_src_level_level5_data_pal_size");
|
||||
|
||||
#define src_level_level5_data_pal_start ((const char *)&_binary_src_level_level5_data_pal_start)
|
||||
#define src_level_level5_data_pal_end ((const char *)&_binary_src_level_level5_data_pal_end)
|
||||
#define src_level_level5_data_pal_size (src_level_level5_data_pal_end - src_level_level5_data_pal_start)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -22,6 +22,7 @@ extern "C" {
|
||||
|
||||
struct game_state {
|
||||
struct block_state blocks[28 * 13];
|
||||
int level_ix;
|
||||
const uint8_t * level;
|
||||
const uint8_t * pal;
|
||||
|
||||
@ -34,6 +35,8 @@ extern "C" {
|
||||
double start_time;
|
||||
double time;
|
||||
double remaining;
|
||||
|
||||
bool intro_shown;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -7,6 +7,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void launch_ball(struct game_state * state, double time);
|
||||
void reset_game(struct game_state * state);
|
||||
void reset_level(struct game_state * state);
|
||||
void update(struct game_state * state, double time);
|
||||
|
||||
|
||||
BIN
src/level/level2.data
Normal file
BIN
src/level/level2.data
Normal file
Binary file not shown.
BIN
src/level/level2.data.pal
Normal file
BIN
src/level/level2.data.pal
Normal file
Binary file not shown.
BIN
src/level/level2.png
Normal file
BIN
src/level/level2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 624 B |
BIN
src/level/level3.data
Normal file
BIN
src/level/level3.data
Normal file
Binary file not shown.
BIN
src/level/level3.data.pal
Normal file
BIN
src/level/level3.data.pal
Normal file
Binary file not shown.
BIN
src/level/level3.png
Normal file
BIN
src/level/level3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 608 B |
BIN
src/level/level4.data
Normal file
BIN
src/level/level4.data
Normal file
Binary file not shown.
BIN
src/level/level4.data.pal
Normal file
BIN
src/level/level4.data.pal
Normal file
Binary file not shown.
BIN
src/level/level4.png
Normal file
BIN
src/level/level4.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 644 B |
BIN
src/level/level5.data
Normal file
BIN
src/level/level5.data
Normal file
Binary file not shown.
BIN
src/level/level5.data.pal
Normal file
BIN
src/level/level5.data.pal
Normal file
Binary file not shown.
BIN
src/level/level5.png
Normal file
BIN
src/level/level5.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 656 B |
@ -147,7 +147,6 @@ int main()
|
||||
uint uniform_normal_trans = glGetUniformLocation(program, "normal_trans");
|
||||
uint uniform_base_color = glGetUniformLocation(program, "base_color");
|
||||
uint uniform_light_pos = glGetUniformLocation(program, "light_pos");
|
||||
printf("attrib_t %d\n", attrib_texture);
|
||||
|
||||
// font
|
||||
|
||||
@ -162,7 +161,6 @@ int main()
|
||||
uint font__uniform_texture0 = glGetUniformLocation(font_program, "texture0");
|
||||
uint font__uniform_base_color = glGetUniformLocation(font_program, "base_color");
|
||||
uint font__uniform_time = glGetUniformLocation(font_program, "time");
|
||||
printf("attrib_t %d\n", font__attrib_texture);
|
||||
|
||||
// background
|
||||
|
||||
@ -211,7 +209,7 @@ int main()
|
||||
const char * last_gamepad_name = NULL;
|
||||
|
||||
struct game_state state = {0};
|
||||
reset_level(&state);
|
||||
reset_game(&state);
|
||||
state.start_time = glfwGetTime();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
@ -285,7 +285,7 @@ void render_text(struct mesh plane_mesh,
|
||||
|
||||
if (c != ' ') {
|
||||
mat4x4 char_t = translate(vec3(-2 * 16 + h_advance / 8.0f,
|
||||
-3.0f * aspect + -v_advance / 16.0f, 0));
|
||||
-8.0f * aspect + -v_advance / 16.0f, 0));
|
||||
mat4x4 trans = a * scale(12.0f / vp_height) * s * char_t * r;
|
||||
|
||||
mat4x4 texture_trans = char_tex_trans(c);
|
||||
@ -366,7 +366,7 @@ void render_font(struct mesh plane_mesh,
|
||||
};
|
||||
const int win_length = (sizeof (win)) / (sizeof (win[0]));
|
||||
|
||||
if (state->balls_launched == 0) {
|
||||
if (state->intro_shown == 0) {
|
||||
vec3 base_color = vec3(1, 1, 1);
|
||||
glUniform3fv(uniform_base_color, 1, &base_color[0]);
|
||||
render_text(plane_mesh,
|
||||
@ -377,7 +377,7 @@ void render_font(struct mesh plane_mesh,
|
||||
aspect,
|
||||
a, s, r);
|
||||
} else if (state->remaining <= 0) {
|
||||
if (1) {
|
||||
if (state->level_ix == 0) {
|
||||
vec3 base_color = vec3(1, 0.1, 0.1);
|
||||
glUniform3fv(uniform_base_color, 1, &base_color[0]);
|
||||
render_text(plane_mesh,
|
||||
|
||||
@ -9,6 +9,47 @@
|
||||
#include "level/level1.data.h"
|
||||
#include "level/level1.data.pal.h"
|
||||
|
||||
#include "level/level2.data.h"
|
||||
#include "level/level2.data.pal.h"
|
||||
|
||||
#include "level/level3.data.h"
|
||||
#include "level/level3.data.pal.h"
|
||||
|
||||
#include "level/level4.data.h"
|
||||
#include "level/level4.data.pal.h"
|
||||
|
||||
#include "level/level5.data.h"
|
||||
#include "level/level5.data.pal.h"
|
||||
|
||||
struct level {
|
||||
const char * data_start;
|
||||
const char * data_pal_start;
|
||||
};
|
||||
|
||||
const struct level levels[] = {
|
||||
{
|
||||
.data_start = src_level_level1_data_start,
|
||||
.data_pal_start = src_level_level1_data_pal_start,
|
||||
},
|
||||
{
|
||||
.data_start = src_level_level2_data_start,
|
||||
.data_pal_start = src_level_level2_data_pal_start,
|
||||
},
|
||||
{
|
||||
.data_start = src_level_level3_data_start,
|
||||
.data_pal_start = src_level_level3_data_pal_start,
|
||||
},
|
||||
{
|
||||
.data_start = src_level_level4_data_start,
|
||||
.data_pal_start = src_level_level4_data_pal_start,
|
||||
},
|
||||
{
|
||||
.data_start = src_level_level5_data_start,
|
||||
.data_pal_start = src_level_level5_data_pal_start,
|
||||
}
|
||||
};
|
||||
const int levels_length = (sizeof (levels)) * (sizeof (levels[0]));
|
||||
|
||||
#include "math/float_types.hpp"
|
||||
#include "math/transform.hpp"
|
||||
|
||||
@ -52,6 +93,7 @@ void launch_ball(struct game_state * state, double time)
|
||||
ball.launch_time = time;
|
||||
|
||||
state->balls_launched += 1;
|
||||
state->intro_shown = true;
|
||||
}
|
||||
|
||||
void reset_level(struct game_state * state)
|
||||
@ -61,9 +103,9 @@ void reset_level(struct game_state * state)
|
||||
|
||||
state->start_time = 0.0;
|
||||
|
||||
assert(src_level_level1_data_size == 13 * 28);
|
||||
const uint8_t * level = (const uint8_t *)src_level_level1_data_start;
|
||||
const uint8_t * pal = (const uint8_t *)src_level_level1_data_pal_start;
|
||||
//assert(src_level_level2_data_size == 13 * 28);
|
||||
const uint8_t * level = (const uint8_t *)levels[state->level_ix].data_start;
|
||||
const uint8_t * pal = (const uint8_t *)levels[state->level_ix].data_pal_start;
|
||||
|
||||
state->level = level;
|
||||
state->pal = pal;
|
||||
@ -72,6 +114,12 @@ void reset_level(struct game_state * state)
|
||||
}
|
||||
}
|
||||
|
||||
void reset_game(struct game_state * state)
|
||||
{
|
||||
state->level_ix = 0;
|
||||
reset_level(state);
|
||||
}
|
||||
|
||||
static inline void ball_collision_response(struct ball_state& ball,
|
||||
struct collision_data& cd)
|
||||
{
|
||||
@ -151,8 +199,31 @@ void update_ball(struct game_state * state, struct ball_state& ball, double time
|
||||
ball.ball_y += ball.ball_dy;
|
||||
}
|
||||
|
||||
void update_advance_level(struct game_state * state)
|
||||
{
|
||||
int block_count = 0;
|
||||
|
||||
for (int i = 0; i < 13 * 28; i++) {
|
||||
char tile = state->level[i];
|
||||
if (tile == 0)
|
||||
continue;
|
||||
if (state->blocks[i].destroyed_time != 0.0)
|
||||
continue;
|
||||
|
||||
block_count += 1;
|
||||
}
|
||||
|
||||
if (block_count < 10) {
|
||||
state->level_ix = (state->level_ix + 1) % levels_length;
|
||||
printf("next level %d\n", state->level_ix);
|
||||
reset_level(state);
|
||||
}
|
||||
}
|
||||
|
||||
void update(struct game_state * state, double time)
|
||||
{
|
||||
update_advance_level(state);
|
||||
|
||||
if (state->remaining >= 0.0) {
|
||||
for (int i = 0; i < state->balls_launched; i++) {
|
||||
if (state->balls[i].ball_y > 30.0f)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user