Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
imt2531_assignment2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Blakli
imt2531_assignment2
Commits
90f80aa5
Commit
90f80aa5
authored
5 years ago
by
Andreas Blakli
Browse files
Options
Downloads
Patches
Plain Diff
Improved GUI, added comfirm action with enter key
parent
fe1ec209
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/ui.h
+3
-0
3 additions, 0 deletions
include/ui.h
resources/levels/level1
+2
-2
2 additions, 2 deletions
resources/levels/level1
src/game.cpp
+7
-7
7 additions, 7 deletions
src/game.cpp
src/ui.cpp
+48
-49
48 additions, 49 deletions
src/ui.cpp
with
60 additions
and
58 deletions
include/ui.h
+
3
−
0
View file @
90f80aa5
...
...
@@ -7,6 +7,8 @@
#include
<imgui/imgui_impl_opengl3.h>
class
ui
{
private:
ImVec4
colorYellow
=
ImVec4
(
1
,
1
,
0
,
1
);
// Yellow color for text
public:
void
inGameStats
(
int
points
,
int
lives
);
void
mainMenu
();
...
...
@@ -15,5 +17,6 @@ public:
void
gameOverDisp
(
int
points
);
void
victoryDisp
(
int
points
);
void
levelSelector
(
ImGuiWindowFlags
window_flags
);
bool
detectEnterPress
();
bool
lvlSelect
=
false
;
};
This diff is collapsed.
Click to expand it.
resources/levels/level1
+
2
−
2
View file @
90f80aa5
...
...
@@ -18,9 +18,9 @@
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 0 1 1 7 1 1 7 1 1 1 1 1 1
2 0 0 0 0 0 c 0 0 b 1 1 1 1 1 0 1 1 b 0 0 c 0 0 0 0 0 0
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 0 1 1 7 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1
7
1 1 1 1 1 0 1 1 7 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1
0
1 1 1 1 1 0 1 1 7 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 a 0 0 0 0 0 b 0 0 b 1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 1 1 1
7
1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 1 1 1
0
1 1 7 1 1 1 1 1 1
1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 1 1 1 7 1 1 7 1 1 1 1 1 1
1 3 0 0 0 0 c 0 0 8 0 0 4 1 1 3 0 0 8 0 0 c 0 0 0 0 4 1
1 7 1 1 1 1 7 1 1 1 1 1 7 1 1 7 1 1 1 1 1 7 1 1 1 1 7 1
...
...
This diff is collapsed.
Click to expand it.
src/game.cpp
+
7
−
7
View file @
90f80aa5
...
...
@@ -128,12 +128,12 @@ void game::loopHandler() {
ui
.
pauseMenu
();
// calls the pause menu
}
if
(
restart
)
{
std
::
string
s
=
"resources/levels/level"
+
std
::
to_string
(
mainMenuLvlSel
);
char
const
*
p
char
=
s
.
c_str
();
//
use char const* as target type
loader
.
loadLevel
(
p
char
);
std
::
string
lvlPath
=
"resources/levels/level"
+
std
::
to_string
(
mainMenuLvlSel
);
// Game level path, adds int from ui::levelSelector()
char
const
*
lvlP
char
=
lvlPath
.
c_str
();
//
String to char
loader
.
loadLevel
(
lvlP
char
);
// Loads game level
pacMan
=
new
pacman
;
restart
=
false
;
//pacMan->points =
298
; // remove commenting if "quick testing" victory display
//pacMan->points =
loader.floorObjects.size() - 1
; // remove commenting if "quick testing" victory display
}
myWindow
.
swapBuffers
();
//<-- SWAP BUFFERS
glfwPollEvents
();
//<-- LISTEN FOR WINDOW EVENTS
...
...
@@ -145,6 +145,6 @@ void game::loopHandler() {
// Resets the ingame stats, so that a new object isnt required
void
game
::
resetStatValues
(
pacman
pacman
){
pacman
.
points
=
0
;
pacman
.
lives
=
3
;
//
pacman.points = 0;
//
pacman.lives = 3;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/ui.cpp
+
48
−
49
View file @
90f80aa5
...
...
@@ -5,76 +5,61 @@
void
ui
::
inGameStats
(
int
points
,
int
lives
)
{
ImGuiWindowFlags
window_flags
=
0
;
// Sets the window flags that is to be used
window_flags
|=
ImGuiWindowFlags_NoMove
;
// window_flags |= ImGuiWindowFlags_NoResize;
window_flags
|=
ImGuiWindowFlags_NoCollapse
;
window_flags
|=
ImGuiWindowFlags_AlwaysAutoResize
;
window_flags
|=
ImGuiWindowFlags_NoInputs
;
window_flags
|=
ImGuiWindowFlags_NoBackground
;
window_flags
|=
ImGuiWindowFlags_NoDecoration
;
// GUI
ImGui_ImplOpenGL3_NewFrame
();
ImGui_ImplGlfw_NewFrame
();
ImGui
::
NewFrame
();
std
::
string
pointsBuffer
=
"Score: "
+
std
::
to_string
(
points
);
// score
std
::
string
livesBuffer
=
"HP: "
+
std
::
to_string
(
lives
);
// HP
// data that is to be displayed
ImGui
::
Begin
(
"Stats"
,
NULL
,
window_flags
);
ImGui
::
Text
(
pointsBuffer
.
c_str
());
ImGui
::
Text
(
livesBuffer
.
c_str
());
ImGui
::
TextColored
(
colorYellow
,
pointsBuffer
.
c_str
());
ImGui
::
TextColored
(
colorYellow
,
livesBuffer
.
c_str
());
ImGui
::
SetWindowFontScale
(
2.0f
);
ImGui
::
End
();
// Display
ImGui
::
Render
();
ImGui_ImplOpenGL3_RenderDrawData
(
ImGui
::
GetDrawData
());
}
// Displays the main menu
void
ui
::
mainMenu
()
{
ImGuiWindowFlags
window_flags
=
0
;
// Sets the window flags that is to be used
window_flags
|=
ImGuiWindowFlags_NoMove
;
//window_flags |= ImGuiWindowFlags_NoResize;
window_flags
|=
ImGuiWindowFlags_NoCollapse
;
window_flags
|=
ImGuiWindowFlags_AlwaysAutoResize
;
window_flags
|=
ImGuiWindowFlags_NoDecoration
;
ImGuiIO
&
io
=
ImGui
::
GetIO
();
(
void
)
io
;
io
.
ConfigFlags
|=
ImGuiConfigFlags_NavEnableKeyboard
;
// Enable Keyboard Controls
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// GUI
ImGui_ImplOpenGL3_NewFrame
();
ImGui_ImplGlfw_NewFrame
();
ImGui
::
NewFrame
();
// Position menu center of screen
ImGui
::
SetNextWindowPos
(
ImVec2
(
io
.
DisplaySize
.
x
*
0.5f
,
io
.
DisplaySize
.
y
*
0.5f
),
\
ImGuiCond_Always
,
ImVec2
(
0.5f
,
0.5f
));
// data that is to be displayed
ImGui
::
Begin
(
"Main Menu"
,
NULL
,
window_flags
);
if
(
ImGui
::
Button
(
"Start game"
))
{
// Creates button. If clicked sets bools val
/* startGame = true; // Enables the main game loop
exitMenu = true; // Disables the menu loop
mainMenuChoice = 2; // Testing ------------------
restart = true;
//victory = false;
*/
ImGui
::
PushStyleColor
(
ImGuiCol_Text
,
colorYellow
);
ImGui
::
Text
(
"Main Menu"
);
if
(
ImGui
::
Button
(
"Start game"
)
||
detectEnterPress
())
{
// Creates button. If clicked sets bools val
lvlSelect
=
true
;
}
if
(
ImGui
::
Button
(
"Quit game"
))
{
// Creates button. If clicked sets bools val
if
(
ImGui
::
Button
(
"Quit game"
)
||
detectEnterPress
()
)
{
// Creates button. If clicked sets bools val
quitGameComf
=
true
;
// Disables the render loop to terminate the application
startGame
=
false
;
// Disables the main game loop
exitMenu
=
true
;
// Disables the menu loop
//mainMenuChoice = 1; // Testing-----------------------
}
if
(
lvlSelect
)
{
levelSelector
(
window_flags
);
}
ImGui
::
PopStyleColor
();
ImGui
::
SetWindowFontScale
(
2.0f
);
ImGui
::
End
();
// Display
...
...
@@ -96,34 +81,35 @@ void ui::pauseMenu() {
window_flags
|=
ImGuiWindowFlags_NoResize
;
window_flags
|=
ImGuiWindowFlags_NoCollapse
;
window_flags
|=
ImGuiWindowFlags_AlwaysAutoResize
;
window_flags
|=
ImGuiWindowFlags_NoDecoration
;
ImGuiIO
&
io
=
ImGui
::
GetIO
();
(
void
)
io
;
io
.
ConfigFlags
|=
ImGuiConfigFlags_NavEnableKeyboard
;
// Enable Keyboard Controls
// GUI
ImGui_ImplOpenGL3_NewFrame
();
ImGui_ImplGlfw_NewFrame
();
ImGui
::
NewFrame
();
// Position menu center of screen
ImGui
::
SetNextWindowPos
(
ImVec2
(
io
.
DisplaySize
.
x
*
0.5f
,
io
.
DisplaySize
.
y
*
0.5f
),
\
ImGuiCond_Always
,
ImVec2
(
0.5f
,
0.5f
));
// data that is to be displayed
ImGui
::
Begin
(
"Pause Menu"
,
NULL
,
window_flags
);
if
(
ImGui
::
Button
(
"Resume game"
))
{
// Creates button. If clicked sets bools val
ImGui
::
PushStyleColor
(
ImGuiCol_Text
,
colorYellow
);
ImGui
::
Text
(
"Pause Menu"
);
if
(
ImGui
::
Button
(
"Resume game"
)
||
detectEnterPress
())
{
// Creates button. If clicked sets bools val
pauseGame
=
false
;
// Stops the pause game loop
startGame
=
true
;
// Enables the main game loop
}
if
(
ImGui
::
Button
(
"
Quit
to main menu"
))
{
// Creates button. If clicked sets bools val
if
(
ImGui
::
Button
(
"
Return
to main menu"
)
||
detectEnterPress
()
)
{
// Creates button. If clicked sets bools val
startGame
=
false
;
// Stops the main game loop
exitMenu
=
false
;
// Enables the menu loop
pauseGame
=
false
;
// Stops the pause game loop
}
if
(
ImGui
::
Button
(
"Quit game"
))
{
// Creates button. If clicked sets bools val
if
(
ImGui
::
Button
(
"Quit game"
)
||
detectEnterPress
()
)
{
// Creates button. If clicked sets bools val
quitGameComf
=
true
;
// Disables the render loop to terminate the application
pauseGame
=
false
;
// Stops the pauseGame loop
}
ImGui
::
PopStyleColor
();
ImGui
::
SetWindowFontScale
(
2.0f
);
ImGui
::
End
();
// Display
...
...
@@ -135,39 +121,39 @@ void ui::pauseMenu() {
void
ui
::
gameOverDisp
(
int
points
)
{
ImGuiWindowFlags
window_flags
=
0
;
// Sets the window flags that is to be used
window_flags
|=
ImGuiWindowFlags_NoMove
;
//window_flags |= ImGuiWindowFlags_NoResize;
window_flags
|=
ImGuiWindowFlags_NoCollapse
;
window_flags
|=
ImGuiWindowFlags_AlwaysAutoResize
;
window_flags
|=
ImGuiWindowFlags_NoBringToFrontOnFocus
;
window_flags
|=
ImGuiWindowFlags_NoDecoration
;
ImGuiIO
&
io
=
ImGui
::
GetIO
();
(
void
)
io
;
io
.
ConfigFlags
|=
ImGuiConfigFlags_NavEnableKeyboard
;
// Enable Keyboard Controls
// GUI
ImGui_ImplOpenGL3_NewFrame
();
ImGui_ImplGlfw_NewFrame
();
ImGui
::
NewFrame
();
// Position menu center of screen
ImGui
::
SetNextWindowPos
(
ImVec2
(
io
.
DisplaySize
.
x
*
0.5f
,
io
.
DisplaySize
.
y
*
0.5f
),
\
ImGuiCond_Always
,
ImVec2
(
0.5f
,
0.5f
));
std
::
string
pointsBuffer
=
"Total score: "
+
std
::
to_string
(
points
);
// Total score
// data that is to be displayed
ImGui
::
Begin
(
"GAME OVER"
,
NULL
,
window_flags
);
ImGui
::
PushStyleColor
(
ImGuiCol_Text
,
colorYellow
);
ImGui
::
Text
(
"GAME OVER"
);
ImGui
::
Text
(
pointsBuffer
.
c_str
());
if
(
ImGui
::
Button
(
"Try again"
))
{
// Creates button. If clicked sets bools val
if
(
ImGui
::
Button
(
"Try again"
)
||
detectEnterPress
()
)
{
// Creates button. If clicked sets bools val
gameIsOver
=
false
;
// Stops the game over loop
startGame
=
true
;
// Enables the main game loop
restart
=
true
;
// Testing---------------------------
}
if
(
ImGui
::
Button
(
"Return to main menu"
))
{
// Creates button. If clicked sets bools val
if
(
ImGui
::
Button
(
"Return to main menu"
)
||
detectEnterPress
()
)
{
// Creates button. If clicked sets bools val
startGame
=
false
;
// Stops the main game loop
exitMenu
=
false
;
// Enables main menu
}
if
(
ImGui
::
Button
(
"Quit game"
))
{
// Creates button. If clicked sets bools val
if
(
ImGui
::
Button
(
"Quit game"
)
||
detectEnterPress
()
)
{
// Creates button. If clicked sets bools val
quitGameComf
=
true
;
// Disables the render loop to terminate the application
}
ImGui
::
PopStyleColor
();
ImGui
::
SetWindowFontScale
(
2.0f
);
ImGui
::
End
();
// Display
...
...
@@ -175,39 +161,39 @@ void ui::gameOverDisp(int points) {
ImGui_ImplOpenGL3_RenderDrawData
(
ImGui
::
GetDrawData
());
}
// Displays the victory menu
void
ui
::
victoryDisp
(
int
points
)
{
ImGuiWindowFlags
window_flags
=
0
;
// Sets the window flags that is to be used
window_flags
|=
ImGuiWindowFlags_NoMove
;
//window_flags |= ImGuiWindowFlags_NoResize;
window_flags
|=
ImGuiWindowFlags_NoCollapse
;
window_flags
|=
ImGuiWindowFlags_AlwaysAutoResize
;
window_flags
|=
ImGuiWindowFlags_No
BringToFrontOnFocus
;
window_flags
|=
ImGuiWindowFlags_No
Decoration
;
ImGuiIO
&
io
=
ImGui
::
GetIO
();
(
void
)
io
;
io
.
ConfigFlags
|=
ImGuiConfigFlags_NavEnableKeyboard
;
// Enable Keyboard Controls
// GUI
ImGui_ImplOpenGL3_NewFrame
();
ImGui_ImplGlfw_NewFrame
();
ImGui
::
NewFrame
();
// Position menu center of screen
ImGui
::
SetNextWindowPos
(
ImVec2
(
io
.
DisplaySize
.
x
*
0.5f
,
io
.
DisplaySize
.
y
*
0.5f
),
\
ImGuiCond_Always
,
ImVec2
(
0.5f
,
0.5f
));
std
::
string
pointsBuffer
=
"Total score: "
+
std
::
to_string
(
points
);
// Total score
// data that is to be displayed
ImGui
::
Begin
(
"VICTORY"
,
NULL
,
window_flags
);
ImGui
::
PushStyleColor
(
ImGuiCol_Text
,
colorYellow
);
ImGui
::
Text
(
"VICTORY"
);
ImGui
::
Text
(
pointsBuffer
.
c_str
());
if
(
ImGui
::
Button
(
"Return to main menu"
))
{
// Creates button. If clicked sets bools val
if
(
ImGui
::
Button
(
"Return to main menu"
)
||
detectEnterPress
()
)
{
// Creates button. If clicked sets bools val
startGame
=
false
;
// Stops the main game loop
exitMenu
=
false
;
// Enables main menu
victory
=
false
;
// Stops victory loop
}
if
(
ImGui
::
Button
(
"Quit game"
))
{
// Creates button. If clicked sets bools val
if
(
ImGui
::
Button
(
"Quit game"
)
||
detectEnterPress
()
)
{
// Creates button. If clicked sets bools val
quitGameComf
=
true
;
// Disables the render loop to terminate the application
}
ImGui
::
PopStyleColor
();
ImGui
::
SetWindowFontScale
(
2.0f
);
ImGui
::
End
();
// Display
...
...
@@ -215,6 +201,7 @@ void ui::victoryDisp(int points) {
ImGui_ImplOpenGL3_RenderDrawData
(
ImGui
::
GetDrawData
());
}
// Displays the level selector menu
void
ui
::
levelSelector
(
ImGuiWindowFlags
window_flags
)
{
window_flags
|=
ImGuiWindowFlags_NoDecoration
;
...
...
@@ -223,22 +210,34 @@ void ui::levelSelector(ImGuiWindowFlags window_flags) {
ImGui
::
SetNextWindowPos
(
ImVec2
(
io
.
DisplaySize
.
x
*
0.5f
,
io
.
DisplaySize
.
y
*
0.7f
),
\
ImGuiCond_Always
,
ImVec2
(
0.5f
,
0.5f
));
ImGui
::
Begin
(
"Select level"
,
NULL
,
window_flags
);
ImGui
::
PushStyleColor
(
ImGuiCol_Text
,
colorYellow
);
ImGui
::
Text
(
"Select Level"
);
if
(
ImGui
::
Button
(
"Level 0"
))
{
if
(
ImGui
::
Button
(
"Level 0"
)
||
detectEnterPress
())
{
//ImGuiCol_ButtonHovered
mainMenuLvlSel
=
0
;
startGame
=
true
;
// Enables the main game loop
exitMenu
=
true
;
// Disables the menu loop
restart
=
true
;
lvlSelect
=
false
;
}
if
(
ImGui
::
Button
(
"Level 1"
))
{
if
(
ImGui
::
Button
(
"Level 1"
)
||
detectEnterPress
()
)
{
mainMenuLvlSel
=
1
;
startGame
=
true
;
// Enables the main game loop
exitMenu
=
true
;
// Disables the menu loop
restart
=
true
;
lvlSelect
=
false
;
}
//
ImGui::
SetItemDefaultFocus
();
ImGui
::
PopStyleColor
();
ImGui
::
SetWindowFontScale
(
2.0f
);
ImGui
::
End
();
}
// Returns true if ENTER key is pressed
bool
ui
::
detectEnterPress
()
{
if
(
ImGui
::
IsItemHovered
(
ImGuiHoveredFlags_RectOnly
)
&&
ImGui
::
IsKeyPressed
(
GLFW_KEY_ENTER
)){
return
true
;
}
else
{
return
false
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment