-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDifficultyScreen.java
More file actions
147 lines (107 loc) · 5.02 KB
/
DifficultyScreen.java
File metadata and controls
147 lines (107 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.mygdx.game.icicles;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.mygdx.game.icicles.Constants.Difficulty;
/**
* Created by linzhang on 9/11/2017.
*/
public class DifficultyScreen extends InputAdapter implements Screen{
public static final String TAG = DifficultyScreen.class.getName();
IciclesGame game;
ShapeRenderer renderer;
SpriteBatch batch;
FitViewport viewport;
BitmapFont font;
public DifficultyScreen(IciclesGame game) {
this.game = game;
}
@Override
public void show() {
renderer = new ShapeRenderer();
batch = new SpriteBatch();
// TODO: Initialize a FitViewport with the difficulty world size constant
viewport = new FitViewport(Constants.DIFFICULTY_WORLD_SIZE, Constants.DIFFICULTY_WORLD_SIZE);
Gdx.input.setInputProcessor(this);
font = new BitmapFont();
// TODO: Set the font scale using the constant we defined
font.getData().setScale(Constants.DIFFICULTY_LABEL_SCALE);
font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
@Override
public void render(float delta) {
// TODO: Apply the viewport
viewport.apply();
Gdx.gl.glClearColor(Constants.BACKGROUND_COLOR.r, Constants.BACKGROUND_COLOR.g, Constants.BACKGROUND_COLOR.b, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// TODO: Set the ShapeRenderer's projection matrix
renderer.setProjectionMatrix(viewport.getCamera().combined);
// TODO: Use ShapeRenderer to draw the buttons
renderer.begin(ShapeType.Filled);
renderer.setColor(Constants.EASY_COLOR);
renderer.circle(Constants.EASY_CENTER.x, Constants.EASY_CENTER.y, Constants.DIFFICULTY_BUBBLE_RADIUS);
renderer.setColor(Constants.MEDIUM_COLOR);
renderer.circle(Constants.MEDIUM_CENTER.x, Constants.MEDIUM_CENTER.y, Constants.DIFFICULTY_BUBBLE_RADIUS);
renderer.setColor(Constants.HARD_COLOR);
renderer.circle(Constants.HARD_CENTER.x, Constants.HARD_CENTER.y, Constants.DIFFICULTY_BUBBLE_RADIUS);
renderer.end();
// TODO: Set the SpriteBatche's projection matrix
batch.setProjectionMatrix(viewport.getCamera().combined);
// TODO: Use SpriteBatch to draw the labels on the buttons
// HINT: Use GlyphLayout to get vertical centering
batch.begin();
final GlyphLayout easyLayout = new GlyphLayout(font, Constants.EASY_LABEL);
font.draw(batch, Constants.EASY_LABEL, Constants.EASY_CENTER.x, Constants.EASY_CENTER.y + easyLayout.height / 2, 0, Align.center, false);
final GlyphLayout mediumLayout = new GlyphLayout(font, Constants.MEDIUM_LABEL);
font.draw(batch, Constants.MEDIUM_LABEL, Constants.MEDIUM_CENTER.x, Constants.MEDIUM_CENTER.y + mediumLayout.height / 2, 0, Align.center, false);
final GlyphLayout hardLayout = new GlyphLayout(font, Constants.HARD_LABEL);
font.draw(batch, Constants.HARD_LABEL, Constants.HARD_CENTER.x, Constants.HARD_CENTER.y + hardLayout.height / 2, 0, Align.center, false);
batch.end();
}
@Override
public void resize(int width, int height) {
// TODO: Update the viewport
viewport.update(width, height, true);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
batch.dispose();
font.dispose();
renderer.dispose();
}
@Override
public void dispose() {
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
// TODO: Unproject the touch from the screen to the world
Vector2 worldTouch = viewport.unproject(new Vector2(screenX, screenY));
// TODO: Check if the touch was inside a button, and launch the icicles screen with the appropriate difficulty
if (worldTouch.dst(Constants.EASY_CENTER) < Constants.DIFFICULTY_BUBBLE_RADIUS) {
game.showIciclesScreen(Difficulty.EASY);
}
if (worldTouch.dst(Constants.MEDIUM_CENTER) < Constants.DIFFICULTY_BUBBLE_RADIUS) {
game.showIciclesScreen(Difficulty.MEDIUM);
}
if (worldTouch.dst(Constants.HARD_CENTER) < Constants.DIFFICULTY_BUBBLE_RADIUS) {
game.showIciclesScreen(Difficulty.HARD);
}
return true;
}
}