Made the StoreScene work, it can now switch between store items.

This commit is contained in:
Bram van der Veen 2014-07-12 14:52:51 +02:00
parent 4f70dc21c6
commit f1d78ea861
3 changed files with 109 additions and 21 deletions

70
src/StoreArrows.hx Normal file
View file

@ -0,0 +1,70 @@
import com.haxepunk.Entity;
import com.haxepunk.graphics.Image;
import com.haxepunk.utils.Input;
import com.haxepunk.utils.Touch;
import StoreItem;
class StoreArrows extends Entity {
public function new(x:Float, y:Float, type:Int) {
super(x - 230, y);
which = type;
arrowLeft = new Image("graphics/fire05.png");
arrowLeft.angle = 90;
arrowLeft.x -= 100;
arrowLeft.centerOrigin();
arrowRight = new Image("graphics/fire05.png");
arrowRight.angle = -90;
arrowRight.x += 100;
arrowRight.centerOrigin();
setHitbox(250, 100);
this.centerOrigin();
this.addGraphic(arrowLeft);
this.addGraphic(arrowRight);
}
public override function update() {
super.update();
if (Input.mouseReleased) {
var storeItems:Array<StoreItem> = [];
this.scene.getClass(StoreItem, storeItems);
if (Input.mouseY > this.top && Input.mouseY < this.bottom) {
if (Input.mouseX > this.left && Input.mouseX < this.left + 100) {
storeItems[which].goLeft();
}
if (Input.mouseX < this.right && Input.mouseX > this.right - 100) {
storeItems[which].goRight();
}
}
}
Input.touchPoints(onTouch);
}
private function onTouch(touch:Touch) {
var storeItems:Array<StoreItem> = [];
this.scene.getClass(StoreItem, storeItems);
if (touch.y > this.top && touch.y < this.bottom) {
if (touch.x > this.left && touch.x < this.left + 100) {
storeItems[which].goLeft();
}
if (touch.x < this.right && touch.x > this.right - 100) {
storeItems[which].goRight();
}
}
}
private var arrowLeft:Image;
private var arrowRight:Image;
private var which:Int;
}

View file

@ -1,6 +1,7 @@
import com.haxepunk.Entity;
import com.haxepunk.graphics.Image;
import com.haxepunk.graphics.Text;
import com.haxepunk.utils.Input;
import openfl.Assets;
class StoreItem extends Entity {
@ -8,10 +9,11 @@ class StoreItem extends Entity {
public function new(x:Float, y:Float, type:Int) {
super(x, y);
which = type;
button = new Image("graphics/buttonGreen.png");
button.scale = 2;
text = new Text(itemnames[type]);
text.color = 0x000000;
text.size = 40;
@ -31,38 +33,46 @@ class StoreItem extends Entity {
sprites[i].centerOrigin();
}
arrowLeft = new Image("graphics/fire05.png");
arrowLeft.angle = 90;
arrowLeft.x = -440;
arrowLeft.centerOrigin();
if (type != 4) currentSprite = 1;
else currentSprite = 0;
arrowRight = new Image("graphics/fire05.png");
arrowRight.angle = -90;
arrowRight.x = -260;
arrowRight.centerOrigin();
this.addGraphic(sprites[0]);
this.addGraphic(arrowLeft);
this.addGraphic(arrowRight);
this.addGraphic(sprites[currentSprite]);
this.addGraphic(button);
this.addGraphic(text);
}
private var button:Image;
private var sprites:Array<Image> = [];
private var arrowLeft:Image;
private var arrowRight:Image;
public override function update() {
super.update();
graphic = sprites[currentSprite];
this.addGraphic(button);
this.addGraphic(text);
}
public function goLeft() {
if (currentSprite != 0) {
currentSprite -= 1;
}
}
public function goRight() {
if (currentSprite != items[which].length - 1) {
currentSprite += 1;
}
}
private var currentSprite:Int;
private var which:Int;
private var button:Image;
private var sprites:Array<Image> = [];
private var text:Text;
public static var itemnames:Array<String> = [
"Fat Jumper",
"Speeder Jumper",
"Speed Jumper",
"X3 Jumper",
"V2 Laser",
"Heavy Laser"
@ -85,6 +95,7 @@ class StoreItem extends Entity {
"playerShip2_orange.png"
],
[
"laserGreen04.png",
"laserGreen06.png",
"laserBlue06.png"
],

View file

@ -1,17 +1,24 @@
import com.haxepunk.Scene;
import com.haxepunk.graphics.Backdrop;
import com.haxepunk.HXP;
import com.haxepunk.graphics.Text;
import openfl.Assets;
import StoreItem;
import StoreArrows;
class StoreScene extends Scene {
public override function begin() {
backdrop = new Backdrop("graphics/darkPurple.png", true, true);
addGraphic(backdrop);
var buyText:Text = new Text("Buy :", HXP.halfWidth - 100, 50, 0, 0, {size: 40});
buyText.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
addGraphic(buyText);
for (i in 0...StoreItem.itemnames.length) {
add(new StoreItem(HXP.halfWidth, 200 + (i * 200), i));
add(new StoreArrows(HXP.halfWidth, 200 + (i * 200), i));
}
}