Skip to content

Commit 08775a2

Browse files
committed
Add scoreboard
Scoreboard can be displayed by clicking tab key
1 parent 55a4df3 commit 08775a2

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

blastback_client/src/com/blastback/appstates/InputManagerAppState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ private void initKeys()
154154
_inputManager.addMapping("1", new KeyTrigger(KeyInput.KEY_1));
155155
_inputManager.addMapping("2", new KeyTrigger(KeyInput.KEY_2));
156156
_inputManager.addMapping("3", new KeyTrigger(KeyInput.KEY_3));
157+
_inputManager.addMapping("Tab", new KeyTrigger(KeyInput.KEY_TAB));
157158

158159
_inputManager.addMapping("MouseMoved", new MouseAxisTrigger(MouseInput.AXIS_X, true),
159160
new MouseAxisTrigger(MouseInput.AXIS_X, false),
@@ -174,7 +175,7 @@ private void registerListener(InputListener listener)
174175
_inputManager.addListener(listener, "MouseMoved");
175176
} else if (listener instanceof ActionListener)
176177
{
177-
_inputManager.addListener(listener, "Right", "Left", "Up", "Down", "Shoot","1","2","3");
178+
_inputManager.addListener(listener, "Right", "Left", "Up", "Down", "Shoot", "1", "2", "3", "Tab");
178179
}
179180
}
180181

blastback_client/src/com/blastback/appstates/PlayerAppState.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.blastback.GameClient;
99
import com.blastback.controls.CharacterHealthControl;
10+
import com.blastback.controls.GameInterfaceControl;
1011
import com.blastback.controls.PlayerInputControl;
1112
import com.blastback.controls.PlayerMovementControl;
1213
import com.blastback.controls.PlayerNetworkPresenceControl;
@@ -40,6 +41,7 @@ public class PlayerAppState extends BaseAppState
4041
private InputManagerAppState _inputAppState;
4142
private BulletAppState _bulletAppState;
4243
private NetworkAppState _networkAppState;
44+
private GUIAppState _guiAppState;
4345

4446
private Spatial _player;
4547
private PlayerInputControl _inputControl;
@@ -57,7 +59,8 @@ protected void initialize(Application app)
5759
_inputAppState = _app.getStateManager().getState(InputManagerAppState.class);
5860
_bulletAppState = _app.getStateManager().getState(BulletAppState.class);
5961
_networkAppState = _app.getStateManager().getState(NetworkAppState.class);
60-
62+
_guiAppState = _app.getStateManager().getState(GUIAppState.class);
63+
6164
initListeners();
6265
initPlayer();
6366
}
@@ -118,6 +121,7 @@ private void initPlayer()
118121
// Add controls to spatials
119122
_player.addControl(_charControl);
120123
_player.addControl(new PlayerMovementControl());
124+
_player.addControl(new GameInterfaceControl(_guiAppState));
121125
_player.addControl(new PlayerShootingControl(new Vector3f(0f, 0f, -1.5f))); //to adjust
122126
_healthControl = new CharacterHealthControl();
123127
_player.addControl(_healthControl);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.blastback.controls;
2+
3+
import com.blastback.appstates.GUIAppState;
4+
import com.jme3.renderer.RenderManager;
5+
import com.jme3.renderer.ViewPort;
6+
import com.jme3.scene.control.AbstractControl;
7+
8+
9+
public class GameInterfaceControl extends AbstractControl
10+
{
11+
private GUIAppState _guiAppState;
12+
13+
public GameInterfaceControl(GUIAppState guiAppState)
14+
{
15+
this._guiAppState = guiAppState;
16+
}
17+
18+
public GUIAppState getGui()
19+
{
20+
return _guiAppState;
21+
}
22+
23+
24+
25+
@Override
26+
protected void controlUpdate(float tpf)
27+
{
28+
}
29+
30+
@Override
31+
protected void controlRender(RenderManager rm, ViewPort vp)
32+
{
33+
}
34+
35+
}

blastback_client/src/com/blastback/controls/PlayerInputControl.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
/*
2-
* To change this license header, choose License Headers in Project Properties.
3-
* To change this template file, choose Tools | Templates
4-
* and open the template in the editor.
5-
*/
61
package com.blastback.controls;
72

83
import com.blastback.appstates.InputManagerAppState;
94
import com.jme3.input.controls.ActionListener;
105
import com.jme3.input.controls.AnalogListener;
11-
import com.jme3.math.Vector2f;
126
import com.jme3.math.Vector3f;
137
import com.jme3.renderer.RenderManager;
148
import com.jme3.renderer.ViewPort;
159
import com.jme3.scene.Spatial;
1610
import com.jme3.scene.control.AbstractControl;
1711

18-
/**
19-
*
20-
* @author Eryk
21-
*/
2212
public class PlayerInputControl extends AbstractControl
2313
{
24-
2514
private ActionListener _keyboardListener;
2615
private AnalogListener _mouseListener;
2716
private PlayerMovementControl _movementControl;
2817
private PlayerShootingControl _shootingControl;
18+
private GameInterfaceControl _gameInterfaceControl;
19+
2920

3021
public PlayerInputControl()
3122
{
@@ -40,6 +31,7 @@ public void setSpatial(Spatial spatial)
4031
{
4132
_movementControl = spatial.getControl(PlayerMovementControl.class);
4233
_shootingControl = spatial.getControl(PlayerShootingControl.class);
34+
_gameInterfaceControl = spatial.getControl(GameInterfaceControl.class);
4335
}
4436
}
4537

@@ -77,8 +69,12 @@ public void onAction(String name, boolean keyPressed, float tpf)
7769
if (name.equals("Down"))
7870
{
7971
_movementControl.setDown(keyPressed);
80-
8172
}
73+
if (name.equals("Tab"))
74+
{
75+
_gameInterfaceControl.getGui().displayScoreboard(keyPressed);
76+
}
77+
8278
if (name.equals("Shoot"))
8379
{
8480
_shootingControl.shoot(keyPressed);

0 commit comments

Comments
 (0)