diff --git a/src/StoreArrows.hx b/src/StoreArrows.hx new file mode 100644 index 0000000..3d0ee7b --- /dev/null +++ b/src/StoreArrows.hx @@ -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 = []; + 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 = []; + 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; +} \ No newline at end of file diff --git a/src/StoreItem.hx b/src/StoreItem.hx index 23117d7..42e0605 100644 --- a/src/StoreItem.hx +++ b/src/StoreItem.hx @@ -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 = []; - 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 = []; private var text:Text; public static var itemnames:Array = [ "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" ], diff --git a/src/StoreScene.hx b/src/StoreScene.hx index e1d5cdc..afbf84e 100644 --- a/src/StoreScene.hx +++ b/src/StoreScene.hx @@ -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)); } }