This commit is contained in:
58
src/main.c
58
src/main.c
@@ -25,8 +25,22 @@ Made by Sem van der Hoeven
|
|||||||
#define SCREEN_WIDTH 960
|
#define SCREEN_WIDTH 960
|
||||||
#define SIMPLE_ENEMY_MAX_AMOUNT 20
|
#define SIMPLE_ENEMY_MAX_AMOUNT 20
|
||||||
#define ENEMY_MAX_AMOUNT 40
|
#define ENEMY_MAX_AMOUNT 40
|
||||||
#define BULLET_MARGIN 5.0 // extra hitbox space to make sure bullets hit
|
#define BULLET_MARGIN 5.0 // extra hitbox space to make sure bullets hit
|
||||||
#define MENU_SWITCH_DELAY 50 // delay in ms for when a menu screen is switched.
|
|
||||||
|
#define MENU_SWITCH_DELAY 50 // delay in ms for when a menu screen is switched.
|
||||||
|
#define MENU_LEFT_RIGHT_NONE 0 // not left or right pressed
|
||||||
|
#define MENU_LEFT_RIGHT_LEFT 1 // left pressed
|
||||||
|
#define MENU_LEFT_RIGHT_RIGHT 2 // right pressed
|
||||||
|
|
||||||
|
/*
|
||||||
|
menu windows:
|
||||||
|
|--------| |------------| |-----|
|
||||||
|
|tutorial| |color select| |start|
|
||||||
|
|--------| |------------| |-----|
|
||||||
|
*/
|
||||||
|
#define MENU_WINDOW_TUTORIAL 0
|
||||||
|
#define MENU_WINDOW_COLOR_SELECT 1
|
||||||
|
#define MENU_WINDOW_START 2
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@@ -36,6 +50,13 @@ typedef enum
|
|||||||
GAMEOVER
|
GAMEOVER
|
||||||
} game_state;
|
} game_state;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
SHIP_SELECT,
|
||||||
|
HOW_TO_PLAY
|
||||||
|
} menu_window_state;
|
||||||
|
|
||||||
uint8_t running, drawing_circle;
|
uint8_t running, drawing_circle;
|
||||||
game_state current_state = START;
|
game_state current_state = START;
|
||||||
|
|
||||||
@@ -70,10 +91,15 @@ int score;
|
|||||||
|
|
||||||
float player_x, player_y, radius;
|
float player_x, player_y, radius;
|
||||||
|
|
||||||
|
// ----------menu-----------
|
||||||
uint8_t ship_color_select_colors[3] = {255, 0, 255}; // colors to select ship
|
uint8_t ship_color_select_colors[3] = {255, 0, 255}; // colors to select ship
|
||||||
uint8_t menu_background_color[3] = {0, 255, 255};
|
uint8_t menu_background_color[3] = {0, 255, 255};
|
||||||
char menu_background_color_index; // 1 or -1, is used to cycle between the colors of the menu
|
char menu_background_color_index; // 1 or -1, is used to cycle between the colors of the menu
|
||||||
|
|
||||||
|
menu_window_state menu_active_window;
|
||||||
|
uint8_t menu_selected_window; // 0 is how to play, 1 is ship color select, 2 is game
|
||||||
|
uint8_t menu_left_right_pressed; // 0 is none, 1 is left, 2 is right
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief should be called when an unhandlable exception or error occurs. Triggers coredump.
|
* @brief should be called when an unhandlable exception or error occurs. Triggers coredump.
|
||||||
*
|
*
|
||||||
@@ -108,6 +134,9 @@ void init_variables()
|
|||||||
menu_background_color[0] = 0;
|
menu_background_color[0] = 0;
|
||||||
menu_background_color[1] = 255;
|
menu_background_color[1] = 255;
|
||||||
menu_background_color_index = 1;
|
menu_background_color_index = 1;
|
||||||
|
menu_active_window = NONE;
|
||||||
|
menu_selected_window = 0;
|
||||||
|
menu_left_right_pressed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ################################################################
|
// ################################################################
|
||||||
@@ -400,6 +429,25 @@ void update_menu()
|
|||||||
player_x = SCREEN_WIDTH / 2;
|
player_x = SCREEN_WIDTH / 2;
|
||||||
player_y = 500;
|
player_y = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (menu_switch_input_delay_timer.elapsed)
|
||||||
|
{
|
||||||
|
if (menu_left_right_pressed == MENU_LEFT_RIGHT_LEFT) // left
|
||||||
|
{
|
||||||
|
menu_selected_window -= 1;
|
||||||
|
if (menu_selected_window < MENU_WINDOW_TUTORIAL)
|
||||||
|
menu_selected_window = MENU_WINDOW_START;
|
||||||
|
menu_left_right_pressed = MENU_LEFT_RIGHT_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menu_left_right_pressed == MENU_LEFT_RIGHT_RIGHT) // right
|
||||||
|
{
|
||||||
|
menu_selected_window += 1;
|
||||||
|
if (menu_selected_window > MENU_WINDOW_START)
|
||||||
|
menu_selected_window = MENU_WINDOW_TUTORIAL;
|
||||||
|
menu_left_right_pressed = MENU_LEFT_RIGHT_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_game()
|
void update_game()
|
||||||
@@ -544,6 +592,11 @@ void update()
|
|||||||
if (pad.buttons & SCE_CTRL_CROSS)
|
if (pad.buttons & SCE_CTRL_CROSS)
|
||||||
cross_pressed = 1;
|
cross_pressed = 1;
|
||||||
|
|
||||||
|
if (pad.buttons & SCE_CTRL_LEFT)
|
||||||
|
menu_left_right_pressed = MENU_LEFT_RIGHT_LEFT;
|
||||||
|
if (pad.buttons & SCE_CTRL_RIGHT)
|
||||||
|
menu_left_right_pressed = MENU_LEFT_RIGHT_RIGHT;
|
||||||
|
|
||||||
ctrl_input_get_leftstick(&pad, &left_stick);
|
ctrl_input_get_leftstick(&pad, &left_stick);
|
||||||
|
|
||||||
// ctrl_input_get_rightstick(&pad, &right_stick);
|
// ctrl_input_get_rightstick(&pad, &right_stick);
|
||||||
@@ -598,6 +651,7 @@ void draw_start()
|
|||||||
|
|
||||||
void draw_menu()
|
void draw_menu()
|
||||||
{
|
{
|
||||||
|
// TODO add windows for tutorial and color select, and make "press x to start" window just a "start" window
|
||||||
drawing_draw_window_filled(SCREEN_WIDTH / 2 - 212 / 2, 50, 212, 100, "Window Title", pgf, RGBA8(menu_background_color[0], menu_background_color[1], menu_background_color[2], 255));
|
drawing_draw_window_filled(SCREEN_WIDTH / 2 - 212 / 2, 50, 212, 100, "Window Title", pgf, RGBA8(menu_background_color[0], menu_background_color[1], menu_background_color[2], 255));
|
||||||
vita2d_pgf_draw_text(pgf, SCREEN_WIDTH / 2 - 212 / 2 + 47, 50 + 70, COLOR_BLACK, 2.0, "Menu");
|
vita2d_pgf_draw_text(pgf, SCREEN_WIDTH / 2 - 212 / 2 + 47, 50 + 70, COLOR_BLACK, 2.0, "Menu");
|
||||||
drawing_draw_window_filled(600, 400, 226, 80, "Message", pgf, SECONDARY_BORDER_COLOR); // width: 28 pixels for each character
|
drawing_draw_window_filled(600, 400, 226, 80, "Message", pgf, SECONDARY_BORDER_COLOR); // width: 28 pixels for each character
|
||||||
|
|||||||
@@ -29,8 +29,18 @@ void drawing_draw_vline(float x0, float y0, float height, int thiccness, unsigne
|
|||||||
|
|
||||||
void drawing_draw_window_clear(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf)
|
void drawing_draw_window_clear(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf)
|
||||||
{
|
{
|
||||||
drawing_draw_rectangle_open(x, y, width, heigth, 10, MAIN_BORDER_COLOR);
|
drawing_draw_window(x,y,width,heigth,title_text,pgf,MAIN_BORDER_COLOR);
|
||||||
drawing_draw_hline(x, y + 10, width, 20, MAIN_BORDER_COLOR);
|
}
|
||||||
|
|
||||||
|
void drawing_draw_window_selected(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf)
|
||||||
|
{
|
||||||
|
drawing_draw_window(x,y,width,heigth,title_text,pgf,SELECTED_BORDER_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawing_draw_window(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf, unsigned int border_color)
|
||||||
|
{
|
||||||
|
drawing_draw_rectangle_open(x, y, width, heigth, 10, border_color);
|
||||||
|
drawing_draw_hline(x, y + 10, width, 20, border_color);
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
int box_x = width - 22 * i - 30 + x;
|
int box_x = width - 22 * i - 30 + x;
|
||||||
@@ -63,6 +73,12 @@ void drawing_draw_window_filled(float x, float y, float width, float heigth, con
|
|||||||
vita2d_draw_rectangle(x + 10, y + 30, width - 20, heigth - 40, color);
|
vita2d_draw_rectangle(x + 10, y + 30, width - 20, heigth - 40, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawing_draw_selected_window_filled(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf, unsigned int color)
|
||||||
|
{
|
||||||
|
drawing_draw_window_selected(x, y, width, heigth, title_text, pgf);
|
||||||
|
vita2d_draw_rectangle(x + 10, y + 30, width - 20, heigth - 40, color);
|
||||||
|
}
|
||||||
|
|
||||||
void drawing_draw_triangle(float x0, float y0, float x1, float y1, float x2, float y2, int thiccness, unsigned int color)
|
void drawing_draw_triangle(float x0, float y0, float x1, float y1, float x2, float y2, int thiccness, unsigned int color)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < thiccness; i++)
|
for (int i = 0; i < thiccness; i++)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <vita2d.h>
|
#include <vita2d.h>
|
||||||
#define MAIN_BORDER_COLOR (RGBA8(98, 124, 158, 255))
|
#define MAIN_BORDER_COLOR (RGBA8(98, 124, 158, 255))
|
||||||
|
#define SELECTED_BORDER_COLOR (RGBA8(115, 115, 110,255))
|
||||||
#define SECONDARY_BORDER_COLOR (RGBA8(181, 181, 181,255))
|
#define SECONDARY_BORDER_COLOR (RGBA8(181, 181, 181,255))
|
||||||
#define COLOR_BLACK (RGBA8(0, 0, 0, 255))
|
#define COLOR_BLACK (RGBA8(0, 0, 0, 255))
|
||||||
#define COLOR_MAGENTA (RGBA8(251, 41, 255,255))
|
#define COLOR_MAGENTA (RGBA8(251, 41, 255,255))
|
||||||
@@ -67,6 +68,18 @@ void drawing_draw_vline(float x0, float y0, float height, int thiccness, unsigne
|
|||||||
*/
|
*/
|
||||||
void drawing_draw_window_clear(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf);
|
void drawing_draw_window_clear(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief draws a selected window frame with the specified features
|
||||||
|
*
|
||||||
|
* @param x the top left x position of the frame
|
||||||
|
* @param y the top left y position of the frame
|
||||||
|
* @param width the width of the frame
|
||||||
|
* @param heigth the heigth of the frame
|
||||||
|
* @param title_text the title text to be displayed at the top of the frame
|
||||||
|
* @param pgf pointer to the pgf font to be used
|
||||||
|
*/
|
||||||
|
void drawing_draw_window_selected(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief draws a window frame with the specified features
|
* @brief draws a window frame with the specified features
|
||||||
*
|
*
|
||||||
@@ -80,6 +93,19 @@ void drawing_draw_window_clear(float x, float y, float width, float heigth, cons
|
|||||||
*/
|
*/
|
||||||
void drawing_draw_window_filled(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf, unsigned int color);
|
void drawing_draw_window_filled(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf, unsigned int color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief draws a selected window frame with the specified features
|
||||||
|
*
|
||||||
|
* @param x the top left x position of the frame
|
||||||
|
* @param y the top left y position of the frame
|
||||||
|
* @param width the width of the frame
|
||||||
|
* @param heigth the heigth of the frame
|
||||||
|
* @param title_text the title text to be displayed at the top of the frame
|
||||||
|
* @param pgf pointer to the pgf font to be used
|
||||||
|
* @param color the color of the background of the window
|
||||||
|
*/
|
||||||
|
void drawing_draw_selected_window_filled(float x, float y, float width, float heigth, const char *title_text, vita2d_pgf *pgf, unsigned int color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief draws an open triangle with the given parameters
|
* @brief draws an open triangle with the given parameters
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user