Skip to content

Commit

Permalink
sloppy menu load
Browse files Browse the repository at this point in the history
  • Loading branch information
computermouth committed Nov 5, 2023
1 parent b865034 commit 5083162
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 8 deletions.
2 changes: 1 addition & 1 deletion c1k3-assets
5 changes: 5 additions & 0 deletions data.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const uint32_t data_sfx_shotgun_shoot_len = audio_sfx_shotgun_shoot_ogg_len;
const uint8_t * data_song = audio_song_ogg;
const uint32_t data_song_len = audio_song_ogg_len;

#include "menu.h"

const uint8_t * data_menu = blend_menu_map;
const uint32_t data_menu_len = blend_menu_map_len;

#include "map1.h"

const uint8_t * data_map1 = blend_map1_map;
Expand Down
3 changes: 3 additions & 0 deletions data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <stdint.h>

extern const uint8_t * data_menu;
extern const uint32_t data_menu_len;

extern const uint8_t * data_map1;
extern const uint32_t data_map1_len;

Expand Down
1 change: 1 addition & 0 deletions entity_demon.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
#include "entity.h"

void entity_demon_constructor(entity_t *e);
void entity_demon_update(entity_t * e);

#endif
4 changes: 2 additions & 2 deletions game.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ void game_init(int map_index) {
game_entities_list_enemies = vector_init(sizeof(entity_t *));

game_map_index = map_index;
map_t * map = vector_at(map_data, game_map_index);
map_load(map);
map_set_level(game_map_index);
map_load();

// make sure that first frame won't have
// massive ticks, and also not divide by 0's
Expand Down
45 changes: 43 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

#include "audio.h"
#include "data.h"
#include "entity.h"
#include "input.h"
#include "render.h"
#include "map.h"
#include "model.h"
#include "game.h"
#include "text.h"
#include "vector.h"
#include "entity_demon.h"

void game_load() {
// text has to come before render init
Expand Down Expand Up @@ -49,29 +51,64 @@ void game_load() {

text_surface_t * c1k3 = NULL;
text_surface_t * dq = NULL;
text_surface_t * dennis = NULL;
entity_t * demon = NULL;

void menu_init(){
// set level to menu
map_set_level(2);

entity_params_t d = {
.id = ENTITY_ID_DEMON,
.position = vec3(0,-12,-18),
.entity_generic_params.ref_entt = map_ref_entt_from_eid(ENTITY_ID_DEMON),
};
demon = calloc(sizeof(entity_t), 1);
demon->_params = &d;
demon->_yaw = PI * 36.0f/40.0f;
entity_demon_constructor(demon);
}

void menu_run(float time_now) {

if (!c1k3) {
c1k3 = text_create_surface((font_input_t) {
.text = "C1K3",
.color = { .r = 255, .g = 255, .b = 255, .a = 255 },
.size = FONT_LG
.size = FONT_MD
});
c1k3->x = INTERNAL_W / 2 - c1k3->w / 2;
c1k3->y = INTERNAL_H / 2 - c1k3->h / 2;

dq = text_create_surface((font_input_t) {
.text = "-- dequake fps --",
.text = "dequake fps",
.color = { .r = 200, .g = 200, .b = 200, .a = 200 },
.size = FONT_SM
});
dq->x = INTERNAL_W / 2 - dq->w / 2;
dq->y = INTERNAL_H / 2 + dq->h;

dennis = text_create_surface((font_input_t) {
.text = "-- DENNIS FPS --",
.color = { .r = 200, .g = 16, .b = 16, .a = 255 },
.size = FONT_LG
});
dennis->x = INTERNAL_W / 2 - dennis->w / 2;
dennis->y = INTERNAL_H / 2 - dennis->h / 2 + 20;
}

time_now *= 0.001f;
game_tick = (time_now - game_time);
if (game_tick <= 0.001f)
game_tick = 0.001f;
game_time = time_now;

demon->_yaw += PI * sinf(game_time / 4)/40.f * game_tick;

r_prepare_frame(0.0f, 0.0f, 0.0f);

entity_demon_update(demon);

// ref_entt_t * re = map_ref_entt_from_eid(ENTITY_ID_TORCH);
// uint32_t * uframes = vector_begin(re->frames);
// r_draw((draw_call_t) {
Expand Down Expand Up @@ -101,6 +138,7 @@ void menu_run(float time_now) {

text_push_surface(c1k3);
text_push_surface(dq);
text_push_surface(dennis);

r_end_frame();

Expand Down Expand Up @@ -161,6 +199,9 @@ int main(int argc, char* argv[]) {

game_load();

// load menu assets
menu_init();

time(&t);
int oldtime = t;
int newtime;
Expand Down
12 changes: 10 additions & 2 deletions map.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,20 @@ void map_parse() {
// todo, be smarter
mpack_map_parse((char *)data_map1, data_map1_len);
mpack_map_parse((char *)data_map3, data_map3_len);

// todo, be smarter
// load menu assets
mpack_map_parse((char *)data_menu, data_menu_len);
}

void map_load (map_t * m) {
// todo, should this just be an index into a global map_collection_t?
void map_set_level(size_t i){
map_t * m = vector_at(map_data, i);
map = m;
}

void map_load () {

// loads from global map_t * map;
for (uint32_t i = 0; i < map->e_size; i++) {
entity_params_t * ref_ep = vector_at(map->map_entities, i);
entity_params_t ep = *ref_ep;
Expand Down
3 changes: 2 additions & 1 deletion map.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ extern vector * map_data;

void map_init();
void map_parse();
void map_load (map_t * m);
void map_set_level(size_t i);
void map_load ();
uint8_t map_block_at(int32_t x, int32_t y, int32_t z);
int map_block_at_box(vec3_t box_start, vec3_t box_end);
void map_draw();
Expand Down

0 comments on commit 5083162

Please sign in to comment.