Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Idle Spaceship Tycoon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Elias Fierke
Idle Spaceship Tycoon
Commits
3a29416d
Commit
3a29416d
authored
1 month ago
by
Elias Fierke
Browse files
Options
Downloads
Patches
Plain Diff
[chore:] various improvements and initial-ESCAPE-Menu
parent
ceedbdc3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/main/java/com/fiewie/idlespaceshiptycoon/GameStage.java
+54
-5
54 additions, 5 deletions
...c/main/java/com/fiewie/idlespaceshiptycoon/GameStage.java
with
54 additions
and
5 deletions
core/src/main/java/com/fiewie/idlespaceshiptycoon/GameStage.java
+
54
−
5
View file @
3a29416d
...
...
@@ -12,6 +12,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import
com.badlogic.gdx.scenes.scene2d.ui.Label
;
import
com.badlogic.gdx.scenes.scene2d.ui.Skin
;
import
com.badlogic.gdx.scenes.scene2d.ui.Table
;
import
com.badlogic.gdx.scenes.scene2d.ui.TextButton
;
import
com.badlogic.gdx.utils.Array
;
import
com.badlogic.gdx.utils.TimeUtils
;
import
com.badlogic.gdx.graphics.Texture
;
...
...
@@ -22,6 +23,7 @@ import com.badlogic.gdx.physics.box2d.ContactImpulse;
import
com.fiewie.idlespaceshiptycoon.gameobjects.SpaceShip
;
import
com.fiewie.idlespaceshiptycoon.logic.SoundManager
;
import
com.fiewie.idlespaceshiptycoon.gameobjects.Enemy
;
import
com.fiewie.idlespaceshiptycoon.Exception.NotImplementedException
;
import
com.fiewie.idlespaceshiptycoon.gameobjects.Background
;
import
com.fiewie.idlespaceshiptycoon.gameobjects.BackgroundManager
;
import
com.fiewie.idlespaceshiptycoon.gameobjects.Bullet
;
...
...
@@ -35,10 +37,12 @@ public class GameStage extends Stage {
private
long
lastSpawnTime
;
private
int
score
;
private
boolean
isGameOver
;
private
boolean
isPaused
=
false
;
private
Table
gameOverMenu
;
public
Label
scoreLabel
;
public
Label
coinLabel
;
public
Image
coinImage
;
private
Table
pausedMenu
;
//public static BackgroundPool background_pool = new BackgroundPool();
...
...
@@ -57,9 +61,9 @@ public class GameStage extends Stage {
addActor
(
scoreLabel
);
coinImage
=
new
Image
(
new
Texture
(
"icon/coin.png"
));
coinImage
.
setPosition
(
getWidth
()
-
coinImage
.
getWidth
()
-
10
,
getHeight
()-
coinImage
.
getHeight
()-
10
);
coinImage
.
setPosition
(
10
,
getHeight
()-
coinImage
.
getHeight
()-
78
);
coinLabel
=
new
Label
(
"0"
,
defaultLabelStyle
);
coinLabel
.
setPosition
(
getWidth
()
-
coinImage
.
getWidth
()
-
coinLabel
.
getWidth
()
-
20
,
getHeight
()-
coinLabel
.
getHeight
()-
1
0
);
coinLabel
.
setPosition
(
coinImage
.
getWidth
()
+
20
,
getHeight
()-
coinLabel
.
getHeight
()-
7
0
);
addActor
(
coinLabel
);
addActor
(
coinImage
);
...
...
@@ -74,7 +78,7 @@ public class GameStage extends Stage {
@Override
public
void
act
(
float
delta
)
{
if
(
isGameOver
)
return
;
// Stoppe das Spiel, wenn Game Over
if
(
isGameOver
||
isPaused
)
return
;
// Stoppe das Spiel, wenn Game Over
super
.
act
(
delta
);
handleInput
();
...
...
@@ -82,6 +86,7 @@ public class GameStage extends Stage {
updateBullets
(
delta
);
checkCollisions
();
handleGameOver
();
handlePaused
();
updateBackground
();
scoreLabel
.
setText
(
"Score: "
+
score
);
}
...
...
@@ -92,7 +97,10 @@ public class GameStage extends Stage {
}
private
void
handleInput
()
{
if
(
isGameOver
)
return
;
// Keine Eingaben nach Game Over
if
(
Gdx
.
input
.
isKeyPressed
(
Input
.
Keys
.
ESCAPE
)){
isPaused
=
!
isPaused
;
// Wert tauschen
}
if
(
isGameOver
||
isPaused
)
return
;
// Keine weiteren Eingaben nach Game Over oder bei pausiertem Spiel
if
(
Gdx
.
input
.
isKeyPressed
(
Input
.
Keys
.
LEFT
)
||
Gdx
.
input
.
isKeyPressed
(
Input
.
Keys
.
A
))
{
ship
.
moveLeft
();
...
...
@@ -143,7 +151,7 @@ public class GameStage extends Stage {
coins
.
removeValue
(
coin
,
true
);
SoundManager
.
getInstance
().
playSound
(
"sounds/coin.mp3"
);
coinLabel
.
setText
(
ship
.
coins
);
coinLabel
.
setPosition
(
getWidth
()
-
coinImage
.
getWidth
()
-
coinLabel
.
getWidth
()
-
20
,
getHeight
()-
coinLabel
.
getHeight
()-
1
0
);
coinLabel
.
setPosition
(
coinImage
.
getWidth
()
+
20
,
getHeight
()-
coinLabel
.
getHeight
()-
7
0
);
}
}
for
(
Enemy
enemy
:
enemies
)
{
...
...
@@ -184,6 +192,47 @@ public class GameStage extends Stage {
}
}
private
void
handlePaused
()
{
if
(
isPaused
)
{
System
.
out
.
println
(
"Paused"
);
showPausedMenu
();
}
else
{
if
(
pausedMenu
!=
null
)
{
pausedMenu
.
remove
();
}
}
}
private
void
showPausedMenu
()
{
pausedMenu
=
new
Table
();
pausedMenu
.
setFillParent
(
true
);
TextureRegionDrawable
buttonTexture
=
new
TextureRegionDrawable
(
new
Texture
(
"button_new.png"
));
TextureRegionDrawable
buttonTextureClicked
=
new
TextureRegionDrawable
(
new
Texture
(
"button_new_click.png"
));
ImageButton
resumeButton
=
new
ImageButton
(
buttonTexture
,
buttonTextureClicked
);
resumeButton
.
addListener
(
event
->
{
if
(
event
.
isHandled
())
{
isPaused
=
false
;
}
return
false
;
});
ImageButton
mainMenuButton
=
new
ImageButton
(
buttonTexture
,
buttonTextureClicked
);
mainMenuButton
.
addListener
(
event
->
{
if
(
event
.
isHandled
()){
throw
new
NotImplementedException
();
}
return
false
;
});
pausedMenu
.
add
(
resumeButton
).
row
();
pausedMenu
.
add
(
mainMenuButton
).
row
();
// Füge das Pausenmenü zur Szene hinzu
addActor
(
pausedMenu
);
}
private
void
showGameOverMenu
()
{
gameOverMenu
=
new
Table
();
gameOverMenu
.
setFillParent
(
true
);
...
...
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