Added menu scene

This commit is contained in:
Bram van der Veen 2014-07-05 22:41:30 +02:00
parent a65c22d2de
commit 21e68289a8
6 changed files with 108 additions and 5 deletions

View file

@ -4,8 +4,8 @@
<app file="Main" main="Main" path="bin" /> <app file="Main" main="Main" path="bin" />
<window fps="60" background="0x000000" /> <window fps="120þ" background="0x000000" />
<window width="360" height="640" resizable="true" if="linux" /> <window width="360" height="640" resizable="false" unless="mobile" />
<window orientation="portrait" fullscreen="true" if="mobile" /> <window orientation="portrait" fullscreen="true" if="mobile" />
<window orientation="portrait" vsync="true" antialiasing="0" if="cpp" /> <window orientation="portrait" vsync="true" antialiasing="0" if="cpp" />

View file

@ -15,7 +15,8 @@ class Main extends Engine
HXP.resize(360, 640); HXP.resize(360, 640);
#end #end
HXP.scene = new MainScene(); // HXP.scene = new MainScene();
HXP.scene = new MenuScene();
} }
public static function main() { new Main(); } public static function main() { new Main(); }

54
src/MenuButton.hx Normal file
View file

@ -0,0 +1,54 @@
import com.haxepunk.Entity;
import com.haxepunk.graphics.Image;
import com.haxepunk.graphics.Text;
import com.haxepunk.HXP;
import com.haxepunk.utils.Input;
import com.haxepunk.utils.Touch;
import com.haxepunk.utils.Key;
import MainScene;
class MenuButton extends Entity {
public function new (x:Float, y:Float, txt:String) {
super(x, y);
sprite = new Image("graphics/buttonGreen.png");
sprite.scale = 2;
setHitbox(sprite.width * 2, sprite.height * 2);
text = new Text(txt);
text.color = 0x000000;
text.size = 40;
text.centerOrigin();
sprite.centerOrigin();
this.centerOrigin();
this.addGraphic(sprite);
this.addGraphic(text);
Input.define("enter", [Key.ENTER, Key.SPACE]);
}
public override function update() {
Input.touchPoints(onTouch);
if (Input.check("enter")) {
HXP.scene = new MainScene();
}
}
private function onTouch(touch:Touch) {
if ((touch.x > this.left && touch.x < this.right) && (touch.y > this.top && touch.y < this.bottom)) {
HXP.scene = new MainScene();
}
}
private var txt:String;
private var sprite:Image;
public var text:Text;
}

22
src/MenuScene.hx Normal file
View file

@ -0,0 +1,22 @@
import com.haxepunk.Scene;
import com.haxepunk.HXP;
import com.haxepunk.graphics.Text;
import MenuButton;
import Title;
class MenuScene extends Scene {
public override function begin() {
var play = new MenuButton(HXP.width / 2, HXP.height / 2, "Play!");
var title = new Title(HXP.width / 2, (HXP.height / 2) - 400);
var copy = new Text("By Bram \"96AA48\" van der Veen, 2014", HXP.width / 2, HXP.height - 50);
copy.size = 22;
copy.centerOrigin();
add(title);
add(play);
addGraphic(copy);
}
}

View file

@ -41,7 +41,7 @@ class Player extends Entity {
this.y -= moveSpeed; this.y -= moveSpeed;
} }
if (Input.pressed("shoot")) { if (Input.check("shoot")) {
shoot(); shoot();
} }
@ -63,7 +63,7 @@ class Player extends Entity {
var asteroid = collide("asteroid", this.x, this.y); var asteroid = collide("asteroid", this.x, this.y);
if (asteroid != null) { if (asteroid != null) {
trace(asteroid);
} }
super.update(); super.update();

26
src/Title.hx Normal file
View file

@ -0,0 +1,26 @@
import com.haxepunk.Entity;
import com.haxepunk.graphics.Image;
import com.haxepunk.graphics.Text;
class Title extends Entity {
public function new (x:Float, y:Float) {
super(x, y);
var icon = new Image("graphics/cursor.png");
icon.scale = 3.5;
icon.x += 200;
var txt = new Text("Spaaace");
txt.size = 80;
txt.x -= 20;
this.centerOrigin();
txt.centerOrigin();
icon.centerOrigin();
this.addGraphic(txt);
this.addGraphic(icon);
}
}