Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. Code
  2. RH
  3.  
  4. Rachel Hannigan
  5. Fri 16/11/2018 15:36
  6. To:
  7. Ryan McKeever;
  8. package uk.ac.qub.eeecs.game;
  9.  
  10. import android.graphics.Color;
  11.  
  12. import java.util.List;
  13.  
  14. import uk.ac.qub.eeecs.gage.Game;
  15. import uk.ac.qub.eeecs.gage.engine.AssetManager;
  16. import uk.ac.qub.eeecs.gage.engine.ElapsedTime;
  17. import uk.ac.qub.eeecs.gage.engine.graphics.IGraphics2D;
  18. import uk.ac.qub.eeecs.gage.engine.input.Input;
  19. import uk.ac.qub.eeecs.gage.engine.input.TouchEvent;
  20. import uk.ac.qub.eeecs.gage.ui.PushButton;
  21. import uk.ac.qub.eeecs.gage.world.GameScreen;
  22. import uk.ac.qub.eeecs.game.boardGameDemo.BoardGameDemoScreen;
  23. import uk.ac.qub.eeecs.game.miscDemos.DemoMenuScreen;
  24. import uk.ac.qub.eeecs.game.platformDemo.PlatformDemoScreen;
  25. import uk.ac.qub.eeecs.game.spaceDemo.SpaceshipDemoScreen;
  26. import uk.ac.qub.eeecs.game.PerformanceScreen;
  27. /**
  28. * An exceedingly basic menu screen with a couple of touch buttons
  29. *
  30. * @version 1.0
  31. */
  32. public class MenuScreen extends GameScreen {
  33.  
  34. // /////////////////////////////////////////////////////////////////////////
  35. // Properties
  36. // /////////////////////////////////////////////////////////////////////////
  37.  
  38. /**
  39. * Define the buttons for playing the 'games'
  40. */
  41. private PushButton mSpaceshipDemoButton;
  42. private PushButton mPlatformDemoButton;
  43. private PushButton mCardDemoButton;
  44. private PushButton mDemosButton;
  45. private PushButton mPerformanceDemoButton;
  46. private PushButton mOptionsDemoButton;
  47.  
  48. // /////////////////////////////////////////////////////////////////////////
  49. // Constructors
  50. // /////////////////////////////////////////////////////////////////////////
  51.  
  52. /**
  53. * Create a simple menu screen
  54. *
  55. * @param game Game to which this screen belongs
  56. */
  57. public MenuScreen(Game game) {
  58. super("MenuScreen", game);
  59.  
  60. // Load in the bitmaps used on the main menu screen
  61. AssetManager assetManager = mGame.getAssetManager();
  62. assetManager.loadAndAddBitmap("PerformanceDemoIcon", "img/PerformanceDemoIcon.png");
  63. assetManager.loadAndAddBitmap("PerformanceDemoIconSelected", "img/PerformanceDemoIconSelected.png");
  64. assetManager.loadAndAddBitmap("SpaceDemoIcon", "img/SpaceDemoIcon.png");
  65. assetManager.loadAndAddBitmap("SpaceDemoIconSelected", "img/SpaceDemoIconSelected.png");
  66. assetManager.loadAndAddBitmap("CardDemoIcon", "img/CardDemoIcon.png");
  67. assetManager.loadAndAddBitmap("CardDemoIconSelected", "img/CardDemoIconSelected.png");
  68. assetManager.loadAndAddBitmap("PlatformDemoIcon", "img/PlatformDemoIcon.png");
  69. assetManager.loadAndAddBitmap("PlatformDemoIconSelected", "img/PlatformDemoIconSelected.png");
  70. assetManager.loadAndAddBitmap("DemosIcon", "img/DemosIcon.png");
  71. assetManager.loadAndAddBitmap("DemosIconSelected", "img/DemosIconSelected.png");
  72. assetManager.loadAndAddSound("JumpSound", "sound/JumpSound.mp3");
  73. assetManager.loadAndAddSound("Swoosh", "sound/Swoosh.mp3");
  74. assetManager.loadAndAddBitmap("worldMap", "img/worldmap.png");
  75.  
  76. //add options button image
  77. assetManager.loadAndAddBitmap("optionsDemoIcon", "img/optionsBTN.png");
  78. assetManager.loadAndAddBitmap("optionsDemoSelected", "img/optionsBTNSelected.png");
  79.  
  80. // Define the spacing that will be used to position the buttons
  81. int spacingX = (int)mDefaultLayerViewport.getWidth() / 7;
  82. int spacingY = (int)mDefaultLayerViewport.getHeight() / 3;
  83.  
  84. // Create the trigger buttons
  85. mSpaceshipDemoButton = new PushButton(
  86. spacingX * 0.50f, spacingY * 1.5f, spacingX, spacingY,
  87. "SpaceDemoIcon", "SpaceDemoIconSelected",this);
  88. mSpaceshipDemoButton.setPlaySounds(true, true);
  89. mPerformanceDemoButton = new PushButton(
  90. spacingX * 1.83f, spacingY * 1.5f, spacingX, spacingY,
  91. "PerformanceDemoIcon", "PerformanceDemoIconSelected", this);
  92. mPerformanceDemoButton.setPlaySounds(true, true);
  93. mPlatformDemoButton = new PushButton(
  94. spacingX * 3.17f, spacingY * 1.5f, spacingX, spacingY,
  95. "PlatformDemoIcon", "PlatformDemoIconSelected", this);
  96.  
  97. mPlatformDemoButton.setPlaySounds(true, true);
  98. mCardDemoButton = new PushButton(
  99. spacingX * 4.50f, spacingY * 1.5f, spacingX, spacingY,
  100. "CardDemoIcon", "CardDemoIconSelected", this);
  101. mCardDemoButton.setPlaySounds(true, true);
  102. mDemosButton = new PushButton(
  103. spacingX * 5.84f, spacingY * 1.5f, spacingX, spacingY,
  104. "DemosIcon", "DemosIconSelected", this);
  105. mDemosButton.setPlaySounds(true, true);
  106. mOptionsDemoButton = new PushButton(
  107. spacingX * 6.51f, spacingY * 0.4f, spacingX, spacingY,
  108. "optionsDemoIcon", "optionsDemoSelected", this);
  109. }
  110.  
  111. // /////////////////////////////////////////////////////////////////////////
  112. // Methods
  113. // /////////////////////////////////////////////////////////////////////////
  114.  
  115. /**
  116. * Update the menu screen
  117. *
  118. * @param elapsedTime Elapsed time information
  119. */
  120. @Override
  121. public void update(ElapsedTime elapsedTime) {
  122.  
  123. // Process any touch events occurring since the update
  124. Input input = mGame.getInput();
  125.  
  126. List<TouchEvent> touchEvents = input.getTouchEvents();
  127. if (touchEvents.size() > 0) {
  128.  
  129. // Update each button and transition if needed
  130. mSpaceshipDemoButton.update(elapsedTime);
  131. mCardDemoButton.update(elapsedTime);
  132. mPlatformDemoButton.update(elapsedTime);
  133. mDemosButton.update(elapsedTime);
  134. mPerformanceDemoButton.update(elapsedTime);
  135. mOptionsDemoButton.update(elapsedTime);
  136.  
  137. if (mSpaceshipDemoButton.isPushTriggered())
  138. mGame.getScreenManager().addScreen(new SpaceshipDemoScreen(mGame));
  139. else if (mCardDemoButton.isPushTriggered())
  140. mGame.getScreenManager().addScreen(new BoardGameDemoScreen(mGame));
  141. else if (mPlatformDemoButton.isPushTriggered())
  142. mGame.getScreenManager().addScreen(new PlatformDemoScreen(mGame));
  143. else if (mDemosButton.isPushTriggered())
  144. mGame.getScreenManager().addScreen(new DemoMenuScreen(mGame));
  145. else if (mPerformanceDemoButton.isPushTriggered())
  146. mGame.getScreenManager().addScreen(new PerformanceScreen(mGame));
  147. else if (mOptionsDemoButton.isPushTriggered())
  148. mGame.getScreenManager().addScreen(new OptionsScreen(mGame));
  149. }
  150. }
  151.  
  152. /**
  153. * Draw the menu screen
  154. *
  155. * @param elapsedTime Elapsed time information
  156. * @param graphics2D Graphics instance
  157. */
  158. @Override
  159. public void draw(ElapsedTime elapsedTime, IGraphics2D graphics2D) {
  160.  
  161. // Clear the screen and draw the buttons
  162. graphics2D.clear(Color.WHITE);
  163.  
  164. mSpaceshipDemoButton.draw(elapsedTime, graphics2D, mDefaultLayerViewport, mDefaultScreenViewport);
  165. mPlatformDemoButton.draw(elapsedTime, graphics2D, mDefaultLayerViewport, mDefaultScreenViewport);
  166. mDemosButton.draw(elapsedTime, graphics2D, mDefaultLayerViewport, mDefaultScreenViewport);
  167. mCardDemoButton.draw(elapsedTime, graphics2D, mDefaultLayerViewport, mDefaultScreenViewport);
  168. mPerformanceDemoButton.draw(elapsedTime, graphics2D, mDefaultLayerViewport, mDefaultScreenViewport);
  169. mOptionsDemoButton.draw(elapsedTime, graphics2D, mDefaultLayerViewport, mDefaultScreenViewport);
  170.  
  171. }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement