Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TDT4240 Tank Wars
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
Package 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
Snorre Skjellestad Kristiansen
TDT4240 Tank Wars
Commits
03df8ca9
Commit
03df8ca9
authored
2 years ago
by
Magnus Segtnan Skjølberg
Browse files
Options
Downloads
Patches
Plain Diff
(
#18
): add simple screen class for gameplay
parent
794c5294
No related branches found
No related tags found
4 merge requests
!51
Resolve "Adjust cannon angle from touch input"
,
!35
Draft: Resolve "Adjust cannon angle from touch input"
,
!32
Combine hud with gameplay
,
!25
Draft: Resolve "Create UI for gameplay"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/core/src/com/game/tankwars/view/GameScreen.java
+38
-14
38 additions, 14 deletions
frontend/core/src/com/game/tankwars/view/GameScreen.java
with
38 additions
and
14 deletions
frontend/core/src/com/game/tankwars/view/GameScreen.java
+
38
−
14
View file @
03df8ca9
package
com.game.tankwars.view
;
import
com.badlogic.gdx.Gdx
;
import
com.badlogic.gdx.Input
;
import
com.badlogic.gdx.Screen
;
import
com.badlogic.gdx.graphics.OrthographicCamera
;
import
com.badlogic.gdx.graphics.Texture
;
import
com.badlogic.gdx.graphics.g2d.BitmapFont
;
import
com.badlogic.gdx.graphics.g2d.SpriteBatch
;
import
com.badlogic.gdx.math.Vector2
;
import
com.badlogic.gdx.utils.ScreenUtils
;
import
com.badlogic.gdx.utils.viewport.FitViewport
;
import
com.badlogic.gdx.utils.viewport.Viewport
;
import
com.game.tankwars.TankWarsGame
;
import
com.game.tankwars.controller.GameController
;
import
com.game.tankwars.model.Tank
;
public
class
GameScreen
implements
Screen
{
final
TankWarsGame
tankWarsGame
;
OrthographicCamera
camera
;
SpriteBatch
batch
;
Tank
tank
;
public
GameScreen
(
final
TankWarsGame
tankWarsGame
){
this
.
tankWarsGame
=
tankWarsGame
;
camera
=
new
OrthographicCamera
();
private
TankWarsGame
game
;
private
OrthographicCamera
camera
;
private
SpriteBatch
batch
;
private
BitmapFont
font
;
private
Viewport
viewport
;
private
GameController
controller
;
private
GameHud
hud
;
private
Tank
tank
;
public
GameScreen
(
final
TankWarsGame
game
){
this
.
game
=
game
;
batch
=
new
SpriteBatch
();
font
=
game
.
getFont
();
font
.
getData
().
setScale
(
0.55f
);
camera
=
game
.
getCamera
();
tank
=
new
Tank
(
new
Vector2
(
50
,
50
),
new
Texture
(
"tank-khaki.png"
));
viewport
=
new
FitViewport
(
TankWarsGame
.
SCREEN_WIDTH
,
TankWarsGame
.
SCREEN_HEIGHT
,
camera
);
hud
=
new
GameHud
(
viewport
,
batch
);
controller
=
new
GameController
(
this
.
game
,
this
.
hud
,
this
.
tank
);
Gdx
.
input
.
setInputProcessor
(
hud
.
getStage
());
controller
.
handleHudEvents
();
}
@Override
public
void
render
(
float
delta
)
{
if
(
Gdx
.
input
.
isKeyPressed
(
Input
.
Keys
.
D
))
{
if
(
controller
.
isMoveRightTouched
(
))
{
tank
.
moveRight
();
}
if
(
Gdx
.
input
.
isKeyPressed
(
Input
.
Keys
.
A
))
{
if
(
controller
.
isMoveLeftTouched
(
))
{
tank
.
moveLeft
();
}
ScreenUtils
.
clear
(
0
,
0
,
0
,
1
);
batch
.
setProjectionMatrix
(
viewport
.
getCamera
().
combined
);
hud
.
getStage
().
draw
();
batch
.
begin
();
batch
.
draw
(
tank
.
getTexture
(),
tank
.
getPosition
().
x
,
tank
.
getPosition
().
y
,
Tank
.
TANK_WIDTH
,
Tank
.
TANK_HEIGHT
);
batch
.
end
();
...
...
@@ -45,7 +68,7 @@ public class GameScreen implements Screen {
}
@Override
public
void
resize
(
int
width
,
int
height
)
{
viewport
.
update
(
width
,
height
);
}
@Override
...
...
@@ -65,6 +88,7 @@ public class GameScreen implements Screen {
@Override
public
void
dispose
()
{
hud
.
getStage
().
dispose
();
batch
.
dispose
();
}
}
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