[Added] Tutorial Screen, Start of the Game Screen
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#include "GameScreen.h"
|
||||
#include "Map.h"
|
||||
#include "StateService.h"
|
||||
|
||||
GameScreen::GameScreen()
|
||||
{
|
||||
std::vector<EBackground> bgs;
|
||||
bgs.push_back(EBackground::GAME1);
|
||||
bgs.push_back(EBackground::GAME2);
|
||||
bgs.push_back(EBackground::GAME3);
|
||||
this->background = Background(bgs);
|
||||
this->map = Map();
|
||||
|
||||
Vector2 screenSize = StateService::getInstance().getScreenSize();
|
||||
Camera2D camera = { 0 };
|
||||
camera.offset = (Vector2){ screenSize.x / 2.0f, screenSize.y / 2.0f }; // Set offset to center
|
||||
camera.target = (Vector2){ screenSize.x /2.0f, screenSize.y / 2.0f }; // Initially at the center of the world
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
this->camera = camera;
|
||||
}
|
||||
|
||||
void GameScreen::logic()
|
||||
{
|
||||
// this->background.value().updatePosition({-2.5f,0});
|
||||
this->camera.value().target.x += 1.0f;
|
||||
}
|
||||
+23
-21
@@ -1,8 +1,7 @@
|
||||
#include "MainScreen.h"
|
||||
#include "AssetService.h"
|
||||
#include "AudioService.h"
|
||||
#include <iostream>
|
||||
#include "StateService.h"
|
||||
#include "raylib.h"
|
||||
|
||||
MainScreen::MainScreen()
|
||||
{
|
||||
@@ -17,7 +16,6 @@ MainScreen::MainScreen()
|
||||
Text txt = Text("new game", EFont::GTEK, 30, 0, WHITE);
|
||||
text.push_back(txt);
|
||||
}
|
||||
|
||||
text[0].setColor(RED);
|
||||
text[1].setText("load game");
|
||||
text[2].setText("tutorial");
|
||||
@@ -29,12 +27,12 @@ MainScreen::MainScreen()
|
||||
}
|
||||
|
||||
/** Will be ignored if already active (like when coming from the TitleScreen) */
|
||||
AudioService::getInstance().setMusic(EMusic::MAIN);
|
||||
AudioService::getInstance().playMusic();
|
||||
}
|
||||
|
||||
MainScreen::~MainScreen()
|
||||
{
|
||||
EMusic track = AudioService::getInstance().getCurrentTrack();
|
||||
if (track != EMusic::MAIN)
|
||||
{
|
||||
AudioService::getInstance().setMusic(EMusic::MAIN);
|
||||
AudioService::getInstance().playMusic();
|
||||
}
|
||||
}
|
||||
|
||||
void MainScreen::logic()
|
||||
@@ -43,10 +41,12 @@ void MainScreen::logic()
|
||||
// std::cout << mouseD.y <<std::endl;
|
||||
// if (mouseD.x != 0.0f && mouseD.y != 0.0f)
|
||||
// {
|
||||
// mouseLogic();
|
||||
mouseLogic();
|
||||
// }
|
||||
|
||||
keyboardLogic();
|
||||
|
||||
clickLogic();
|
||||
}
|
||||
|
||||
void MainScreen::mouseLogic()
|
||||
@@ -57,13 +57,15 @@ void MainScreen::mouseLogic()
|
||||
if (hoveredButton == i)
|
||||
continue;
|
||||
|
||||
/** Pixels around the text that also count towards that button, to make the hover feel better */
|
||||
int textPadding = 20;
|
||||
Vector2 dim = text[i].getDimensions();
|
||||
Vector2 pos = text[i].getPosition();
|
||||
Rectangle rect = {pos.x, pos.y, dim.x, dim.y};
|
||||
|
||||
Vector2 mousePos = GetMousePosition();
|
||||
// mousePos.x >= rect.x && mousePos.x <= (rect.x+rect.width) &&
|
||||
if (mousePos.x >= rect.x && mousePos.x <= (rect.x+rect.width) && mousePos.y >= rect.y && mousePos.y <= (rect.y + rect.height))
|
||||
if ((mousePos.x + textPadding) >= rect.x && mousePos.x <= (rect.x + rect.width + textPadding) && (mousePos.y + textPadding) >= rect.y && mousePos.y <= (rect.y + rect.height + textPadding))
|
||||
{
|
||||
text[hoveredButton].setColor(WHITE);
|
||||
hoveredButton = i;
|
||||
@@ -82,22 +84,22 @@ void MainScreen::keyboardLogic()
|
||||
hoveredButton = ((hoveredButton - (IsKeyPressed(KEY_DOWN) ? -1 : 1)) + 4) % 4;
|
||||
text[hoveredButton].setColor(RED);
|
||||
}
|
||||
}
|
||||
|
||||
void MainScreen::clickLogic()
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||
{
|
||||
std::cout << text[hoveredButton].getText() << std::endl;
|
||||
std::string selectedButton = text[hoveredButton].getText();
|
||||
|
||||
|
||||
if(selectedButton == "new game") {
|
||||
if (selectedButton == "new game")
|
||||
StateService::getInstance().setScreen(EScreen::GAME);
|
||||
else if (selectedButton == "load game")
|
||||
{
|
||||
}
|
||||
else if(selectedButton == "load game") {
|
||||
}
|
||||
else if(selectedButton == "tutorial") {
|
||||
else if (selectedButton == "tutorial")
|
||||
StateService::getInstance().setScreen(EScreen::TUTORIAL);
|
||||
}
|
||||
else if(selectedButton == "quit") {
|
||||
else if (selectedButton == "quit")
|
||||
StateService::getInstance().setScreen(EScreen::CLOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-1
@@ -2,10 +2,24 @@
|
||||
#include "AudioService.h"
|
||||
#include <optional>
|
||||
|
||||
Screen::Screen()
|
||||
{
|
||||
}
|
||||
|
||||
void Screen::draw()
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
if (camera.has_value())
|
||||
BeginMode2D(this->camera.value());
|
||||
|
||||
if (!background.has_value())
|
||||
ClearBackground(BLACK);
|
||||
else
|
||||
this->background.value().draw();
|
||||
|
||||
if (map.has_value())
|
||||
this->map.value().draw();
|
||||
|
||||
if (text.size() > 0)
|
||||
{
|
||||
@@ -14,5 +28,8 @@ void Screen::draw()
|
||||
text[t].draw();
|
||||
}
|
||||
}
|
||||
if (camera.has_value())
|
||||
EndMode2D();
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
@@ -27,20 +27,11 @@ TitleScreen::TitleScreen()
|
||||
text.push_back(textCenter);
|
||||
text.push_back(testSub);
|
||||
|
||||
|
||||
AudioService::getInstance().setMusic(EMusic::MAIN);
|
||||
AudioService::getInstance().playMusic();
|
||||
|
||||
// bg = LoadMusicStream("assets/Audio/Music/Crash_WarpRoomTheme.ogg");
|
||||
// bg.looping = true;
|
||||
// SetMasterVolume(1.0f);
|
||||
// SetMusicVolume(bg, 1.0f);
|
||||
// PlayMusicStream(bg);
|
||||
}
|
||||
|
||||
TitleScreen::~TitleScreen()
|
||||
{
|
||||
// UnloadMusicStream(bg);
|
||||
EMusic track = AudioService::getInstance().getCurrentTrack();
|
||||
if (track != EMusic::MAIN) {
|
||||
AudioService::getInstance().setMusic(EMusic::MAIN);
|
||||
AudioService::getInstance().playMusic();
|
||||
}
|
||||
}
|
||||
|
||||
void TitleScreen::logic()
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "TutorialScreen.h"
|
||||
|
||||
#include "StateService.h"
|
||||
#include "EFont.h"
|
||||
#include "EScreen.h"
|
||||
|
||||
TutorialScreen::TutorialScreen()
|
||||
{
|
||||
Text textBack = Text("Press Enter to go back", EFont::SANSATION, 30, 0, RED);
|
||||
textBack.setPosition({(float)(GetScreenWidth() - textBack.getDimensions().x) / 1.3f,
|
||||
(float)(GetScreenHeight() - textBack.getDimensions().y) / 1.15f});
|
||||
this->text.push_back(textBack);
|
||||
|
||||
this->background = Background(EBackground::TUTORIAL);
|
||||
}
|
||||
|
||||
void TutorialScreen::logic()
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||
{
|
||||
StateService::getInstance().setScreen(EScreen::MAIN);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user