Merged the StoreScene.hx with the rest of the game, all purchases will be made.
Also introduced savegames.
This commit is contained in:
parent
f0375c798b
commit
e2f94102d4
0
assets/save/savegame.save
Normal file
0
assets/save/savegame.save
Normal file
|
@ -15,6 +15,7 @@
|
||||||
<haxelib name="openfl" version="1.4.0" />
|
<haxelib name="openfl" version="1.4.0" />
|
||||||
|
|
||||||
<assets path="assets/graphics" rename="graphics" include="*.png|*.jpg" />
|
<assets path="assets/graphics" rename="graphics" include="*.png|*.jpg" />
|
||||||
|
<assets path="assets/save" rename="save" include="*.save" />
|
||||||
<assets path="assets/audio" rename="audio" include="*.mp3" if="flash" />
|
<assets path="assets/audio" rename="audio" include="*.mp3" if="flash" />
|
||||||
<assets path="assets/audio" rename="audio" include="*.wav|*.ogg" unless="flash" />
|
<assets path="assets/audio" rename="audio" include="*.wav|*.ogg" unless="flash" />
|
||||||
<assets path="assets/font" rename="font" include="*.ttf" />
|
<assets path="assets/font" rename="font" include="*.ttf" />
|
||||||
|
|
|
@ -51,8 +51,6 @@ class Boss extends Entity {
|
||||||
var enemies:Array<Enemy> = [];
|
var enemies:Array<Enemy> = [];
|
||||||
this.scene.getClass(Enemy, enemies);
|
this.scene.getClass(Enemy, enemies);
|
||||||
|
|
||||||
trace(enemies.length + ", " + maxEnemies);
|
|
||||||
|
|
||||||
if (spawnTimer < 0 && enemies.length != maxEnemies && canSpawn) {
|
if (spawnTimer < 0 && enemies.length != maxEnemies && canSpawn) {
|
||||||
this.scene.add(new Enemy(this.width / 2, 20, color, Math.floor(Math.random() * 4) + 1));
|
this.scene.add(new Enemy(this.width / 2, 20, color, Math.floor(Math.random() * 4) + 1));
|
||||||
spawnTimer = .75;
|
spawnTimer = .75;
|
||||||
|
|
|
@ -13,6 +13,9 @@ class Bullet extends Entity {
|
||||||
graphic = laser1;
|
graphic = laser1;
|
||||||
|
|
||||||
setHitboxTo(laser1);
|
setHitboxTo(laser1);
|
||||||
|
laser1.centerOrigin();
|
||||||
|
laser2.centerOrigin();
|
||||||
|
this.centerOrigin();
|
||||||
|
|
||||||
type = "bullet";
|
type = "bullet";
|
||||||
|
|
||||||
|
|
19
src/Lives.hx
19
src/Lives.hx
|
@ -3,18 +3,21 @@ import com.haxepunk.graphics.Image;
|
||||||
import com.haxepunk.HXP;
|
import com.haxepunk.HXP;
|
||||||
|
|
||||||
import Player;
|
import Player;
|
||||||
|
import Save;
|
||||||
|
|
||||||
class Lives extends Entity {
|
class Lives extends Entity {
|
||||||
|
|
||||||
public function new () {
|
public function new () {
|
||||||
baseSprite = new Image("graphics/playerShip1_green.png");
|
baseSprite = new Image("graphics/playerShip" + Save.load().ship_type + "_green.png");
|
||||||
sprite = [
|
sprite = [
|
||||||
baseSprite,
|
baseSprite,
|
||||||
new Image("graphics/playerShip1_damage1.png"),
|
new Image("graphics/playerShip" + Save.load().ship_type + "_damage1.png"),
|
||||||
new Image("graphics/playerShip1_damage2.png"),
|
new Image("graphics/playerShip" + Save.load().ship_type + "_damage2.png"),
|
||||||
new Image("graphics/playerShip1_damage3.png")
|
new Image("graphics/playerShip" + Save.load().ship_type + "_damage3.png")
|
||||||
];
|
];
|
||||||
|
|
||||||
|
maxDamage = Save.load().ship_type + Save.load().ship_color;
|
||||||
|
|
||||||
liveBar = Image.createRect(Math.floor(baseSprite.width * .75), 10, 0x00FF00);
|
liveBar = Image.createRect(Math.floor(baseSprite.width * .75), 10, 0x00FF00);
|
||||||
liveBar.y += 65;
|
liveBar.y += 65;
|
||||||
|
|
||||||
|
@ -42,13 +45,13 @@ class Lives extends Entity {
|
||||||
|
|
||||||
public override function update() {
|
public override function update() {
|
||||||
graphic = baseSprite;
|
graphic = baseSprite;
|
||||||
this.addGraphic(sprite[damage]);
|
this.addGraphic(sprite[Math.floor((damage / maxDamage) * 4)]);
|
||||||
|
|
||||||
liveBar.scaledWidth = (liveBar.width / 4) * (4 - damage);
|
liveBar.scaledWidth = (liveBar.width / maxDamage) * (maxDamage - damage);
|
||||||
|
|
||||||
this.addGraphic(liveBar);
|
this.addGraphic(liveBar);
|
||||||
|
|
||||||
if (damage > 3) {
|
if (damage == maxDamage) {
|
||||||
var player:Array<Player> = [];
|
var player:Array<Player> = [];
|
||||||
this.scene.getClass(Player, player);
|
this.scene.getClass(Player, player);
|
||||||
player[0].die();
|
player[0].die();
|
||||||
|
@ -61,6 +64,8 @@ class Lives extends Entity {
|
||||||
private var sprite:Array<Image> = [];
|
private var sprite:Array<Image> = [];
|
||||||
private var baseSprite:Image;
|
private var baseSprite:Image;
|
||||||
private var liveBar:Image;
|
private var liveBar:Image;
|
||||||
|
|
||||||
private var damage:Int;
|
private var damage:Int;
|
||||||
|
private var maxDamage:Int;
|
||||||
|
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@ class Main extends Engine
|
||||||
HXP.resize(360, 640);
|
HXP.resize(360, 640);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
HXP.scene = new StoreScene();
|
HXP.scene = new MenuScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function main() { new Main(); }
|
public static function main() { new Main(); }
|
||||||
|
|
|
@ -39,15 +39,19 @@ class MenuButton extends Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function update() {
|
public override function update() {
|
||||||
Input.touchPoints(onTouch);
|
|
||||||
|
|
||||||
if (Input.mouseReleased) {
|
if (Input.mouseReleased) {
|
||||||
if ((Input.mouseX > this.left && Input.mouseX < this.right) && (Input.mouseY > this.top && Input.mouseY < this.bottom)) {
|
if ((Input.mouseX > this.left && Input.mouseX < this.right) && (Input.mouseY > this.top && Input.mouseY < this.bottom) || Input.pressed("enter")) {
|
||||||
if (this.text.text != "Menu") {
|
if (this.text.text == "Retry" || this.text.text == "Play!") {
|
||||||
HXP.scene = null;
|
HXP.scene = null;
|
||||||
Assets.cache.clear();
|
Assets.cache.clear();
|
||||||
HXP.scene = new MainScene();
|
HXP.scene = new MainScene();
|
||||||
}
|
}
|
||||||
|
else if (this.text.text == "Store") {
|
||||||
|
HXP.scene = null;
|
||||||
|
Assets.cache.clear();
|
||||||
|
HXP.scene = new StoreScene();
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
HXP.scene = null;
|
HXP.scene = null;
|
||||||
Assets.cache.clear();
|
Assets.cache.clear();
|
||||||
|
@ -55,34 +59,6 @@ class MenuButton extends Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.check("enter")) {
|
|
||||||
if (this.text.text != "Menu") {
|
|
||||||
HXP.scene = null;
|
|
||||||
Assets.cache.clear();
|
|
||||||
HXP.scene = new MainScene();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
HXP.scene = null;
|
|
||||||
Assets.cache.clear();
|
|
||||||
HXP.scene = new MenuScene();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function onTouch(touch:Touch) {
|
|
||||||
if ((touch.x > this.left && touch.x < this.right) && (touch.y > this.top && touch.y < this.bottom)) {
|
|
||||||
if (this.text.text != "Menu") {
|
|
||||||
HXP.scene = null;
|
|
||||||
Assets.cache.clear();
|
|
||||||
HXP.scene = new MainScene();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
HXP.scene = null;
|
|
||||||
Assets.cache.clear();
|
|
||||||
HXP.scene = new MenuScene();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var txt:String;
|
private var txt:String;
|
||||||
|
|
|
@ -12,11 +12,23 @@ import Bullet;
|
||||||
import Lives;
|
import Lives;
|
||||||
import Score;
|
import Score;
|
||||||
import Explosion;
|
import Explosion;
|
||||||
|
import StoreScene;
|
||||||
|
import Save;
|
||||||
|
|
||||||
class Player extends Entity {
|
class Player extends Entity {
|
||||||
public function new() {
|
public function new() {
|
||||||
super(HXP.halfWidth - 16, HXP.height - 200);
|
super(HXP.halfWidth - 16, HXP.height - 200);
|
||||||
baseSprite = new Image("graphics/playerShip1_green.png");
|
baseSprite = new Image("graphics/" + Save.load().ship);
|
||||||
|
|
||||||
|
if (Save.load().ship_type == 1)
|
||||||
|
moveSpeed = 10;
|
||||||
|
else if (Save.load().ship_type == 2)
|
||||||
|
moveSpeed = 7;
|
||||||
|
else
|
||||||
|
moveSpeed = 5;
|
||||||
|
|
||||||
|
trace(moveSpeed + ", " + Save.load().ship_type);
|
||||||
|
|
||||||
shield = new Image("graphics/shield1.png");
|
shield = new Image("graphics/shield1.png");
|
||||||
|
|
||||||
#if flash
|
#if flash
|
||||||
|
@ -39,18 +51,22 @@ class Player extends Entity {
|
||||||
new Image("graphics/fire17.png"),
|
new Image("graphics/fire17.png"),
|
||||||
];
|
];
|
||||||
|
|
||||||
fireEffectLeft = fireEffectsLeft[currentAnim];
|
for (i in 0...fireEffectsLeft.length) {
|
||||||
fireEffectLeft.x = -30;
|
fireEffectsLeft[i].originX = fireEffectsLeft[i].width / 2;
|
||||||
fireEffectLeft.y = 24;
|
fireEffectsLeft[i].x = -30;
|
||||||
|
fireEffectsLeft[i].y = 24;
|
||||||
|
fireEffectsRight[i].originX = fireEffectsLeft[i].width / 2;
|
||||||
|
fireEffectsRight[i].x = 30;
|
||||||
|
fireEffectsRight[i].y = 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
fireEffectLeft = fireEffectsLeft[currentAnim];
|
||||||
fireEffectRight = fireEffectsRight[currentAnim];
|
fireEffectRight = fireEffectsRight[currentAnim];
|
||||||
fireEffectRight.x = 19;
|
|
||||||
fireEffectRight.y = 24;
|
|
||||||
|
|
||||||
this.addGraphic(fireEffectLeft);
|
this.addGraphic(fireEffectLeft);
|
||||||
this.addGraphic(fireEffectRight);
|
this.addGraphic(fireEffectRight);
|
||||||
|
|
||||||
setHitbox(99, 75);
|
setHitboxTo(baseSprite);
|
||||||
|
|
||||||
Input.define("left", [Key.LEFT, Key.A]);
|
Input.define("left", [Key.LEFT, Key.A]);
|
||||||
Input.define("right", [Key.RIGHT, Key.D]);
|
Input.define("right", [Key.RIGHT, Key.D]);
|
||||||
|
@ -96,17 +112,32 @@ class Player extends Entity {
|
||||||
public function shoot() {
|
public function shoot() {
|
||||||
if (this.y > 0) {
|
if (this.y > 0) {
|
||||||
var score:Array<Score> = [];
|
var score:Array<Score> = [];
|
||||||
|
|
||||||
this.scene.getClass(Score, score);
|
this.scene.getClass(Score, score);
|
||||||
|
|
||||||
score[0].rem(500);
|
score[0].rem(250);
|
||||||
|
var ship:Int = Save.load().ship_type;
|
||||||
|
|
||||||
|
if (ship == 3){
|
||||||
this.scene.add(new Bullet(this.x, this.y - this.height / 2));
|
this.scene.add(new Bullet(this.x, this.y - this.height / 2));
|
||||||
|
}
|
||||||
|
else if (ship == 1) {
|
||||||
|
this.scene.add(new Bullet(this.x + 40, this.y - 20));
|
||||||
|
this.scene.add(new Bullet(this.x - 40, this.y - 20));
|
||||||
|
}
|
||||||
|
else if (ship == 2) {
|
||||||
|
this.scene.add(new Bullet(this.x, this.y - this.height / 2));
|
||||||
|
this.scene.add(new Bullet(this.x - 40, this.y - 20));
|
||||||
|
this.scene.add(new Bullet(this.x + 40, this.y - 20));
|
||||||
|
}
|
||||||
laser.play();
|
laser.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function die() {
|
public function die() {
|
||||||
this.visible = false;
|
this.visible = false;
|
||||||
|
var score:Array<Score> = [];
|
||||||
|
this.scene.getClass(Score, score);
|
||||||
|
|
||||||
|
|
||||||
this.scene.add(new Explosion(this.x, this.y, this));
|
this.scene.add(new Explosion(this.x, this.y, this));
|
||||||
|
|
||||||
|
@ -115,8 +146,10 @@ class Player extends Entity {
|
||||||
var txt:Text = new Text("You died!", HXP.halfWidth - 225, HXP.halfHeight - 250, 500, 50, {size: 100});
|
var txt:Text = new Text("You died!", HXP.halfWidth - 225, HXP.halfHeight - 250, 500, 50, {size: 100});
|
||||||
txt.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
|
txt.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
|
||||||
|
|
||||||
|
Save.save("money", score[0].score);
|
||||||
|
|
||||||
this.scene.addGraphic(txt);
|
this.scene.addGraphic(txt);
|
||||||
this.scene.add(new MenuButton(HXP.halfWidth, HXP.halfHeight - 50, "Retry?"));
|
this.scene.add(new MenuButton(HXP.halfWidth, HXP.halfHeight - 50, "Store"));
|
||||||
this.scene.add(new MenuButton(HXP.halfWidth, HXP.halfHeight + 50, "Menu"));
|
this.scene.add(new MenuButton(HXP.halfWidth, HXP.halfHeight + 50, "Menu"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,12 +168,8 @@ class Player extends Entity {
|
||||||
currentAnim = 0;
|
currentAnim = 0;
|
||||||
|
|
||||||
fireEffectLeft = fireEffectsLeft[currentAnim];
|
fireEffectLeft = fireEffectsLeft[currentAnim];
|
||||||
fireEffectLeft.x = -30;
|
|
||||||
fireEffectLeft.y = 24;
|
|
||||||
|
|
||||||
fireEffectRight = fireEffectsRight[currentAnim];
|
fireEffectRight = fireEffectsRight[currentAnim];
|
||||||
fireEffectRight.x = 19;
|
|
||||||
fireEffectRight.y = 24;
|
|
||||||
|
|
||||||
graphic = baseSprite;
|
graphic = baseSprite;
|
||||||
this.addGraphic(fireEffectLeft);
|
this.addGraphic(fireEffectLeft);
|
||||||
|
@ -185,13 +214,14 @@ class Player extends Entity {
|
||||||
private var fireEffectsLeft:Array<Image> = [];
|
private var fireEffectsLeft:Array<Image> = [];
|
||||||
private var fireEffectsRight:Array<Image> = [];
|
private var fireEffectsRight:Array<Image> = [];
|
||||||
|
|
||||||
|
private var moveSpeed:Float;
|
||||||
|
public var health:Int;
|
||||||
|
|
||||||
private var fireEffectLeft:Image;
|
private var fireEffectLeft:Image;
|
||||||
private var fireEffectRight:Image;
|
private var fireEffectRight:Image;
|
||||||
|
|
||||||
private var moveSpeed:Int = 7;
|
|
||||||
private var hitPause:Float = 0;
|
|
||||||
|
|
||||||
|
private var hitPause:Float = 0;
|
||||||
private var animWait:Float = .75;
|
private var animWait:Float = .75;
|
||||||
private var currentAnim:Int = 0;
|
private var currentAnim:Int = 0;
|
||||||
|
|
||||||
|
|
13
src/Save.hx
13
src/Save.hx
|
@ -5,19 +5,22 @@ class Save extends Entity {
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
Data.load("savegame.save");
|
Data.load("save/savegame.save");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function save(what:String, data:Dynamic) {
|
public static function save(what:String, data:Dynamic) {
|
||||||
Data.write(what, data);
|
Data.write(what, data);
|
||||||
Data.save("savegame.save", true);
|
Data.save("save/savegame.save", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function load() {
|
public static function load() {
|
||||||
var data = {
|
var data = {
|
||||||
"current_ship" : Data.readString("ship" , "playerShip3_green"),
|
"ship" : Data.readString("ship" , "playerShip3_green.png"),
|
||||||
"current_laser" : Data.readString("laser", "laserGreen04.png"),
|
"ship_type" : Data.readInt("ship_type", 3),
|
||||||
"has_heavy_laser" : Data.readBool("heavy_laser", false)
|
"ship_color" : Data.readInt("ship_color", 1),
|
||||||
|
"laser" : Data.readString("laser", "laserGreen04.png"),
|
||||||
|
"has_heavy_laser" : Data.readBool("heavy_laser", false),
|
||||||
|
"money" : Data.readInt("money", 1000)
|
||||||
};
|
};
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -4,14 +4,16 @@ import com.haxepunk.graphics.Text;
|
||||||
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
|
|
||||||
|
import Save;
|
||||||
|
|
||||||
class Score extends Entity {
|
class Score extends Entity {
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super(HXP.halfWidth, 30);
|
super(HXP.halfWidth, 30);
|
||||||
|
|
||||||
name = "score";
|
name = "score";
|
||||||
score = 1000;
|
score = Save.load().money;
|
||||||
scoreText = new Text("$1000", 0, 0, 0, 0, {size : 50, /*align : "center",*/ color : 0xFFF000});
|
scoreText = new Text("$" + score, 0, 0, 0, 0, {size : 50, align : "center", color : 0xFFF000});
|
||||||
scoreText.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
|
scoreText.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
|
||||||
|
|
||||||
layer = -3;
|
layer = -3;
|
||||||
|
|
|
@ -62,8 +62,6 @@ class StoreArrows extends Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Input.touchPoints(onTouch);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onTouch(touch:Touch) {
|
private function onTouch(touch:Touch) {
|
||||||
|
|
|
@ -2,6 +2,8 @@ import com.haxepunk.Entity;
|
||||||
import com.haxepunk.graphics.Image;
|
import com.haxepunk.graphics.Image;
|
||||||
import com.haxepunk.graphics.Text;
|
import com.haxepunk.graphics.Text;
|
||||||
import com.haxepunk.utils.Input;
|
import com.haxepunk.utils.Input;
|
||||||
|
import com.haxepunk.utils.Touch;
|
||||||
|
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
|
|
||||||
class StoreItem extends Entity {
|
class StoreItem extends Entity {
|
||||||
|
@ -64,6 +66,23 @@ class StoreItem extends Entity {
|
||||||
this.addGraphic(button);
|
this.addGraphic(button);
|
||||||
this.addGraphic(text);
|
this.addGraphic(text);
|
||||||
this.addGraphic(description);
|
this.addGraphic(description);
|
||||||
|
|
||||||
|
if (Input.mouseReleased) {
|
||||||
|
if ((Input.mouseX > this.left && Input.mouseX < this.right) && (Input.mouseY > this.top && Input.mouseY < this.bottom)) {
|
||||||
|
buy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buy() {
|
||||||
|
var save = Save.load();
|
||||||
|
if (save.money >= prices[which][currentSprite]) {
|
||||||
|
Save.save("ship", items[which][currentSprite]);
|
||||||
|
Save.save("ship_type", which);
|
||||||
|
Save.save("ship_color", currentSprite);
|
||||||
|
Save.save("money", save.money - prices[which][currentSprite]);
|
||||||
|
trace("Bought something");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function goLeft() {
|
public function goLeft() {
|
||||||
|
|
|
@ -14,7 +14,7 @@ class StoreScene extends Scene {
|
||||||
public override function begin() {
|
public override function begin() {
|
||||||
backdrop = new Backdrop("graphics/darkPurple.png", true, true);
|
backdrop = new Backdrop("graphics/darkPurple.png", true, true);
|
||||||
addGraphic(backdrop);
|
addGraphic(backdrop);
|
||||||
var buyText:Text = new Text("Buy :", HXP.halfWidth - 100, 50, 0, 0, {size: 40});
|
buyText = new Text("$" + Save.load().money + ", Buy :", HXP.halfWidth - 100, 50, 0, 0, {size: 40});
|
||||||
buyText.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
|
buyText.font = Assets.getFont("font/kenpixel_mini_square.ttf").fontName;
|
||||||
addGraphic(buyText);
|
addGraphic(buyText);
|
||||||
|
|
||||||
|
@ -23,13 +23,16 @@ class StoreScene extends Scene {
|
||||||
add(new StoreArrows(HXP.halfWidth, 200 + (i * 200), i));
|
add(new StoreArrows(HXP.halfWidth, 200 + (i * 200), i));
|
||||||
}
|
}
|
||||||
|
|
||||||
trace(Save.load());
|
this.add(new MenuButton(HXP.halfWidth - 220, HXP.height - 50, "Retry"));
|
||||||
|
this.add(new MenuButton(HXP.halfWidth + 220, HXP.height - 50, "Menu"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override function update() {
|
public override function update() {
|
||||||
super.update();
|
super.update();
|
||||||
|
buyText.text = "$" + Save.load().money + ", Buy :";
|
||||||
backdrop.y += 1;
|
backdrop.y += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private var backdrop:Backdrop;
|
private var backdrop:Backdrop;
|
||||||
|
private var buyText:Text;
|
||||||
}
|
}
|
Reference in a new issue