Add simple menu
parent
0e6a605b9a
commit
5b2027c57b
|
@ -143,6 +143,10 @@ void free_target_list(struct target_obj_node **HEAD);
|
|||
void add_target_node(struct target_obj *obj, struct target_obj_node **HEAD);
|
||||
bool collide_target(struct kinematic_obj *obj, struct target_obj *target);
|
||||
|
||||
//Menu
|
||||
void draw_menu();
|
||||
void main_menu_check();
|
||||
|
||||
//Debug stuff, debug.c
|
||||
void state_string(char *str, enum PLAYER_STATE state);
|
||||
void display_input(char *dir);
|
||||
|
|
45
main.c
45
main.c
|
@ -29,23 +29,52 @@ int PLAYER_ACCEL = 1500;
|
|||
int JUMP_ACCEL = 15000;
|
||||
int JUMP_SPD = 350;
|
||||
int GRAV = 1000;
|
||||
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
void main_menu(Camera2D camera);
|
||||
void play_test_level(Camera2D camera);
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
char current_state[20];
|
||||
char current_spd[50];
|
||||
//char dir[7];
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib");
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
|
||||
Camera2D camera = { 0 };
|
||||
camera.offset = (Vector2){0,0};
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
while (!WindowShouldClose())
|
||||
//play_test_level(camera);
|
||||
main_menu(camera);
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
}
|
||||
|
||||
|
||||
void main_menu(Camera2D camera){
|
||||
camera.target = (Vector2){0,0};
|
||||
|
||||
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
main_menu_check();
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
draw_menu();
|
||||
EndDrawing();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void play_test_level(Camera2D camera){
|
||||
|
||||
char current_state[20];
|
||||
char current_spd[50];
|
||||
|
||||
struct player_obj player = {
|
||||
.kinematic = init_kinematic_obj(PLAYER_SIZE, PLAYER_SIZE),
|
||||
|
@ -88,10 +117,9 @@ int main()
|
|||
set_position(&target.kinematic, 300, 100);
|
||||
add_target_node(&target, &target_HEAD);
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
while (!WindowShouldClose() || IsKeyPressed(KEY_Q)) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -145,8 +173,7 @@ int main()
|
|||
free_kinematic_list(&kinematic_HEAD);
|
||||
free_target_list(&target_HEAD);
|
||||
free_afterimages(&player);
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
#include "header.h"
|
||||
#include <raymath.h>
|
||||
|
||||
static unsigned int option = 0;
|
||||
|
||||
const unsigned int max_options = 2;
|
||||
const char menu_options[2][10] = {"Play", "Exit"};
|
||||
|
||||
Vector2 menu_list_pos = (Vector2){200,100};
|
||||
|
||||
Vector2 t1 = (Vector2){180, 100};
|
||||
Vector2 t2 = (Vector2){190, 105};
|
||||
Vector2 t3 = (Vector2){180, 110};
|
||||
Vector2 offset = (Vector2){0, 50};
|
||||
|
||||
|
||||
void main_menu_check(){
|
||||
if (IsKeyPressed(UP))
|
||||
--option;
|
||||
if (IsKeyPressed(DOWN))
|
||||
++option;
|
||||
}
|
||||
|
||||
void draw_menu(){
|
||||
DrawFPS(0,0);
|
||||
for(unsigned int i=0;i<2;++i){
|
||||
DrawText(menu_options[i], menu_list_pos.x,
|
||||
menu_list_pos.y + 50 * i, 12, BLACK);
|
||||
}
|
||||
//display_input(dir);
|
||||
//DrawText(dir, 0, 50, 12, BLACK);
|
||||
|
||||
// Triangles has to be anticlockwse, because z axis
|
||||
Vector2 off = Vector2Scale(offset, option);
|
||||
DrawTriangle(Vector2Add(t1, off), Vector2Add(t3, off), Vector2Add(t2, off), BLACK);
|
||||
}
|
Loading…
Reference in New Issue