diff --git a/res/layout/main.json b/res/layout/main.json index 5406fca..a70c7bb 100755 --- a/res/layout/main.json +++ b/res/layout/main.json @@ -79,12 +79,14 @@ "pWidth":100, "height":25, "text":"" }, { - "id":"logout", - "type":"haxework.gui.ButtonView", - "width":100, - "height":30, + "id":"logout", "type":"haxework.gui.ButtonView", + "width":100, "height":30, "skin":{"type":"haxework.gui.skin.ButtonColorSkin"}, "text":"Logout" + }, + { + "id":"render", "type":"ru.m.tankz.render.Render", + "pWidth":100, "pHeight":100 } ] } diff --git a/sql/init.sql b/sql/init.sql index a1ee6fd..71a6872 100755 --- a/sql/init.sql +++ b/sql/init.sql @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS armageddon.account ( ); DROP TABLE IF EXISTS armageddon.person; -CREATE TABLE IF NOT EXISTS armageddon.account ( +CREATE TABLE IF NOT EXISTS armageddon.person ( id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, account_id INT UNSIGNED NOT NULL, name VARCHAR(255), diff --git a/src/client/haxe/ru/m/armageddon/client/frames/AuthFrame.hx b/src/client/haxe/ru/m/armageddon/client/frames/AuthFrame.hx index 1db174f..8b9e6b4 100755 --- a/src/client/haxe/ru/m/armageddon/client/frames/AuthFrame.hx +++ b/src/client/haxe/ru/m/armageddon/client/frames/AuthFrame.hx @@ -43,9 +43,14 @@ class AuthFrame extends VGroupView implements IPacketHandler { public function onShow():Void { Provider.get(IConnection).packetHandler = this; + if (so.data.login != null && so.data.password != null) { + loginInput.text = so.data.login; + passwordInput.text = so.data.password; + onPress(null); + } } - public function onPress(view:ButtonView):Void { + public function onPress(_):Void { var login:String = loginInput.text; var password:String = Md5.encode(passwordInput.text); var connection:IConnection = Provider.get(IConnection); diff --git a/src/client/haxe/ru/m/armageddon/client/frames/GameFrame.hx b/src/client/haxe/ru/m/armageddon/client/frames/GameFrame.hx index 47861ee..dfc83a1 100755 --- a/src/client/haxe/ru/m/armageddon/client/frames/GameFrame.hx +++ b/src/client/haxe/ru/m/armageddon/client/frames/GameFrame.hx @@ -1,11 +1,16 @@ package ru.m.armageddon.client.frames; +import ru.m.tankz.render.IRender; +import flash.events.Event; +import ru.m.tankz.game.Tankz; +import ru.m.tankz.game.ITankz; import ru.m.armageddon.core.connect.IConnection; import haxework.gui.LabelView; import haxework.gui.ButtonView; import haxework.provider.Provider; import ru.m.armageddon.client.data.GameData; import haxework.gui.VGroupView; +import ru.m.tankz.render.Render; class GameFrame extends VGroupView { @@ -13,17 +18,34 @@ class GameFrame extends VGroupView { public static inline var ID = "game"; + private var render:IRender; + private var game:ITankz; + public function new() { super(); + game = new Tankz(); } public function init():Void { + render = findViewById("render"); findViewById("logout", ButtonView).onPress = this; } public function onShow():Void { var person = Provider.get(GameData).person; findViewById("name", LabelView).text = person.name; + game.init(); + content.addEventListener(Event.ENTER_FRAME, updateGame); + } + + public function onHide():Void { + content.removeEventListener(Event.ENTER_FRAME, updateGame); + game.clear(); + } + + private function updateGame(_):Void { + game.update(); + render.draw(game); } public function onPress(view:ButtonView):Void { diff --git a/src/client/haxe/ru/m/tankz/core/Entity.hx b/src/client/haxe/ru/m/tankz/core/Entity.hx new file mode 100755 index 0000000..b7a13cf --- /dev/null +++ b/src/client/haxe/ru/m/tankz/core/Entity.hx @@ -0,0 +1,13 @@ +package ru.m.tankz.core; + +class Entity implements IEntity { + public var x(default, default):Float; + public var y(default, default):Float; + + public var width(default, default):Float; + public var height(default, default):Float; + + public function new() { + + } +} diff --git a/src/client/haxe/ru/m/tankz/core/IEntity.hx b/src/client/haxe/ru/m/tankz/core/IEntity.hx new file mode 100755 index 0000000..7f518fc --- /dev/null +++ b/src/client/haxe/ru/m/tankz/core/IEntity.hx @@ -0,0 +1,9 @@ +package ru.m.tankz.core; + +interface IEntity { + public var x(default, default):Float; + public var y(default, default):Float; + + public var width(default, default):Float; + public var height(default, default):Float; +} diff --git a/src/client/haxe/ru/m/tankz/core/IMobileEntity.hx b/src/client/haxe/ru/m/tankz/core/IMobileEntity.hx new file mode 100755 index 0000000..78ec9b6 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/core/IMobileEntity.hx @@ -0,0 +1,6 @@ +package ru.m.tankz.core; + +interface IMobileEntity extends IEntity { + public var mx(default, default):Float; + public var my(default, default):Float; +} diff --git a/src/client/haxe/ru/m/tankz/core/ITank.hx b/src/client/haxe/ru/m/tankz/core/ITank.hx new file mode 100755 index 0000000..568d424 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/core/ITank.hx @@ -0,0 +1,5 @@ +package ru.m.tankz.core; + +interface ITank extends IMobileEntity { + +} diff --git a/src/client/haxe/ru/m/tankz/core/MobileEntity.hx b/src/client/haxe/ru/m/tankz/core/MobileEntity.hx new file mode 100755 index 0000000..5f4b57b --- /dev/null +++ b/src/client/haxe/ru/m/tankz/core/MobileEntity.hx @@ -0,0 +1,11 @@ +package ru.m.tankz.core; + +class MobileEntity extends Entity implements IMobileEntity { + + public var mx(default, default):Float; + public var my(default, default):Float; + + public function new() { + super(); + } +} diff --git a/src/client/haxe/ru/m/tankz/core/Tank.hx b/src/client/haxe/ru/m/tankz/core/Tank.hx new file mode 100755 index 0000000..927fa59 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/core/Tank.hx @@ -0,0 +1,14 @@ +package ru.m.tankz.core; + +class Tank extends MobileEntity implements ITank { + + public function new() { + super(); + x = 0 + Math.random() * 50; + y = 0 + Math.random() * 50; + mx = 2 + Math.random() * 3; + my = 2 + Math.random() * 3; + width = 20 + Math.random() * 10; + height = 20 + Math.random() * 10; + } +} diff --git a/src/client/haxe/ru/m/tankz/game/ITankz.hx b/src/client/haxe/ru/m/tankz/game/ITankz.hx new file mode 100755 index 0000000..103513c --- /dev/null +++ b/src/client/haxe/ru/m/tankz/game/ITankz.hx @@ -0,0 +1,13 @@ +package ru.m.tankz.game; + +import ru.m.tankz.core.ITank; +import ru.m.tankz.map.ITankzMap; + +interface ITankz { + public var map(default, null):ITankzMap; + public var tanks(default, null):Array; + + public function clear():Void; + public function init():Void; + public function update():Void; +} diff --git a/src/client/haxe/ru/m/tankz/game/Tankz.hx b/src/client/haxe/ru/m/tankz/game/Tankz.hx new file mode 100755 index 0000000..2609350 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/game/Tankz.hx @@ -0,0 +1,47 @@ +package ru.m.tankz.game; + +import ru.m.tankz.map.TankzMap; +import ru.m.tankz.core.Tank; +import ru.m.tankz.core.ITank; +import ru.m.tankz.map.ITankzMap; + +class Tankz implements ITankz { + + public var map(default, null):ITankzMap; + public var tanks(default, null):Array; + + private var x_limit:Float; + private var y_limit:Float; + + public function new() { + map = new TankzMap(); + } + + public function clear():Void { + tanks = []; + } + + public function init():Void { + tanks = [ + new Tank(), + new Tank() + ]; + x_limit = map.width * map.cellWidth; + y_limit = map.height * map.cellHeight; + } + + public function update():Void { + for (tank in tanks) { + tank.x += tank.mx; + tank.y += tank.my; + if (tank.x < 0 || tank.x + tank.width > x_limit) { + tank.mx = - tank.mx; + tank.x += tank.mx; + } + if (tank.y < 0 || tank.y + tank.height > y_limit) { + tank.my = - tank.my; + tank.y += tank.my; + } + } + } +} diff --git a/src/client/haxe/ru/m/tankz/map/ITankzMap.hx b/src/client/haxe/ru/m/tankz/map/ITankzMap.hx new file mode 100755 index 0000000..b36f1dc --- /dev/null +++ b/src/client/haxe/ru/m/tankz/map/ITankzMap.hx @@ -0,0 +1,8 @@ +package ru.m.tankz.map; + +interface ITankzMap { + public var cellWidth(default, null):Float; + public var cellHeight(default, null):Float; + public var width(default, null):Int; + public var height(default, null):Int; +} diff --git a/src/client/haxe/ru/m/tankz/map/TankzMap.hx b/src/client/haxe/ru/m/tankz/map/TankzMap.hx new file mode 100755 index 0000000..d99fc59 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/map/TankzMap.hx @@ -0,0 +1,16 @@ +package ru.m.tankz.map; + +class TankzMap implements ITankzMap { + + public var cellWidth(default, null):Float; + public var cellHeight(default, null):Float; + public var width(default, null):Int; + public var height(default, null):Int; + + public function new() { + cellWidth = 10; + cellHeight = 10; + width = 26; + height = 26; + } +} diff --git a/src/client/haxe/ru/m/tankz/render/IRender.hx b/src/client/haxe/ru/m/tankz/render/IRender.hx new file mode 100755 index 0000000..84ba073 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/render/IRender.hx @@ -0,0 +1,9 @@ +package ru.m.tankz.render; + +import flash.display.Sprite; +import haxework.gui.IView; +import ru.m.tankz.game.ITankz; + +interface IRender extends IView { + public function draw(game:ITankz):Void; +} diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx new file mode 100755 index 0000000..2d41113 --- /dev/null +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -0,0 +1,36 @@ +package ru.m.tankz.render; + +import flash.display.Sprite; +import flash.display.Graphics; +import haxework.gui.SpriteView; +import ru.m.tankz.game.ITankz; + +class Render extends SpriteView implements IRender { + + private var mapLayer:Sprite; + private var tankLayer:Sprite; + + public function new() { + super(); + mapLayer = new Sprite(); + tankLayer = new Sprite(); + content.addChild(mapLayer); + content.addChild(tankLayer); + } + + public function draw(game:ITankz):Void { + var g:Graphics = mapLayer.graphics; + g.clear(); + g.beginFill(0x00ff00); + g.drawRect(0,0,game.map.width*game.map.cellWidth,game.map.height*game.map.cellHeight); + g.endFill(); + + var g:Graphics = tankLayer.graphics; + g.clear(); + for (tank in game.tanks) { + g.beginFill(0xff0000); + g.drawRect(tank.x, tank.y, tank.width, tank.height); + g.endFill(); + } + } +}