Skip to content

Commit

Permalink
Tutorial scene
Browse files Browse the repository at this point in the history
  • Loading branch information
falseme committed Dec 19, 2023
1 parent 900dcde commit 6ea9edd
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 10 deletions.
Binary file removed CRogue/data/assets/textures/gui/keyboard/A.png
Binary file not shown.
Binary file removed CRogue/data/assets/textures/gui/keyboard/D.png
Binary file not shown.
Binary file added CRogue/data/assets/textures/gui/keyboard/ESC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CRogue/data/assets/textures/gui/keyboard/H.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed CRogue/data/assets/textures/gui/keyboard/S.png
Binary file not shown.
Binary file added CRogue/data/assets/textures/gui/keyboard/TAB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed CRogue/data/assets/textures/gui/keyboard/W.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions CRogue/data/lvds/ld1.lvd
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#2 #0 #0 &7 #0 #0 #0 #0 #0 #3 00
#2 O1 O5 O5 O5 O5 O5 O5 O3 #3 00 #2 #0 #0 #0 #0 #0 #0 #3
#2 O7 O0 O0 O0 O0 O0 O0 &A #3 00 #2 O1 O5 O5 O5 O5 O3 #3
#2 O7 O0 O0 O0 O0 O0 O0 O8 #0 #0 #0 O7 O0 O0 O0 O0 O8 #3
#2 O7 O0 O0 &0 O0 O0 O0 O0 O5 O5 O5 O0 O0 O0 O0 O0 O8 #3
#2 O7 O0 O0 O0 O0 &0 O0 O8 #0 #0 #0 O7 O0 O0 O0 O0 O8 #3
#2 O7 O0 O0 O0 O0 O0 O0 O0 O5 O5 O5 O0 O0 O0 O0 O0 O8 #3
#2 &9 O0 O0 O0 O0 O0 O0 O0 O6 O6 O6 O0 O0 O0 &1 O0 O8 #3
#2 O7 O0 O0 O0 O0 O0 O0 O8 #6 #1 #7 O7 O0 O0 O0 O0 O8 #3
#2 O7 O0 O0 O0 O0 O0 O0 &A #3 00 #2 O2 O6 O0 O0 O6 O4 #3
Expand Down
2 changes: 1 addition & 1 deletion CRogue/data/lvds/ld3.lvd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#2 O2 O6 O6 O6 O6 O6 O6 O6 O6 O6 O6 O4 #6 #1 #7 O7 O0 O0 &3 O0 O8 #6 #1 #7 O2 O6 O6 O6 O6 O6 O6 O6 O6 O6 O6 O4 #3
#4 #1 #1 #1 #1 #1 #1 #1 #1 #1 #1 #1 #1 #5 00 #2 O2 O6 O0 O0 O6 O4 #3 00 #4 #1 #1 #1 #1 #1 #1 #1 #1 #1 #1 #1 #1 #5
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 #4 #1 #7 O7 O8 #6 #1 #5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 #2 O7 O8 #3
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 #2 &6 O8 #3
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 #2 #0 #0 O7 O8 &8 #0 #3
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 #2 O1 O5 O0 O0 O5 O3 #3
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 #2 O7 O0 O0 O0 O0 O8 #3
Expand Down
2 changes: 1 addition & 1 deletion CRogue/src/Scene/LevelScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void LevelScene::updateGUIHealth(int health) {
GUIHealth[i]->setTexture(Assets::heart_empty);

int half = health % 2;
if (half != 0 && health > 0)
if (half > 0)
GUIHealth[whole]->setTexture(Assets::heart_half);

playerHealth = health;
Expand Down
15 changes: 14 additions & 1 deletion CRogue/src/Scene/SceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MenuScene.h"
#include "PauseMenu.h"
#include "StatsScene.h"
#include "TutorialScene.h"
#include <gameObject/Player.h>

Scene* SceneManager::mainScene = nullptr;
Expand All @@ -15,7 +16,7 @@ bool SceneManager::gamePaused = true;

void SceneManager::init() {
currentLevel = 1;
auxScene = new LevelScene(currentLevel, 0.15f, 0, 0, 0, 0, 0);
auxScene = new LevelScene(currentLevel, 0.15f, 0, 0, 0, 1, 0);
loadScene(auxScene);
mainScene = new MenuScene();
loadScene(mainScene);
Expand Down Expand Up @@ -94,6 +95,18 @@ void SceneManager::showStats() {

}

void SceneManager::showTutorial() {

if (gamePaused)
mainScene = new TutorialScene();
else
mainScene = new MenuScene();

loadScene(mainScene);
gamePaused = !gamePaused;

}

void SceneManager::update(Vector2f mousePosition) {
if (loadingNextLevel) {
loadNextLevel();
Expand Down
1 change: 1 addition & 0 deletions CRogue/src/Scene/SceneManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SceneManager {
static void quitGame();
static void pauseGame();
static void showStats();
static void showTutorial();
static void update(Vector2f mousePosition);
static void draw(RWindow* render);
static Scene* getCurrentScene();
Expand Down
39 changes: 39 additions & 0 deletions CRogue/src/Scene/TutorialScene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "TutorialScene.h"

#include <ui/Label.h>
#include <ui/Button.h>
#include <ui/AnimatedSpriteImage.h>

TutorialScene::TutorialScene() : Scene() {

GUIPanel = Panel(Vector2f(0, 0), Color(200, 180, 190, 50));

}

void TutorialScene::update(Vector2f mousePosition) {
GUIPanel.update(mousePosition);
}

void TutorialScene::loadScene() {

GUIPanel.addComponent(new Label(Vector2f(400, 80), "CONTROLES", 30, false, true));

GUIPanel.addComponent(new AnimatedSpriteImage(Animation(0.6f, Assets::WASD), Vector2f(100, 200), Vector2f(2, 2), Vector2f(31.5f, 21)));
GUIPanel.addComponent(new AnimatedSpriteImage(Animation(0.6f, Assets::playerRun), Vector2f(100, 320), Vector2f(4, 4), Vector2f(12, 12)));

GUIPanel.addComponent(new AnimatedSpriteImage(Animation(0.6f, Assets::H), Vector2f(300, 200), Vector2f(2, 2), Vector2f(9.5f, 0)));
GUIPanel.addComponent(new AnimatedSpriteImage(Animation(0.6f, Assets::playerHeal), Vector2f(300, 320), Vector2f(4, 4), Vector2f(12, 12)));

GUIPanel.addComponent(new AnimatedSpriteImage(Animation(0.6f, Assets::TAB), Vector2f(500, 200), Vector2f(2, 2), Vector2f(16.5f, 0)));
GUIPanel.addComponent(new Label(Vector2f(500, 320), "Inventario", 16, false, true, true));

GUIPanel.addComponent(new AnimatedSpriteImage(Animation(0.6f, Assets::ESC), Vector2f(700, 200), Vector2f(2, 2), Vector2f(20.5f, 0)));
GUIPanel.addComponent(new Label(Vector2f(700, 320), "Pausa", 16, false, true, true));

GUIPanel.addComponent(new Label(Vector2f(400, 430), "Click izquierdo para atacar", 16, false, true, true));

Button* backButton = new Button(Vector2f(400, 520), "Volver", 20);
backButton->setCallback(&SceneManager::showTutorial);
GUIPanel.addComponent(backButton);

}
11 changes: 11 additions & 0 deletions CRogue/src/Scene/TutorialScene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "Scene.h"

class TutorialScene : public Scene {
public:
TutorialScene();
void update(Vector2f mousePosition) override;
void loadScene() override;
};

29 changes: 29 additions & 0 deletions CRogue/src/UI/AnimatedSpriteImage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "AnimatedSpriteImage.h"

AnimatedSpriteImage::AnimatedSpriteImage(Animation anim, Vector2f pos, Vector2f scale, Vector2f origin) {
animation = anim;
sprite.setPosition(pos);
sprite.setScale(scale);
sprite.setOrigin(origin);
}

void AnimatedSpriteImage::update(Vector2f mousePosition, Vector2f panelPosition) {
animation.play();
sprite.setTexture(*animation.getFrame());
}

void AnimatedSpriteImage::draw(RWindow* render) {
render->draw(sprite);
}

void AnimatedSpriteImage::setPosition(Vector2f position) {
sprite.setPosition(position);
}

Vector2f AnimatedSpriteImage::getPosition() {
return sprite.getPosition();
}

void AnimatedSpriteImage::move(Vector2f delta) {
sprite.move(delta);
}
18 changes: 18 additions & 0 deletions CRogue/src/UI/AnimatedSpriteImage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "UIComponent.h"
#include <animation/Animation.h>

class AnimatedSpriteImage : public UIComponent {
public:
AnimatedSpriteImage(Animation anim, Vector2f pos, Vector2f scale, Vector2f origin);
void update(Vector2f mousePosition, Vector2f panelPosition);
void draw(RWindow* render);
void setPosition(Vector2f position);
Vector2f getPosition();
void move(Vector2f delta);
private:
Sprite sprite;
Animation animation;
};

2 changes: 1 addition & 1 deletion CRogue/src/UI/RWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void RWindow::setMousePosition(Vector2f pos) {
void RWindow::setSwordCursor() {

Cursor cursor;
if (cursor.loadFromPixels(Assets::mouse.getPixelsPtr(), { 20,20 }, { 0,0 }))
if (cursor.loadFromPixels(Assets::mouse->copyToImage().getPixelsPtr(), { 20,20 }, { 0,0 }))
setMouseCursor(cursor);

}
12 changes: 10 additions & 2 deletions CRogue/src/assets/Assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ Texture* Assets::key = nullptr;
Texture* Assets::healthPotion = nullptr;
Texture* Assets::healthPotion_small = nullptr;

Image Assets::mouse;
vector<Texture*> Assets::WASD;
vector<Texture*> Assets::H;
vector<Texture*> Assets::ESC;
vector<Texture*> Assets::TAB;
Texture* Assets::mouse = nullptr;

Font Assets::defaultFont;
Font Assets::titleFont;
Expand Down Expand Up @@ -114,7 +118,11 @@ void Assets::load() {
healthPotion_small = Loader::loadTexture("data/assets/textures/items/health_small.png");

//GUI
mouse = Loader::loadTexture("data/assets/textures/gui/mouse.png")->copyToImage();
WASD = Loader::loadSpriteSheet("data/assets/textures/gui/keyboard/WASD.png", 63, 42);
H = Loader::loadSpriteSheet("data/assets/textures/gui/keyboard/H.png", 19, 21);
ESC = Loader::loadSpriteSheet("data/assets/textures/gui/keyboard/ESC.png", 41, 21);
TAB = Loader::loadSpriteSheet("data/assets/textures/gui/keyboard/TAB.png", 33, 21);
mouse = Loader::loadTexture("data/assets/textures/gui/mouse.png");
heart = Loader::loadTexture("data/assets/textures/gui/heart2.png");
heart_half = Loader::loadTexture("data/assets/textures/gui/heart1.png");
heart_empty = Loader::loadTexture("data/assets/textures/gui/heart0.png");
Expand Down
6 changes: 5 additions & 1 deletion CRogue/src/assets/Assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class Assets {
static Texture* healthPotion;
static Texture* healthPotion_small;

static Image mouse;
static vector<Texture*> WASD;
static vector<Texture*> H;
static vector<Texture*> ESC;
static vector<Texture*> TAB;
static Texture* mouse;

static Font defaultFont;
static Font titleFont;
Expand Down
6 changes: 5 additions & 1 deletion CRogue/src/scene/MenuScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ void MenuScene::loadScene() {
statsButton->setCallback(&SceneManager::showStats);
GUIPanel.addComponent(statsButton);

Button* quitButton = new Button(Vector2f(400, 500), "Salir", 16);
Button* tutorialButton = new Button(Vector2f(400, 500), "Controles", 16);
tutorialButton->setCallback(&SceneManager::showTutorial);
GUIPanel.addComponent(tutorialButton);

Button* quitButton = new Button(Vector2f(400, 550), "Salir", 16);
quitButton->setCallback(&SceneManager::quitGame);
GUIPanel.addComponent(quitButton);

Expand Down

1 comment on commit 6ea9edd

@falseme
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also solved a bug that showed half a heart when player health was -1

Please sign in to comment.