[ADD] menu for first version, adds to #4 but will be updated to #2

This commit is contained in:
SemvdH
2021-08-26 13:24:03 +02:00
parent 666c740917
commit d9c2a6ff31
5 changed files with 129 additions and 22 deletions

View File

@@ -60,8 +60,8 @@ timing_timer score_timer = {0, 100, 0}; // timer to update score
timing_timer simple_enemy_spawn_timer = {0, 500, 0}; // timer to spawn a new simple enemy
timing_timer complex_enemy_spawn_timer = {0, 2000, 0}; // timer to spawn a new complex enemy
timing_timer start_color_switch_timer = {0, 500, 0}; // timer to switch color on the start menu
SceBool start_color_set; // boolean to track if the title text should be colored or not
timing_timer start_color_switch_timer = {0, 500, 0}; // timer to switch color on the start menu
SceBool color_switch_value; // boolean to track if the title text should be colored or not
ENEMY_SPRITE enemies[ENEMY_MAX_AMOUNT];
uint32_t enemy_count;
@@ -70,6 +70,10 @@ int score;
float player_x, player_y, radius;
uint8_t ship_color_select_colors[3] = {255, 0, 255}; // colors to select ship
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
/**
* @brief should be called when an unhandlable exception or error occurs. Triggers coredump.
*
@@ -97,7 +101,13 @@ void init_variables()
player_y = 500;
radius = 5.0;
score = 0;
start_color_set = SCE_FALSE;
color_switch_value = SCE_FALSE;
ship_color_select_colors[0] = 0;
ship_color_select_colors[1] = 255;
ship_color_select_colors[2] = 255;
menu_background_color[0] = 0;
menu_background_color[1] = 255;
menu_background_color_index = 1;
}
// ################################################################
@@ -351,7 +361,7 @@ void update_start()
if (start_color_switch_timer.elapsed)
{
start_color_set = !start_color_set;
color_switch_value = !color_switch_value;
start_color_switch_timer.elapsed = 0;
}
@@ -360,6 +370,8 @@ void update_start()
{
current_state = MENU;
menu_switch_input_delay_timer.elapsed = 0;
player_x = 700;
player_y = 300;
}
}
@@ -367,10 +379,27 @@ void update_menu()
{
timing_update_timer(&menu_switch_input_delay_timer, deltaTime);
timing_check_timer_elapsed(&menu_switch_input_delay_timer);
if (menu_background_color[0] == 254 || menu_background_color[0] == 1)
{
menu_background_color[0] += menu_background_color_index;
menu_background_color[1] -= menu_background_color_index;
}
else
{
menu_background_color[0] += menu_background_color_index * 2;
menu_background_color[1] -= menu_background_color_index * 2;
}
if (menu_background_color[0] == 0 || menu_background_color[1] == 0)
menu_background_color_index = -menu_background_color_index;
if (cross_pressed)
if (menu_switch_input_delay_timer.elapsed)
{
current_state = GAME;
player_x = SCREEN_WIDTH / 2;
player_y = 500;
}
}
void update_game()
@@ -541,7 +570,7 @@ void draw_start()
{
unsigned int text_color;
unsigned int background_color;
if (start_color_set == SCE_TRUE)
if (color_switch_value == SCE_TRUE)
{
text_color = COLOR_BLACK;
background_color = COLOR_CYAN;
@@ -551,22 +580,31 @@ void draw_start()
background_color = COLOR_BLACK;
text_color = COLOR_CYAN;
}
drawing_draw_window_filled(SCREEN_WIDTH/2 - 300 / 2, 50, 300, 100, "Game Title", pgf, text_color);
vita2d_pgf_draw_text(pgf, SCREEN_WIDTH/2 - 300 / 2 + 47, 50 + 70, background_color, 2.0, "Cybershot");
drawing_draw_window_filled(SCREEN_WIDTH / 2 - 300 / 2, 50, 300, 100, "Game Title", pgf, background_color);
vita2d_pgf_draw_text(pgf, SCREEN_WIDTH / 2 - 300 / 2 + 47, 50 + 70, text_color, 2.0, "Cybershot");
drawing_draw_window_filled(600, 400, 226, 80, "Message", pgf, SECONDARY_BORDER_COLOR);
drawing_draw_window_filled(600, 400, 226, 80, "Message", pgf, SECONDARY_BORDER_COLOR); // width: 28 pixels for each character
vita2d_pgf_draw_text(pgf, 622, 457, COLOR_BLACK, 1.2f, "Press X to start");
}
void draw_menu()
{
vita2d_pvf_draw_text(pvf, 700, 80, RGBA8(0, 255, 0, 255), 1.0f, "menu sletjes");
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");
drawing_draw_window_filled(600, 400, 226, 80, "Message", pgf, SECONDARY_BORDER_COLOR); // width: 28 pixels for each character
vita2d_pgf_draw_text(pgf, 622, 457, COLOR_BLACK, 1.2f, "Press X to start");
drawing_draw_window_filled(100, 200, 356, 120, "WIP", pgf, RGBA8(255, 0, 0, 255)); // width: 28 pixels for each character
vita2d_pgf_draw_text(pgf, 122, 257, COLOR_BLACK, 1.2f, "Menu will be\nadded later");
//draw warning triangle
drawing_draw_triangle(320, 240, 280, 300, 360, 300, 3, COLOR_BLACK);
drawing_draw_vline(320-1.5, 255, 30, 6, COLOR_BLACK);
vita2d_draw_rectangle(320-1.5, 290, 6, 6, COLOR_BLACK);
}
void draw_game()
{
sprites_draw_player(player_x, player_y, PLAYER_SCALE);
sprites_draw_player(player_x, player_y, PLAYER_SCALE, RGBA8(ship_color_select_colors[0], ship_color_select_colors[1], ship_color_select_colors[2], 255));
for (int i = 0; i < 255; i++)
{
@@ -585,7 +623,6 @@ void draw_game()
sprintf(score_text, "%07d", score);
vita2d_pgf_draw_text(pgf, 42, 97, COLOR_BLACK, 1.2f, score_text);
char title_text[40];
sprintf(title_text, "CYBERSHOT_PSVITA - FPS: %d", timing_get_fps(deltaTime));

View File

@@ -20,7 +20,7 @@ void sprites_draw_smoke_circle(SMOKE_PARTICLE *smoke_particle)
}
}
void sprites_draw_player(float x, float y, float scale)
void sprites_draw_player(float x, float y, float scale,unsigned int color)
{
// bounding box: x -/+ 2.0 * scale, y - 5.0 * scale
@@ -30,15 +30,15 @@ void sprites_draw_player(float x, float y, float scale)
vita2d_draw_line(x, y + random_size, x + 1.0 * scale, y, RGBA8(255, 0, 0, 200));
//left side
vita2d_draw_line(x - 2.0 * scale, y, x + 2.0 * scale, y, SHIP_PRIMARY_COLOR);
vita2d_draw_line(x - 2.0 * scale, y, x - 1.0 * scale, y - 2.0 * scale, SHIP_PRIMARY_COLOR);
vita2d_draw_line(x - 1.0 * scale, y - 2.0 * scale, x - 1.0 * scale, y - 4.0 * scale, SHIP_PRIMARY_COLOR);
vita2d_draw_line(x - 1.0 * scale, y - 4.0 * scale, x, y - 5.0 * scale, SHIP_PRIMARY_COLOR);
vita2d_draw_line(x - 2.0 * scale, y, x + 2.0 * scale, y, color);
vita2d_draw_line(x - 2.0 * scale, y, x - 1.0 * scale, y - 2.0 * scale, color);
vita2d_draw_line(x - 1.0 * scale, y - 2.0 * scale, x - 1.0 * scale, y - 4.0 * scale, color);
vita2d_draw_line(x - 1.0 * scale, y - 4.0 * scale, x, y - 5.0 * scale, color);
//right side
vita2d_draw_line(x, y - 5.0 * scale, x + 1.0 * scale, y - 4.0 * scale, SHIP_PRIMARY_COLOR);
vita2d_draw_line(x + 1.0 * scale, y - 4.0 * scale, x + 1.0 * scale, y - 2.0 * scale, SHIP_PRIMARY_COLOR);
vita2d_draw_line(x + 1.0 * scale, y - 2.0 * scale, x + 2.0 * scale, y, SHIP_PRIMARY_COLOR);
vita2d_draw_line(x, y - 5.0 * scale, x + 1.0 * scale, y - 4.0 * scale, color);
vita2d_draw_line(x + 1.0 * scale, y - 4.0 * scale, x + 1.0 * scale, y - 2.0 * scale, color);
vita2d_draw_line(x + 1.0 * scale, y - 2.0 * scale, x + 2.0 * scale, y, color);
}
void sprites_draw_enemy(ENEMY_SPRITE *enemy)

View File

@@ -98,8 +98,9 @@ void sprites_draw_bullet(BULLET *bullet);
* @param x the x position of the player
* @param y the y position of the player
* @param scale the scale of the ship
* @param color the color of the ship (rgb array)
*/
void sprites_draw_player(float x, float y, float scale);
void sprites_draw_player(float x, float y, float scale, unsigned int color);
/**
* @brief draws a smoke particle

View File

@@ -61,4 +61,46 @@ void drawing_draw_window_filled(float x, float y, float width, float heigth, con
{
drawing_draw_window_clear(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)
{
for (int i = 0; i < thiccness; i++)
{
vita2d_draw_line(x0, y0 + i, x1, y1 + i, color);
vita2d_draw_line(x1, y1 + i, x2, y2 + i, color);
vita2d_draw_line(x2, y2 + i, x0, y0 + i, color);
}
}
void drawing_draw_triangle_filled(float x0, float y0, float x1, float y1, float x2, float y2, unsigned int color)
{
vita2d_draw_line(x0, y0, x1, y1, color);
vita2d_draw_line(x1, y1, x2, y2, color);
vita2d_draw_line(x2, y2, x0, y0, color);
float x_start = x0;
float y_start = y0;
float x_end = x1;
float y_end = y1;
SceBool start_done = SCE_FALSE;
SceBool end_done = SCE_FALSE;
//something is not right with y_start
while (start_done == SCE_FALSE && end_done == SCE_FALSE)
{
if (x_start < x2)
x_start += 1.0;
if (y_start < y2)
y_start += 1.0;
if (x_end < x2)
x_end += 1.0;
if (y_end < y2)
y_end += 1.0;
if (x_start >= x2 && y_start >= y2)
start_done = SCE_TRUE;
if (x_end >= x2 && y_end >= x2)
end_done = SCE_TRUE;
vita2d_draw_line(x_start, y_start, x_end, y_end, color);
}
}

View File

@@ -79,4 +79,31 @@ 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);
/**
* @brief draws an open triangle with the given parameters
*
* @param x0 the top x position
* @param y0 the top y position
* @param x1 the left x position
* @param y1 the left y position
* @param x2 the right x position
* @param y2 the right y position
* @param thiccness the width of the line of the triangle
* @param color the color to draw the triangle with
*/
void drawing_draw_triangle(float x0, float y0, float x1, float y1, float x2, float y2, int thiccness, unsigned int color);
/**
* @brief draws a filled triangle
*
* @param x0 the top x position
* @param y0 the top y position
* @param x1 the left x position
* @param y1 the left y position
* @param x2 the right x position
* @param y2 the right y position
* @param color the color of the triangle
*/
void drawing_draw_triangle_filled(float x0, float y0, float x1, float y1, float x2, float y2, unsigned int color);
#endif // !DRAWING_H