[Updated] Backgrounds to display the desired portion of the image, [Added] Start of the Game class
This commit is contained in:
+30
-30
@@ -2,38 +2,38 @@
|
||||
|
||||
#include "AssetService.h"
|
||||
|
||||
Background::Background(EBackground background)
|
||||
{
|
||||
this->textures.push_back(AssetService::getInstance().getBackground(background));
|
||||
this->position = {0,0};
|
||||
}
|
||||
// Background::Background(EBackground background)
|
||||
// {
|
||||
// this->textures.push_back(AssetService::getInstance().getBackground(background));
|
||||
// this->position = {0,0};
|
||||
// }
|
||||
|
||||
Background::Background(std::vector<EBackground> backgrounds)
|
||||
{
|
||||
for(int i = 0; i < backgrounds.size(); i++) {
|
||||
this->textures.push_back(AssetService::getInstance().getBackground(backgrounds[i]));
|
||||
this->position = {0,0};
|
||||
}
|
||||
}
|
||||
// Background::Background(std::vector<EBackground> backgrounds)
|
||||
// {
|
||||
// for(int i = 0; i < backgrounds.size(); i++) {
|
||||
// this->textures.push_back(AssetService::getInstance().getBackground(backgrounds[i]));
|
||||
// this->position = {0,0};
|
||||
// }
|
||||
// }
|
||||
|
||||
Vector2 Background::getPosition()
|
||||
{
|
||||
return this->position;
|
||||
}
|
||||
// Vector2 Background::getPosition()
|
||||
// {
|
||||
// return this->position;
|
||||
// }
|
||||
|
||||
void Background::updatePosition(Vector2 deltaPos)
|
||||
{
|
||||
this->position = {this->position.x+deltaPos.x, this->position.y+deltaPos.y};
|
||||
}
|
||||
// void Background::updatePosition(Vector2 deltaPos)
|
||||
// {
|
||||
// this->position = {this->position.x+deltaPos.x, this->position.y+deltaPos.y};
|
||||
// }
|
||||
|
||||
void Background::setPosition(Vector2 position)
|
||||
{
|
||||
this->position = position;
|
||||
}
|
||||
// void Background::setPosition(Vector2 position)
|
||||
// {
|
||||
// this->position = position;
|
||||
// }
|
||||
|
||||
void Background::draw()
|
||||
{
|
||||
for(int i = 0; i < textures.size(); i++) {
|
||||
DrawTexture(textures[i], position.x+ (i != 0 ? i*textures[i-1].width : 0), position.y, WHITE);
|
||||
}
|
||||
}
|
||||
// void Background::draw()
|
||||
// {
|
||||
// for(int i = 0; i < textures.size(); i++) {
|
||||
// DrawTexture(textures[i], position.x+ (i != 0 ? i*textures[i-1].width : 0), position.y, WHITE);
|
||||
// }
|
||||
// }
|
||||
|
||||
+15
-15
@@ -4,24 +4,24 @@
|
||||
|
||||
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;
|
||||
// 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();
|
||||
|
||||
this->game = Game();
|
||||
// this->camera = camera;
|
||||
}
|
||||
|
||||
void GameScreen::logic()
|
||||
{
|
||||
this->game.logic();
|
||||
// this->background.value().updatePosition({-2.5f,0});
|
||||
this->camera.value().target.x += 1.0f;
|
||||
// this->camera.value().target.x += 1.0f;
|
||||
}
|
||||
|
||||
void GameScreen::draw() {
|
||||
this->game.draw();
|
||||
}
|
||||
|
||||
+30
-14
@@ -14,16 +14,16 @@ MainScreen::MainScreen()
|
||||
for (int i = 0; i < AMNT_OF_BUTTONS; i++)
|
||||
{
|
||||
Text txt = Text("new game", EFont::GTEK, 30, 0, WHITE);
|
||||
text.push_back(txt);
|
||||
buttons.push_back(txt);
|
||||
}
|
||||
text[0].setColor(RED);
|
||||
text[1].setText("load game");
|
||||
text[2].setText("tutorial");
|
||||
text[3].setText("quit");
|
||||
buttons[0].setColor(RED);
|
||||
buttons[1].setText("load game");
|
||||
buttons[2].setText("tutorial");
|
||||
buttons[3].setText("quit");
|
||||
|
||||
for (int i = 0; i < AMNT_OF_BUTTONS; i++)
|
||||
{
|
||||
text[i].setPosition({(float)(GetScreenWidth() - text[i].getDimensions().x) / 2.0f, (float)TOP_GAP + SPACE_PER_ITEM * i});
|
||||
buttons[i].setPosition({(float)(GetScreenWidth() - buttons[i].getDimensions().x) / 2.0f, (float)TOP_GAP + SPACE_PER_ITEM * i});
|
||||
}
|
||||
|
||||
/** Will be ignored if already active (like when coming from the TitleScreen) */
|
||||
@@ -49,9 +49,10 @@ void MainScreen::logic()
|
||||
clickLogic();
|
||||
}
|
||||
|
||||
|
||||
void MainScreen::mouseLogic()
|
||||
{
|
||||
for (int i = 0; i < text.size(); i++)
|
||||
for (int i = 0; i < buttons.size(); i++)
|
||||
{
|
||||
/** No need to check the button that is already being hovered */
|
||||
if (hoveredButton == i)
|
||||
@@ -59,17 +60,17 @@ void MainScreen::mouseLogic()
|
||||
|
||||
/** 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();
|
||||
Vector2 dim = buttons[i].getDimensions();
|
||||
Vector2 pos = buttons[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 + 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);
|
||||
buttons[hoveredButton].setColor(WHITE);
|
||||
hoveredButton = i;
|
||||
text[hoveredButton].setColor(RED);
|
||||
buttons[hoveredButton].setColor(RED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -79,10 +80,10 @@ void MainScreen::keyboardLogic()
|
||||
{
|
||||
if (IsKeyPressed(KEY_DOWN) || IsKeyPressed(KEY_UP))
|
||||
{
|
||||
text[hoveredButton].setColor(WHITE);
|
||||
buttons[hoveredButton].setColor(WHITE);
|
||||
/** Move up or down depending on the pressed button. +4 is used so that -1 becomes 3 (the last button) */
|
||||
hoveredButton = ((hoveredButton - (IsKeyPressed(KEY_DOWN) ? -1 : 1)) + 4) % 4;
|
||||
text[hoveredButton].setColor(RED);
|
||||
buttons[hoveredButton].setColor(RED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ void MainScreen::clickLogic()
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER) || IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||
{
|
||||
std::string selectedButton = text[hoveredButton].getText();
|
||||
std::string selectedButton = buttons[hoveredButton].getText();
|
||||
|
||||
if (selectedButton == "new game")
|
||||
StateService::getInstance().setScreen(EScreen::GAME);
|
||||
@@ -103,3 +104,18 @@ void MainScreen::clickLogic()
|
||||
StateService::getInstance().setScreen(EScreen::CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
void MainScreen::draw()
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
if (buttons.size() > 0)
|
||||
{
|
||||
for (int i = 0; i < buttons.size(); i++)
|
||||
{
|
||||
buttons[i].draw();
|
||||
}
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
+22
-25
@@ -2,34 +2,31 @@
|
||||
#include "AudioService.h"
|
||||
#include <optional>
|
||||
|
||||
Screen::Screen()
|
||||
{
|
||||
}
|
||||
|
||||
void Screen::draw()
|
||||
{
|
||||
BeginDrawing();
|
||||
// void Screen::draw()
|
||||
// {
|
||||
// BeginDrawing();
|
||||
|
||||
if (camera.has_value())
|
||||
BeginMode2D(this->camera.value());
|
||||
// if (camera.has_value())
|
||||
// BeginMode2D(this->camera.value());
|
||||
|
||||
if (!background.has_value())
|
||||
ClearBackground(BLACK);
|
||||
else
|
||||
this->background.value().draw();
|
||||
// if (!background.has_value())
|
||||
// ClearBackground(BLACK);
|
||||
// else
|
||||
// this->background.value().draw();
|
||||
|
||||
if (map.has_value())
|
||||
this->map.value().draw();
|
||||
// if (map.has_value())
|
||||
// this->map.value().draw();
|
||||
|
||||
if (text.size() > 0)
|
||||
{
|
||||
for (int t = 0; t < text.size(); t++)
|
||||
{
|
||||
text[t].draw();
|
||||
}
|
||||
}
|
||||
if (camera.has_value())
|
||||
EndMode2D();
|
||||
// if (text.size() > 0)
|
||||
// {
|
||||
// for (int t = 0; t < text.size(); t++)
|
||||
// {
|
||||
// text[t].draw();
|
||||
// }
|
||||
// }
|
||||
// if (camera.has_value())
|
||||
// EndMode2D();
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
// EndDrawing();
|
||||
// }
|
||||
+25
-15
@@ -7,28 +7,23 @@
|
||||
|
||||
TitleScreen::TitleScreen()
|
||||
{
|
||||
Text textAbout = Text("Made by Ian Vink", EFont::SANSATION, 20,0, WHITE);
|
||||
textAbout.setPosition({
|
||||
(float)(GetScreenWidth()-textAbout.getDimensions().x)/1.2f,
|
||||
(float)(GetScreenHeight()-textAbout.getDimensions().y)/6.0f
|
||||
});
|
||||
Text textCenter = Text("Jelly rescue", EFont::RECKONER_BOLD, 100, 0, {255,25,25,255});
|
||||
textCenter.setPosition({
|
||||
(float)(GetScreenWidth()-textCenter.getDimensions().x)/2.0f,
|
||||
(float)(GetScreenHeight()-textCenter.getDimensions().y)/2.0f
|
||||
});
|
||||
Text textAbout = Text("Made by Ian Vink", EFont::SANSATION, 20, 0, WHITE);
|
||||
textAbout.setPosition({(float)(GetScreenWidth() - textAbout.getDimensions().x) / 1.2f,
|
||||
(float)(GetScreenHeight() - textAbout.getDimensions().y) / 6.0f});
|
||||
Text textCenter = Text("Jelly rescue", EFont::RECKONER_BOLD, 100, 0, {255, 25, 25, 255});
|
||||
textCenter.setPosition({(float)(GetScreenWidth() - textCenter.getDimensions().x) / 2.0f,
|
||||
(float)(GetScreenHeight() - textCenter.getDimensions().y) / 2.0f});
|
||||
Text testSub = Text("Press Enter", EFont::SANSATION, 30, 0, WHITE);
|
||||
testSub.setPosition({
|
||||
(float)(GetScreenWidth()-testSub.getDimensions().x)/2.0f,
|
||||
(float)(GetScreenHeight()-testSub.getDimensions().y)/1.5f
|
||||
});
|
||||
testSub.setPosition({(float)(GetScreenWidth() - testSub.getDimensions().x) / 2.0f,
|
||||
(float)(GetScreenHeight() - testSub.getDimensions().y) / 1.5f});
|
||||
|
||||
text.push_back(textAbout);
|
||||
text.push_back(textCenter);
|
||||
text.push_back(testSub);
|
||||
|
||||
EMusic track = AudioService::getInstance().getCurrentTrack();
|
||||
if (track != EMusic::MAIN) {
|
||||
if (track != EMusic::MAIN)
|
||||
{
|
||||
AudioService::getInstance().setMusic(EMusic::MAIN);
|
||||
AudioService::getInstance().playMusic();
|
||||
}
|
||||
@@ -41,4 +36,19 @@ void TitleScreen::logic()
|
||||
StateService::getInstance().setScreen(EScreen::MAIN);
|
||||
// std::cout << "Next screen!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void TitleScreen::draw()
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
|
||||
if (text.size() > 0)
|
||||
{
|
||||
for (int t = 0; t < text.size(); t++)
|
||||
{
|
||||
text[t].draw();
|
||||
}
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
@@ -4,8 +4,7 @@
|
||||
#include "EFont.h"
|
||||
#include "EScreen.h"
|
||||
|
||||
TutorialScreen::TutorialScreen()
|
||||
{
|
||||
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});
|
||||
@@ -21,3 +20,18 @@ void TutorialScreen::logic()
|
||||
StateService::getInstance().setScreen(EScreen::MAIN);
|
||||
}
|
||||
}
|
||||
|
||||
void TutorialScreen::draw()
|
||||
{
|
||||
BeginDrawing();
|
||||
this->background.draw();
|
||||
|
||||
if (text.size() > 0)
|
||||
{
|
||||
for (int t = 0; t < text.size(); t++)
|
||||
{
|
||||
text[t].draw();
|
||||
}
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user