Nugget
psyqo
examples
tetris
tetris.hh
1
/*
2
3
MIT License
4
5
Copyright (c) 2022 PCSX-Redux authors
6
7
Permission is hereby granted, free of charge, to any person obtaining a copy
8
of this software and associated documentation files (the "Software"), to deal
9
in the Software without restriction, including without limitation the rights
10
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
copies of the Software, and to permit persons to whom the Software is
12
furnished to do so, subject to the following conditions:
13
14
The above copyright notice and this permission notice shall be included in all
15
copies or substantial portions of the Software.
16
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
SOFTWARE.
24
25
*/
26
27
#pragma once
28
29
#include "credits.hh"
30
#include "game.hh"
31
#include "gameover.hh"
32
#include "mainmenu.hh"
33
#include "options.hh"
34
#include "pause.hh"
35
#include "playfield.hh"
36
#include "psyqo/application.hh"
37
#include "psyqo/font.hh"
38
#include "psyqo/simplepad.hh"
39
#include "rand.hh"
40
#include "sound.hh"
41
#include "splash.hh"
42
43
// This is our top application class. It's what will run as the software starts.
44
// See tetris.cpp for details on the main function and the details on the
45
// methods implementations.
46
47
class
Tetris
final :
public
psyqo::Application
{
48
// These two methods are called by the PSYQo framework.
49
void
prepare()
override
;
50
void
createScene()
override
;
51
52
// We keep track of how many times we've been called to
53
// avoid initializing the hardware multiple times.
54
bool
m_initialized =
false
;
55
56
public
:
57
// A helper used in multiple scenes to draw the main logo.
58
void
renderTetrisLogo();
59
// A helper used in multiple scenes to get a blinking color.
60
psyqo::Color
getBlink(
unsigned
scale = 1);
61
62
// We're going to use the SimplePad interface to handle the input.
63
psyqo::SimplePad
m_input;
64
// The font renderer. We instantiate it with the defaut amount of
65
// fragments, but we're not actually using that many.
66
psyqo::Font<>
m_font;
67
68
// Everything else here is the Tetris implementation details.
69
70
// We're going to use a global random number generator, stored here.
71
Rand
m_rand;
72
73
// The splash screen scene. It'll be the first thing to be displayed.
74
SplashScreen
m_splash;
75
// The main menu scene. It comes right after the splash screen.
76
MainMenu
m_mainMenu;
77
// The options scene. It's one of the main menu entries.
78
Options
m_options;
79
// The credits scene. It's one of the main menu entries.
80
Credits
m_credits;
81
// The main game. Started from the main scene. It's the most
82
// complex one in the whole example.
83
MainGame
m_mainGame;
84
// The pause scene. It will be pushed on top of the main game scene.
85
Pause
m_pause;
86
// The game over scene. It will be pushed on top of the main game scene.
87
GameOver
m_gameOver;
88
89
// The sound engine.
90
Sound
m_sound;
91
92
// This represents the global playfield state. It's a completely custom
93
// class, implemented in the playfield.hh file.
94
Playfield<10, 20>
m_playfield;
95
96
private
:
97
// The global timer used by the mod player.
98
unsigned
m_musicTimer;
99
};
100
101
// We're only going to use a single global to hold everything. It'll
102
// be defined in tetris.cpp, and this is its definition for all the
103
// other modules in this project.
104
extern
Tetris
g_tetris;
Credits
Definition:
credits.hh:32
GameOver
Definition:
gameover.hh:32
MainGame
Definition:
game.hh:39
MainMenu
Definition:
mainmenu.hh:36
Options
Definition:
options.hh:32
Pause
Definition:
pause.hh:32
Rand
Definition:
rand.hh:33
Sound
Definition:
sound.hh:30
SplashScreen
Definition:
splash.hh:35
Tetris
Definition:
tetris.hh:47
psyqo::Application
The application class.
Definition:
application.hh:49
psyqo::Font
Definition:
font.hh:30
psyqo::SimplePad
A simple class to access the pads.
Definition:
simplepad.hh:45
Playfield< 10, 20 >
psyqo::Color
The Color struct.
Definition:
common.hh:91
Generated by
1.9.1