123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- /* main menu, with one start button */
- class WorldMenu extends World {
- /* assets that are available to this world */
- assets() {
- return [
- "images/button_start.png",
- "images/menu_background.png",
- "images/volume_yes.png",
- "images/volume_no.png",
- ];
- }
- /* assets are loaded, initialize interface */
- start() {
- /* array holding the buttons's sprites */
- this.buttons = new Object();
- /* start button */
- this.buttons["start"] = new PIXI.Sprite( loader.resources["images/button_start.png"].texture );
- this.buttons["start"].position.set( width/2 -this.buttons["start"].width/2,
- height -this.buttons["start"].height -20 );
- app.stage.addChild(this.buttons["start"]);
- /* mute button */
- this.buttons["mute"] = new PIXI.Sprite( loader.resources["images/volume_yes.png"].texture );
- this.buttons["mute"].position.set( 10, height -this.buttons["mute"].height -10 );
- this.update_mute_button();
- app.stage.addChild(this.buttons["mute"]);
- /* background image */
- this.bg = new PIXI.Sprite( loader.resources["images/menu_background.png"].texture );
- app.stage.addChildAt(this.bg, 0);
- /* title text */
- let style = new PIXI.TextStyle({
- fill: "#777777",
- stroke: "#210510",
- strokeThickness: 4,
- fontSize: 70,
- fontWeight: "bold",
- });
- this.text = new PIXI.Text("The Collector", style);
- this.text.position.set(width/2, 75);
- this.text.anchor = {x: 0.5, y: 0.5};
- app.stage.addChild(this.text);
- /* main theme, repeat endlessly */
- this.theme = new Audio("audio/collector_main.mp3");
- this.theme.addEventListener('ended', function() {
- this.currentTime = 0;
- this.play();
- }, false);
- if (!muted) {
- this.theme.play();
- }
- /* button sound */
- this.sound_button = new Audio("audio/button_click.mp3");
- /* closing animation */
- this.anim_close = new Animation(15);
- this.next_world = -1;
- /* rectangle to fade out animation */
- this.fade = new PIXI.Graphics();
- this.fade.beginFill(0x000000);
- this.fade.drawRect(0, 0, width, height);
- this.fade.endFill();
- this.fade.alpha = 1;
- app.stage.addChild(this.fade);
- this.anim_close.start();
- } /* start */
- /* called once per frame */
- update() {
- /* closing animation is running */
- if (this.anim_close.update()) {
- /* animation ended */
- if (!this.anim_close.is_running()) {
- /* was closing animation */
- if (this.anim_close.timer == 0) {
- /* stop theme song */
- this.theme.pause();
- /* return new world to be opened */
- return this.next_world;
- }
- /* was opening animation */
- else {
- /* hide rectangle */
- this.fade.visible = false;
- /* update nothing */
- return -1;
- }
- } /* animation end */
- /* make volume fade out and black screen fade in */
- this.theme.volume = this.anim_close.interpolate(1);
- this.fade.alpha = 1 -this.anim_close.interpolate(1);
- /* while world is closing, input and updating are both ignored */
- return -1;
- } /* closing animation */
- /* handle input */
- for (let i = 0; i < input.length; i++) {
- /* left button was clicked */
- if (input[i].which == 1) {
- /* point of click */
- let click = new PIXI.Point(input[i].offsetX, input[i].offsetY);
- /* start button was clicked */
- if (this.buttons["start"].containsPoint(click)) {
- /* make sound */
- if (!muted) {
- this.sound_button.play();
- }
- /* start closing animation and save WorldGame as next world */
- this.anim_close.start();
- this.fade.visible = true;
- this.next_world = world_list.indexOf(WorldGame);
- /* every input can only trigger one button */
- continue;
- } /* start button clicked */
- /* mute button clicked - toggle mute */
- if (this.buttons["mute"].containsPoint(click)){
- if (muted) {
- this.theme.play();
- muted = false;
- }
- else {
- this.theme.pause();
- muted = true;
- }
- /* update mute button graphic */
- this.update_mute_button();
- /* each input can only trigger one button */
- continue;
- } /* mute button clicked */
- } /* left click event */
- } /* for every input */
- } /* update */
- /* changes appearence of mute button based on if the game
- * is muted or not
- */
- update_mute_button() {
- if (muted) {
- this.buttons["mute"].texture =
- loader.resources["images/volume_no.png"].texture;
- }
- else {
- this.buttons["mute"].texture =
- loader.resources["images/volume_yes.png"].texture;
- }
- } /* update mute button */
- }
|