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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | //1. module name module gamegui; //2. Imports import arc.gui.gui; import arc.math.point; import arc.math.size; import asteroids; import arc.input; //3. Bools, GUI, and GUI code handler bool gamePaused = false; bool showGUI = false; bool showOptions = false; bool showAudio = false; bool showVideo = false; GUI gui; HandleGUI handle; //4. The HandleGUI class class HandleGUI { // main menu code ////////// //5. exit the game void exit() { // exit application arc.input.quit(); } //6. return to current game void returnToGame() { showGUI = false; gamePaused = false; } //7. start a new game void newGame() { asteroids.setupLevel(asteroids.level=1, true); showGUI = false; gamePaused = false; } //8. show the options void options() { showGUI = false; showOptions = true; } // options code /////////// //9. Show video options void video() { showOptions = false; showVideo = true; } //10. Show audio options void audio() { showOptions = false; showAudio = true; } //11. Go back to the previous screen void back() { showOptions = false; showGUI = true; } // audio code ////////// //12. Turn sound on void on() { // turn sound on arc.sound.on(); showAudio = false; gamePaused = false; } //13. Turn sound off void off() { // turn sound off arc.sound.off(); showAudio = false; gamePaused = false; } //14. Go to the previous menu void backAud() { showAudio = false; showOptions = true; } // video code ////////// //15. Resize window to 600x480 resolution void six() { arc.window.resize(600, 480); showVideo = false; gamePaused = false; } //16. Resize window to 800x600 resolution void eight() { arc.window.resize(800, 600); showVideo = false; gamePaused = false; } //17. Resize window to 1024x768 resolution void thousand() { arc.window.resize(1024, 768); showVideo = false; gamePaused = false; } //18. Toggle full screen void fullscreen() { arc.window.toggleFullScreen(); showVideo = false; gamePaused = false; } //19. Go back to the previous screen void backVid() { showVideo = false; showOptions = true; } } //20. load game gui void load() { handle = new HandleGUI; gui = new GUI("astbin/gui/gui.xml"); gui.getLayout("main").setPosition(Size.toPoint(arc.window.getSize/2 - Point(100,100))); gui.getLayout("options").setPosition(Size.toPoint(arc.window.getSize/2 - Point(100,75))); gui.getLayout("video").setPosition(Size.toPoint(arc.window.getSize/2 - Point(100,125))); gui.getLayout("audio").setPosition(Size.toPoint(arc.window.getSize/2 - Point(100,75))); // hook main menu code up gui.getLayout("main").getWidget("exit").clicked.connect(&handle.exit); gui.getLayout("main").getWidget("return").clicked.connect(&handle.returnToGame); gui.getLayout("main").getWidget("newgame").clicked.connect(&handle.newGame); gui.getLayout("main").getWidget("options").clicked.connect(&handle.options); // hook up options code gui.getLayout("options").getWidget("video").clicked.connect(&handle.video); gui.getLayout("options").getWidget("audio").clicked.connect(&handle.audio); gui.getLayout("options").getWidget("back").clicked.connect(&handle.back); // hook up audio code gui.getLayout("audio").getWidget("on").clicked.connect(&handle.on); gui.getLayout("audio").getWidget("off").clicked.connect(&handle.off); gui.getLayout("audio").getWidget("back").clicked.connect(&handle.backAud); // hook up video code gui.getLayout("video").getWidget("600").clicked.connect(&handle.six); gui.getLayout("video").getWidget("800").clicked.connect(&handle.eight); gui.getLayout("video").getWidget("1024").clicked.connect(&handle.thousand); gui.getLayout("video").getWidget("fullscreen").clicked.connect(&handle.fullscreen); gui.getLayout("video").getWidget("back").clicked.connect(&handle.backVid); } ///21. process game gui void process() { if (arc.input.keyPressed(ARC_ESCAPE) && !gamegui.showOptions && !gamegui.showAudio && !gamegui.showVideo) { gamegui.showGUI = !gamegui.showGUI; gamePaused = !gamePaused; } if (showGUI) { gui.getLayout("main").setHide(false); } else { gui.getLayout("main").setHide(true); } if (showOptions) { if (arc.input.keyPressed(ARC_ESCAPE)) { showOptions = false; showGUI = true; } gui.getLayout("options").setHide(false); } else gui.getLayout("options").setHide(true); if (showAudio) { if (arc.input.keyPressed(ARC_ESCAPE)) { showAudio = false; showOptions = true; } gui.getLayout("audio").setHide(false); } else gui.getLayout("audio").setHide(true); if (showVideo) { if (arc.input.keyPressed(ARC_ESCAPE)) { showVideo = false; showOptions = true; } gui.getLayout("video").setHide(false); } else gui.getLayout("video").setHide(true); } |