Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
0
01_LibGDX_Screens
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
a.guest
01_LibGDX_Screens
Commits
12c660db
Commit
12c660db
authored
Dec 07, 2017
by
a.guest
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First Commit
parent
4817397b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
346 additions
and
14 deletions
+346
-14
MyGdxGame.java
core/src/com/mygdx/game/MyGdxGame.java
+11
-14
GameOverScreen.java
core/src/screens/GameOverScreen.java
+47
-0
MainGameScreen.java
core/src/screens/MainGameScreen.java
+47
-0
MainMenuScreen.java
core/src/screens/MainMenuScreen.java
+54
-0
OptionsScreen.java
core/src/screens/OptionsScreen.java
+63
-0
ScreenTemplate.java
core/src/screens/ScreenTemplate.java
+124
-0
No files found.
core/src/com/mygdx/game/MyGdxGame.java
View file @
12c660db
package
com
.
mygdx
.
game
;
package
com
.
mygdx
.
game
;
import
com.badlogic.gdx.ApplicationAdapter
;
import
com.badlogic.gdx.Game
;
import
com.badlogic.gdx.Gdx
;
import
com.badlogic.gdx.graphics.GL20
;
import
com.badlogic.gdx.graphics.Texture
;
import
com.badlogic.gdx.graphics.g2d.SpriteBatch
;
import
com.badlogic.gdx.graphics.g2d.SpriteBatch
;
import
com.badlogic.gdx.graphics.g2d.BitmapFont
;
import
screens.MainMenuScreen
;
public
class
MyGdxGame
extends
ApplicationAdapter
{
public
class
MyGdxGame
extends
Game
{
SpriteBatch
batch
;
public
SpriteBatch
batch
;
Texture
img
;
public
BitmapFont
font
;
@Override
@Override
public
void
create
()
{
public
void
create
()
{
batch
=
new
SpriteBatch
();
batch
=
new
SpriteBatch
();
img
=
new
Texture
(
"badlogic.jpg"
);
font
=
new
BitmapFont
();
this
.
setScreen
(
new
MainMenuScreen
(
this
));
}
}
@Override
@Override
public
void
render
()
{
public
void
render
()
{
Gdx
.
gl
.
glClearColor
(
1
,
0
,
0
,
1
);
super
.
render
();
Gdx
.
gl
.
glClear
(
GL20
.
GL_COLOR_BUFFER_BIT
);
batch
.
begin
();
batch
.
draw
(
img
,
0
,
0
);
batch
.
end
();
}
}
@Override
@Override
public
void
dispose
()
{
public
void
dispose
()
{
batch
.
dispose
();
batch
.
dispose
();
img
.
dispose
();
font
.
dispose
();
}
}
}
}
core/src/screens/GameOverScreen.java
0 → 100644
View file @
12c660db
package
screens
;
import
com.badlogic.gdx.Gdx
;
import
com.badlogic.gdx.graphics.GL20
;
import
com.badlogic.gdx.Input.Keys
;
import
com.mygdx.game.*
;
public
class
GameOverScreen
extends
ScreenTemplate
{
public
GameOverScreen
(
final
MyGdxGame
game
)
{
super
(
game
);
}
public
void
process_input
(
float
delta
)
{
super
.
process_input
(
delta
);
if
(
Gdx
.
input
.
isKeyPressed
(
Keys
.
F1
)&&
enough_time_passed
())
{
game_handle
.
setScreen
(
new
MainMenuScreen
(
game_handle
));
dispose
();
}
}
public
void
update
(
float
delta
)
{
}
public
void
render_me
(
float
delta
)
{
Gdx
.
gl
.
glClearColor
(
0
,
0
,
0.2f
,
1
);
Gdx
.
gl
.
glClear
(
GL20
.
GL_COLOR_BUFFER_BIT
);
camera
.
update
();
game_handle
.
batch
.
setProjectionMatrix
(
camera
.
combined
);
game_handle
.
batch
.
begin
();
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"Game Over! "
,
100
,
150
);
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"Press F1 to play again"
,
100
,
100
);
game_handle
.
batch
.
end
();
}
}
core/src/screens/MainGameScreen.java
0 → 100644
View file @
12c660db
package
screens
;
import
com.badlogic.gdx.Gdx
;
import
com.badlogic.gdx.graphics.GL20
;
import
com.badlogic.gdx.Input.Keys
;
import
com.mygdx.game.*
;
public
class
MainGameScreen
extends
ScreenTemplate
{
public
MainGameScreen
(
final
MyGdxGame
game
)
{
super
(
game
);
}
public
void
process_input
(
float
delta
)
{
super
.
process_input
(
delta
);
if
(
Gdx
.
input
.
isKeyPressed
(
Keys
.
F1
)&&
enough_time_passed
())
{
game_handle
.
setScreen
(
new
GameOverScreen
(
game_handle
));
dispose
();
}
}
public
void
update
(
float
delta
)
{
}
public
void
render_me
(
float
delta
)
{
Gdx
.
gl
.
glClearColor
(
0
,
0
,
0.2f
,
1
);
Gdx
.
gl
.
glClear
(
GL20
.
GL_COLOR_BUFFER_BIT
);
camera
.
update
();
game_handle
.
batch
.
setProjectionMatrix
(
camera
.
combined
);
game_handle
.
batch
.
begin
();
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"oooh super sexy game play!! "
,
100
,
150
);
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"Press F1 to end game"
,
100
,
100
);
game_handle
.
batch
.
end
();
}
}
core/src/screens/MainMenuScreen.java
0 → 100644
View file @
12c660db
package
screens
;
import
com.badlogic.gdx.Gdx
;
import
com.badlogic.gdx.graphics.GL20
;
import
com.badlogic.gdx.Input.Keys
;
import
com.mygdx.game.*
;
public
class
MainMenuScreen
extends
ScreenTemplate
{
public
MainMenuScreen
(
final
MyGdxGame
game
)
{
super
(
game
);
}
public
void
process_input
(
float
delta
)
{
super
.
process_input
(
delta
);
if
(
Gdx
.
input
.
isTouched
())
{
game_handle
.
setScreen
(
new
MainGameScreen
(
game_handle
));
dispose
();
}
if
(
Gdx
.
input
.
isKeyPressed
(
Keys
.
F1
)&&
enough_time_passed
())
{
game_handle
.
setScreen
(
new
MainGameScreen
(
game_handle
));
dispose
();
}
}
public
void
update
(
float
delta
)
{
}
public
void
render_me
(
float
delta
)
{
Gdx
.
gl
.
glClearColor
(
0
,
0
,
0.2f
,
1
);
Gdx
.
gl
.
glClear
(
GL20
.
GL_COLOR_BUFFER_BIT
);
camera
.
update
();
game_handle
.
batch
.
setProjectionMatrix
(
camera
.
combined
);
game_handle
.
batch
.
begin
();
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"Welcome to My Sexy Game!!! "
,
100
,
150
);
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"Tap anywhere to begin!, Esc for options"
,
100
,
100
);
game_handle
.
batch
.
end
();
}
}
core/src/screens/OptionsScreen.java
0 → 100644
View file @
12c660db
package
screens
;
import
com.badlogic.gdx.Gdx
;
import
com.badlogic.gdx.graphics.GL20
;
import
com.badlogic.gdx.Input.Keys
;
import
com.mygdx.game.*
;
public
class
OptionsScreen
extends
ScreenTemplate
{
public
ScreenTemplate
previousScreen
;
boolean
ESC_PRESSED
=
false
;
public
OptionsScreen
(
final
MyGdxGame
game
,
ScreenTemplate
prev_screen
)
{
super
(
game
);
previousScreen
=
prev_screen
;
}
public
void
process_input
(
float
delta
)
{
// do not call super.process_input(delta) here
// its there to call switch to options screen
// and we are already there!
if
(
Gdx
.
input
.
isTouched
())
{
game_handle
.
setScreen
(
new
MainGameScreen
(
game_handle
));
dispose
();
}
if
(
Gdx
.
input
.
isKeyPressed
(
Keys
.
F1
)&&
enough_time_passed
())
{
game_handle
.
setScreen
(
new
MainGameScreen
(
game_handle
));
dispose
();
}
if
(
Gdx
.
input
.
isKeyPressed
(
Keys
.
ESCAPE
)&&
enough_time_passed
())
{
previousScreen
.
set_start_time
();
game_handle
.
setScreen
(
previousScreen
);
dispose
();
}
}
public
void
update
(
float
delta
)
{
}
public
void
render_me
(
float
delta
)
{
Gdx
.
gl
.
glClearColor
(
0
,
0
,
0.2f
,
1
);
Gdx
.
gl
.
glClear
(
GL20
.
GL_COLOR_BUFFER_BIT
);
camera
.
update
();
game_handle
.
batch
.
setProjectionMatrix
(
camera
.
combined
);
game_handle
.
batch
.
begin
();
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"Options Screen"
,
100
,
150
);
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"Press escape to return"
,
100
,
100
);
game_handle
.
batch
.
end
();
}
}
core/src/screens/ScreenTemplate.java
0 → 100644
View file @
12c660db
package
screens
;
import
com.badlogic.gdx.Gdx
;
import
com.badlogic.gdx.Screen
;
import
com.badlogic.gdx.graphics.GL20
;
import
com.badlogic.gdx.graphics.OrthographicCamera
;
import
com.badlogic.gdx.Input.Keys
;
import
com.mygdx.game.*
;
import
com.badlogic.gdx.utils.TimeUtils
;
public
class
ScreenTemplate
implements
Screen
{
public
MyGdxGame
game_handle
;
public
OrthographicCamera
camera
;
public
long
StartTime
;
public
final
long
ENOUGH_TIME
=
250
;
// 250ms
public
ScreenTemplate
()
{
game_handle
=
null
;
}
public
ScreenTemplate
(
final
MyGdxGame
game
)
{
game_handle
=
game
;
camera
=
new
OrthographicCamera
();
camera
.
setToOrtho
(
false
,
800
,
600
);
set_start_time
();
}
@Override
public
void
show
()
{
// TODO Auto-generated method stub
}
public
long
elapsed_time
()
{
long
NowTime
=
TimeUtils
.
nanosToMillis
(
TimeUtils
.
nanoTime
());
return
(
NowTime
-
StartTime
);
}
public
boolean
enough_time_passed
()
{
if
(
elapsed_time
()>
ENOUGH_TIME
)
return
true
;
else
return
false
;
}
public
void
set_start_time
()
{
StartTime
=
TimeUtils
.
nanosToMillis
(
TimeUtils
.
nanoTime
());
}
public
void
process_input
(
float
delta
)
{
if
(
Gdx
.
input
.
isKeyPressed
(
Keys
.
ESCAPE
)&&
enough_time_passed
())
{
game_handle
.
setScreen
(
new
OptionsScreen
(
game_handle
,
this
));
}
}
public
void
update
(
float
delta
)
{
}
public
void
render_me
(
float
delta
)
{
Gdx
.
gl
.
glClearColor
(
0
,
0
,
0.2f
,
1
);
Gdx
.
gl
.
glClear
(
GL20
.
GL_COLOR_BUFFER_BIT
);
camera
.
update
();
game_handle
.
batch
.
setProjectionMatrix
(
camera
.
combined
);
game_handle
.
batch
.
begin
();
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"Game Over! "
,
100
,
150
);
game_handle
.
font
.
draw
(
game_handle
.
batch
,
"Press F1 to play again"
,
100
,
100
);
game_handle
.
batch
.
end
();
}
@Override
public
void
render
(
float
delta
)
{
process_input
(
delta
);
update
(
delta
);
render_me
(
delta
);
}
@Override
public
void
resize
(
int
width
,
int
height
)
{
// TODO Auto-generated method stub
}
@Override
public
void
pause
()
{
// TODO Auto-generated method stub
}
@Override
public
void
resume
()
{
// TODO Auto-generated method stub
}
@Override
public
void
hide
()
{
// TODO Auto-generated method stub
}
@Override
public
void
dispose
()
{
// TODO Auto-generated method stub
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment