Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,612 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
class Game extends hxd.App | ||
{ | ||
var currentScene:scenes.GameScene; | ||
var saveData:SaveData; | ||
var scenes:Map<String,scenes.GameScene>; | ||
var settings:GameSettings; | ||
var window:hxd.Window; | ||
|
||
var tiles:Array<Array<h2d.Tile>> = new Array<Array<h2d.Tile>>(); | ||
|
||
override function init () :Void | ||
{ | ||
hxd.Res.initLocal(); | ||
this.tiles = hxd.Res.loader.load("tile.png").toTile().grid(40); | ||
|
||
this.engine.backgroundColor = 0xFF6666CC; | ||
|
||
this.readSaveData(); | ||
this.settings = this.readSettings(); | ||
|
||
// i'd copy over old state manager code from a different project but honestly this thing doesn't need it | ||
// 12 hours in, maybe it did need it, good lord | ||
this.scenes = | ||
[ | ||
"MAIN"=>new scenes.MainGameScene(this), | ||
"TITLE"=>new scenes.TitleGameScene(this), | ||
"NEW"=>new scenes.NewGameScene(this), | ||
"SHOP"=>new scenes.ShopGameScene(this), | ||
"RPS"=>new scenes.RPSGameScene(this) | ||
]; | ||
this.changeScene("TITLE"); | ||
|
||
this.window = hxd.Window.getInstance(); | ||
window.resize(800,800); | ||
window.setFullScreen(this.settings.getVideoSettings().fullscreen); | ||
} | ||
|
||
override function update (dt:Float) :Void | ||
{ | ||
super.update(dt); | ||
this.currentScene.tick(dt); | ||
} | ||
|
||
public function clearSaveData () :Void this.saveData = null; | ||
public function readSaveData () :Void | ||
{ | ||
if (hxd.File.exists("save.json")) | ||
{ | ||
var s:String; | ||
hxd.File.load("save.json", function (content:haxe.io.Bytes) s = content.toString(), function (err:String) trace(err)); | ||
this.saveData = haxe.Json.parse(s); | ||
} | ||
} | ||
|
||
function readSettings () :GameSettings | ||
{ | ||
if (hxd.File.exists("settings.json")) | ||
{ | ||
var s:String; | ||
hxd.File.load("settings.json", function (content:haxe.io.Bytes) s = content.toString(), function (err:String) trace(err)); | ||
return new GameSettings(s); | ||
} else return null; | ||
} | ||
|
||
public function changeScene (key:String) :Void { | ||
this.currentScene = this.scenes[key]; | ||
this.setScene(this.currentScene); | ||
} | ||
|
||
public function getSaveData () :Null<SaveData> return this.saveData; | ||
public function getSettings () :GameSettings return this.settings; | ||
public function getTiles () :Array<Array<h2d.Tile>> return this.tiles; | ||
public function getWindow () :hxd.Window return this.window; | ||
|
||
static var inst:Game; | ||
static function main () :Void inst = new Game(); | ||
} | ||
|
||
typedef SaveData = { name:String, body:Int, leaf:Int, eyes:Int, color:Int, cash:Int, happy:Float, trumpet:Bool }; | ||
|
||
typedef AudioSettings = { ui_volume:Int, t_volume:Int }; | ||
typedef VideoSettings = { fullscreen:Bool }; | ||
class GameSettings | ||
{ | ||
var aSettings:AudioSettings; | ||
var vSettings:VideoSettings; | ||
|
||
public function new (s:String) | ||
{ | ||
var json:Dynamic = haxe.Json.parse(s); | ||
this.aSettings = json.audio; | ||
this.vSettings = json.video; | ||
} | ||
|
||
public function getAudioSettings () :AudioSettings return aSettings; | ||
public function getVideoSettings () :VideoSettings return vSettings; | ||
|
||
public function changeSettings (aSettings:AudioSettings,vSettings:VideoSettings) :Void | ||
{ | ||
this.aSettings = aSettings; | ||
this.vSettings = vSettings; | ||
hxd.File.saveBytes("settings.json",haxe.io.Bytes.ofString(haxe.Json.stringify({audio:aSettings,video:vSettings}))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-cp src | ||
-lib heaps | ||
-lib hlsdl | ||
-hl out/main.c | ||
-main Game |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"audio":{"t_volume":10,"ui_volume":10},"video":{"fullscreen":false}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
class Turnpet extends h2d.Object | ||
{ | ||
var tName(default,null):String; | ||
|
||
var height(default,null):Int; | ||
var width(default,null):Int; | ||
|
||
var body(default,null):Int; | ||
var color(default,null):Int; | ||
var eyes(default,null):Int; | ||
var leaf(default,null):Int; | ||
|
||
var bodyAnim(default,null):h2d.Anim; | ||
var eyesAnim(default,null):h2d.Anim; | ||
var leafAnim(default,null):h2d.Anim; | ||
var trumpetAnim(default,null):h2d.Anim; | ||
|
||
var happy:Float; | ||
var maxHappy:Int = 1000; | ||
|
||
var cash:Int; | ||
var maxCash:Int = 1000; // divide by 100 when displaying | ||
|
||
var state:TurnpetState; | ||
var pastState:TurnpetState; | ||
var texture:h3d.mat.Texture; | ||
var game:Game; | ||
|
||
var timeStart:Float; | ||
var timeEnd:Float; | ||
var ranTicker:Int=0; | ||
|
||
var angle:Float; | ||
|
||
var trumpet:Bool; | ||
var playing:Bool=false; | ||
|
||
public function new (data:Dynamic /*hehe sloppy*/,g:Game,parent:scenes.GameScene) | ||
{ | ||
super(parent); | ||
this.game = g; | ||
|
||
this.changeData(data); | ||
|
||
this.cash = (data.cash < 0 || data.cash > this.maxCash) ? 0 : data.cash; | ||
this.happy = (data.happy < 0 || data.happy > this.maxHappy) ? 0 : data.happy; | ||
|
||
this.trumpet = data.trumpet; | ||
|
||
this.height = 40; | ||
this.width = 40; | ||
this.state = TurnpetState.IDLE; | ||
this.pastState = this.state; | ||
} | ||
|
||
public function checkAnims () :Void | ||
{ | ||
if (this.pastState!=this.state) | ||
{ | ||
|
||
|
||
this.removeChild(this.bodyAnim); | ||
this.removeChild(this.eyesAnim); | ||
this.removeChild(this.leafAnim); | ||
this.removeChild(this.trumpetAnim); | ||
|
||
switch (this.state) | ||
{ | ||
case IDLE: | ||
this.bodyAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[0][this.body], | ||
this.game.getTiles()[1][this.body] | ||
] | ||
,2,this); | ||
this.eyesAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[7][this.eyes], | ||
this.game.getTiles()[8][this.eyes] | ||
] | ||
,2,this); | ||
this.leafAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[14][this.leaf], | ||
this.game.getTiles()[15][this.leaf] | ||
] | ||
,2,this); | ||
case WALKING: | ||
this.bodyAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[2][this.body], | ||
this.game.getTiles()[3][this.body] | ||
] | ||
,2,this); | ||
this.eyesAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[9][this.eyes], | ||
this.game.getTiles()[10][this.eyes] | ||
] | ||
,2,this); | ||
this.leafAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[16][this.leaf], | ||
this.game.getTiles()[17][this.leaf] | ||
] | ||
,2,this); | ||
case TRUMPET: | ||
this.bodyAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[4][this.body], | ||
this.game.getTiles()[5][this.body], | ||
this.game.getTiles()[6][this.body], | ||
this.game.getTiles()[5][this.body] | ||
] | ||
,2,this); | ||
this.eyesAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[11][this.eyes], | ||
this.game.getTiles()[12][this.eyes], | ||
this.game.getTiles()[13][this.eyes], | ||
this.game.getTiles()[12][this.eyes] | ||
] | ||
,2,this); | ||
this.leafAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[18][this.leaf], | ||
this.game.getTiles()[19][this.leaf], | ||
this.game.getTiles()[20][this.leaf], | ||
this.game.getTiles()[19][this.leaf] | ||
] | ||
,2,this); | ||
this.trumpetAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[21][0], | ||
this.game.getTiles()[22][0], | ||
this.game.getTiles()[23][0], | ||
this.game.getTiles()[22][0] | ||
] | ||
,2,this); | ||
default: | ||
}} | ||
|
||
if (0!=this.color) this.bodyAnim.adjustColor({hue:this.color*Math.PI/6}); | ||
} | ||
|
||
public function changeData (data:Dynamic) :Void | ||
{ | ||
this.tName = (data.name.length < 0 || data.name.length > 12) ? "Turnpet" : data.name; | ||
this.body = (data.body < 0 || data.body > 2) ? 0 : data.body; | ||
this.color = (data.color < 0 || data.color > 11) ? 0 : data.color; | ||
this.eyes = (data.eyes < 0 || data.eyes > 2) ? 0 : data.eyes; | ||
this.leaf = (data.leaf < 0 || data.leaf > 2) ? 0 : data.leaf; | ||
|
||
this.removeChild(this.bodyAnim); | ||
this.removeChild(this.eyesAnim); | ||
this.removeChild(this.leafAnim); | ||
|
||
this.bodyAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[0][this.body], | ||
this.game.getTiles()[1][this.body] | ||
] | ||
,2,this); | ||
this.eyesAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[7][this.eyes], | ||
this.game.getTiles()[8][this.eyes] | ||
] | ||
,2,this); | ||
this.leafAnim = new h2d.Anim( | ||
[ | ||
this.game.getTiles()[14][this.leaf], | ||
this.game.getTiles()[15][this.leaf] | ||
] | ||
,2,this); | ||
|
||
if (0!=this.color) this.bodyAnim.adjustColor({hue:this.color*Math.PI/6}); | ||
} | ||
|
||
public function addCash (cash:Int) :Void this.cash = (this.maxCash < cash + this.cash) ? this.maxCash : this.cash + cash; | ||
public function addHappy (happy:Float) :Void this.happy = (this.maxHappy < happy + this.happy) ? this.maxHappy : this.happy + happy; | ||
|
||
public function decay () :Void this.happy -= 2; | ||
|
||
public function getCash () :Int return this.cash; | ||
public function getHappiness () :Float return this.happy; | ||
public function getHeight () :Int return this.height; | ||
public function getName () :String return this.tName; | ||
public function getWidth () :Int return this.width; | ||
|
||
function setState (state:TurnpetState) :Void | ||
{ | ||
this.pastState = this.state; | ||
this.state = state; | ||
this.checkAnims(); | ||
} | ||
|
||
public function update () :Void | ||
{ | ||
if (!this.trumpet) | ||
{ | ||
// "ai" decision making | ||
++this.ranTicker; | ||
if (9==this.ranTicker) | ||
{ | ||
this.ranTicker = 0; | ||
var ran:Float = Math.random() * 5; | ||
if (1>ran&&TurnpetState.WALKING!=this.state) | ||
{ | ||
this.setState(TurnpetState.WALKING); | ||
this.angle = Math.random() * Math.PI * 2; | ||
|
||
this.timeStart = cast(this.parent,scenes.GameScene).getElapsedTime(); | ||
this.timeEnd = this.timeStart + 3.; | ||
} | ||
} | ||
|
||
// ai movement | ||
if (TurnpetState.WALKING==this.state) | ||
{ | ||
if (2==this.ranTicker%3) this.angle += Math.random() * Math.PI / 8 * (Math.random() - 0.5); | ||
this.x += Math.cos(this.angle) * .5; | ||
this.y += Math.sin(this.angle) * .5; | ||
|
||
this.x = (0>this.x) ? 0 : (360<this.x) ? 360 : this.x; | ||
this.y = (0>this.y) ? 0 : (360<this.y) ? 360 : this.y; | ||
} | ||
|
||
if (TurnpetState.IDLE!=this.state&&this.timeEnd<cast(this.parent,scenes.GameScene).getElapsedTime()) this.setState(TurnpetState.IDLE); | ||
} | ||
else | ||
{ | ||
if (!this.playing) | ||
{ | ||
this.setState(TurnpetState.TRUMPET); | ||
var subject = new msg.Subject(); | ||
subject.addObserver(new msg.Observer.AudioObserver()); | ||
subject.notify(this,msg.TpetEvent.TRUMPET); | ||
playing = true; | ||
} | ||
} | ||
|
||
if (cast(this.parent,scenes.GameScene).getGame().getSaveData().cash!=this.cash) | ||
{ | ||
var c = cast(this.parent,scenes.GameScene).getGame().getSaveData().cash; | ||
var h = cast(this.parent,scenes.GameScene).getGame().getSaveData().happy; | ||
this.cash = (1000<c) ? 1000 : c; | ||
this.happy = (1000<h) ? 1000 : h; | ||
this.trumpet = cast(this.parent,scenes.GameScene).getGame().getSaveData().trumpet; | ||
hxd.File.saveBytes("save.json",haxe.io.Bytes.ofString(haxe.Json.stringify( | ||
{ | ||
body:this.body, | ||
eyes:this.eyes, | ||
leaf:this.leaf, | ||
name:this.tName, | ||
color:this.color, | ||
cash:this.cash, | ||
happy:this.happy, | ||
trumpet:this.trumpet | ||
} | ||
))); | ||
} | ||
} | ||
} | ||
|
||
enum TurnpetState | ||
{ | ||
IDLE; | ||
WALKING; | ||
TRUMPET; | ||
} |
Oops, something went wrong.