1212import javax .swing .JFrame ;
1313import javax .swing .JOptionPane ;
1414
15+ import org .apache .commons .lang3 .text .WordUtils ;
16+
1517import com .redomar .game .entities .Player ;
1618import com .redomar .game .entities .PlayerMP ;
1719import com .redomar .game .gfx .Screen ;
@@ -28,35 +30,37 @@ public class Game extends Canvas implements Runnable {
2830 private static final long serialVersionUID = 1L ;
2931
3032 // Setting the size and name of the frame/canvas
31- public static final int WIDTH = 160 ;
32- public static final int HEIGHT = (WIDTH / 3 * 2 );
33- public static final int SCALE = 3 ;
34- public static final String NAME = "Game" ;
35- public static Game game ;
33+ private static final int WIDTH = 160 ;
34+ private static final int HEIGHT = (WIDTH / 3 * 2 );
35+ private static final int SCALE = 3 ;
36+ private static final String NAME = "Game" ;
37+ private static Game game ;
3638 private static int Jdata_Host ;
3739 private static String Jdata_UserName = "" ;
3840 private static String Jdata_IP = "127.0.0.1" ;
3941
4042 private JFrame frame ;
4143
42- public boolean running = false ;
43- public int tickCount = 0 ;
44+ private boolean running = false ;
45+ private int tickCount = 0 ;
4446
4547 private BufferedImage image = new BufferedImage (WIDTH , HEIGHT ,
4648 BufferedImage .TYPE_INT_RGB );
4749 private int [] pixels = ((DataBufferInt ) image .getRaster ().getDataBuffer ())
4850 .getData ();
4951 private int [] colours = new int [6 * 6 * 6 ];
5052
53+ private BufferedImage image2 = new BufferedImage (WIDTH , HEIGHT - 30 , BufferedImage .TYPE_INT_RGB );
5154 private Screen screen ;
5255 private InputHandler input ;
5356 private WindowHandler window ;
5457 private LevelHandler level ;
5558 private Player player ;
5659 private Music music = new Music ();
57- public Thread musicThread = new Thread (music );
60+ private Thread musicThread = new Thread (music );
61+ private String nowPlaying = "Playing Music" ;
5862
59- public boolean notActive = true ;
63+ private boolean notActive = true ;
6064
6165 private GameClient socketClient ;
6266 private GameServer socketServer ;
@@ -78,7 +82,7 @@ public Game() {
7882 }
7983
8084 public void init () {
81- game = this ;
85+ setGame ( this ) ;
8286 int index = 0 ;
8387 for (int r = 0 ; r < 6 ; r ++) {
8488 for (int g = 0 ; g < 6 ; g ++) {
@@ -174,7 +178,7 @@ public void run() {
174178 }
175179
176180 public void tick () {
177- tickCount ++ ;
181+ setTickCount ( getTickCount () + 1 ) ;
178182 getLevel ().tick ();
179183 }
180184
@@ -185,8 +189,8 @@ public void render() {
185189 return ;
186190 }
187191
188- int xOffset = getPlayer ().x - (screen .width / 2 );
189- int yOffset = getPlayer ().y - (screen .height / 2 );
192+ int xOffset = getPlayer ().x - (screen .getWidth () / 2 );
193+ int yOffset = getPlayer ().y - (screen .getHeight () / 2 );
190194
191195 getLevel ().renderTiles (screen , xOffset , yOffset );
192196
@@ -199,9 +203,9 @@ public void render() {
199203
200204 getLevel ().renderEntities (screen );
201205
202- for (int y = 0 ; y < screen .height ; y ++) {
203- for (int x = 0 ; x < screen .width ; x ++) {
204- int colourCode = screen .pixels [x + y * screen .width ];
206+ for (int y = 0 ; y < screen .getHeight () ; y ++) {
207+ for (int x = 0 ; x < screen .getWidth () ; x ++) {
208+ int colourCode = screen .getPixels () [x + y * screen .getWidth () ];
205209 if (colourCode < 255 ) {
206210 pixels [x + y * WIDTH ] = colours [colourCode ];
207211 }
@@ -212,18 +216,27 @@ public void render() {
212216 int musicOption = JOptionPane .showConfirmDialog (this , "You are about to turn on music and can be VERY loud" , "Music Options" , 2 , 2 );
213217 if (musicOption == 0 ){
214218 musicThread .start ();
215- notActive = false ;
219+ notActive = false ;
216220 } else {
217221 System .out .println ("Canceled" );
218222 input .PlayMusic = false ;
219223 }
220224 }
221225
222-
223226 Graphics g = bs .getDrawGraphics ();
224227
225228 g .drawRect (0 , 0 , getWidth (), getHeight ());
226- g .drawImage (image , 0 , 0 , getWidth (), getHeight (), null );
229+ g .drawImage (image , 0 , 0 , getWidth (), getHeight ()-30 , null );
230+ // Font.render("Hi", screen, 0, 0, Colours.get(-1, -1, -1, 555), 1);
231+ g .drawImage (image2 , 0 , getHeight ()-30 , getWidth (), getHeight (), null );
232+ g .setColor (Color .WHITE );
233+ g .drawString ("Welcome " +WordUtils .capitalizeFully (player .getUsername ()), 0 , getHeight ()-19 );
234+ if (notActive == true ){
235+ g .drawString ("MUSIC is OFF | press 'M' to start" , 0 , getHeight ()-8 );
236+ } else {
237+ g .drawString ("MUSIC is ON | You cannot turn off the music" , 0 , getHeight ()-8 );
238+ g .drawString (nowPlaying , (getWidth () - nowPlaying .length ()) - (120 + nowPlaying .length ()), getHeight () - 20 );
239+ }
227240 g .dispose ();
228241 bs .show ();
229242 }
@@ -251,15 +264,15 @@ public static void main(String[] args) {
251264 Thread .sleep (750 );
252265 splash .setProgress (92 , "Aquring data: Multiplayer" );
253266 Thread .sleep (200 );
254- Jdata_Host = JOptionPane .showConfirmDialog (game , "Do you want to be the HOST?" );
267+ Jdata_Host = JOptionPane .showConfirmDialog (getGame () , "Do you want to be the HOST?" );
255268 if (Jdata_Host == 1 ){
256- Jdata_IP = JOptionPane .showInputDialog (game , "Enter the name \n leave blank for local" );
269+ Jdata_IP = JOptionPane .showInputDialog (getGame () , "Enter the name \n leave blank for local" );
257270 }
258271 Thread .sleep (200 );
259272 splash .setProgress (95 , "Aquring data: Username" );
260273 Thread .sleep (200 );
261274 splash .setProgress (96 , "Initalizing as Server:Host" );
262- Jdata_UserName = JOptionPane .showInputDialog (game , "Enter a name" );
275+ Jdata_UserName = JOptionPane .showInputDialog (getGame () , "Enter a name" );
263276 splash .setProgress (97 , "Connecting as" + Jdata_UserName );
264277 Thread .sleep (500 );
265278 splash .splashOff ();
@@ -310,4 +323,28 @@ public void setWindow(WindowHandler window) {
310323 this .window = window ;
311324 }
312325
326+ public String getNowPlaying () {
327+ return nowPlaying ;
328+ }
329+
330+ public void setNowPlaying (String nowPlaying ) {
331+ this .nowPlaying = nowPlaying ;
332+ }
333+
334+ public int getTickCount () {
335+ return tickCount ;
336+ }
337+
338+ public void setTickCount (int tickCount ) {
339+ this .tickCount = tickCount ;
340+ }
341+
342+ public static Game getGame () {
343+ return game ;
344+ }
345+
346+ public static void setGame (Game game ) {
347+ Game .game = game ;
348+ }
349+
313350}
0 commit comments