-
This commit is contained in:
@@ -79,12 +79,14 @@
|
|||||||
"pWidth":100, "height":25, "text":""
|
"pWidth":100, "height":25, "text":""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id":"logout",
|
"id":"logout", "type":"haxework.gui.ButtonView",
|
||||||
"type":"haxework.gui.ButtonView",
|
"width":100, "height":30,
|
||||||
"width":100,
|
|
||||||
"height":30,
|
|
||||||
"skin":{"type":"haxework.gui.skin.ButtonColorSkin"},
|
"skin":{"type":"haxework.gui.skin.ButtonColorSkin"},
|
||||||
"text":"Logout"
|
"text":"Logout"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":"render", "type":"ru.m.tankz.render.Render",
|
||||||
|
"pWidth":100, "pHeight":100
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS armageddon.account (
|
|||||||
);
|
);
|
||||||
|
|
||||||
DROP TABLE IF EXISTS armageddon.person;
|
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,
|
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||||
account_id INT UNSIGNED NOT NULL,
|
account_id INT UNSIGNED NOT NULL,
|
||||||
name VARCHAR(255),
|
name VARCHAR(255),
|
||||||
|
|||||||
@@ -43,9 +43,14 @@ class AuthFrame extends VGroupView implements IPacketHandler {
|
|||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
Provider.get(IConnection).packetHandler = this;
|
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 login:String = loginInput.text;
|
||||||
var password:String = Md5.encode(passwordInput.text);
|
var password:String = Md5.encode(passwordInput.text);
|
||||||
var connection:IConnection = Provider.get(IConnection);
|
var connection:IConnection = Provider.get(IConnection);
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package ru.m.armageddon.client.frames;
|
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 ru.m.armageddon.core.connect.IConnection;
|
||||||
import haxework.gui.LabelView;
|
import haxework.gui.LabelView;
|
||||||
import haxework.gui.ButtonView;
|
import haxework.gui.ButtonView;
|
||||||
import haxework.provider.Provider;
|
import haxework.provider.Provider;
|
||||||
import ru.m.armageddon.client.data.GameData;
|
import ru.m.armageddon.client.data.GameData;
|
||||||
import haxework.gui.VGroupView;
|
import haxework.gui.VGroupView;
|
||||||
|
import ru.m.tankz.render.Render;
|
||||||
|
|
||||||
class GameFrame extends VGroupView {
|
class GameFrame extends VGroupView {
|
||||||
|
|
||||||
@@ -13,17 +18,34 @@ class GameFrame extends VGroupView {
|
|||||||
|
|
||||||
public static inline var ID = "game";
|
public static inline var ID = "game";
|
||||||
|
|
||||||
|
private var render:IRender;
|
||||||
|
private var game:ITankz;
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
|
game = new Tankz();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init():Void {
|
public function init():Void {
|
||||||
|
render = findViewById("render");
|
||||||
findViewById("logout", ButtonView).onPress = this;
|
findViewById("logout", ButtonView).onPress = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onShow():Void {
|
public function onShow():Void {
|
||||||
var person = Provider.get(GameData).person;
|
var person = Provider.get(GameData).person;
|
||||||
findViewById("name", LabelView).text = person.name;
|
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 {
|
public function onPress(view:ButtonView):Void {
|
||||||
|
|||||||
13
src/client/haxe/ru/m/tankz/core/Entity.hx
Executable file
13
src/client/haxe/ru/m/tankz/core/Entity.hx
Executable file
@@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/client/haxe/ru/m/tankz/core/IEntity.hx
Executable file
9
src/client/haxe/ru/m/tankz/core/IEntity.hx
Executable file
@@ -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;
|
||||||
|
}
|
||||||
6
src/client/haxe/ru/m/tankz/core/IMobileEntity.hx
Executable file
6
src/client/haxe/ru/m/tankz/core/IMobileEntity.hx
Executable file
@@ -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;
|
||||||
|
}
|
||||||
5
src/client/haxe/ru/m/tankz/core/ITank.hx
Executable file
5
src/client/haxe/ru/m/tankz/core/ITank.hx
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
package ru.m.tankz.core;
|
||||||
|
|
||||||
|
interface ITank extends IMobileEntity {
|
||||||
|
|
||||||
|
}
|
||||||
11
src/client/haxe/ru/m/tankz/core/MobileEntity.hx
Executable file
11
src/client/haxe/ru/m/tankz/core/MobileEntity.hx
Executable file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/client/haxe/ru/m/tankz/core/Tank.hx
Executable file
14
src/client/haxe/ru/m/tankz/core/Tank.hx
Executable file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/client/haxe/ru/m/tankz/game/ITankz.hx
Executable file
13
src/client/haxe/ru/m/tankz/game/ITankz.hx
Executable file
@@ -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<ITank>;
|
||||||
|
|
||||||
|
public function clear():Void;
|
||||||
|
public function init():Void;
|
||||||
|
public function update():Void;
|
||||||
|
}
|
||||||
47
src/client/haxe/ru/m/tankz/game/Tankz.hx
Executable file
47
src/client/haxe/ru/m/tankz/game/Tankz.hx
Executable file
@@ -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<ITank>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/client/haxe/ru/m/tankz/map/ITankzMap.hx
Executable file
8
src/client/haxe/ru/m/tankz/map/ITankzMap.hx
Executable file
@@ -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;
|
||||||
|
}
|
||||||
16
src/client/haxe/ru/m/tankz/map/TankzMap.hx
Executable file
16
src/client/haxe/ru/m/tankz/map/TankzMap.hx
Executable file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/client/haxe/ru/m/tankz/render/IRender.hx
Executable file
9
src/client/haxe/ru/m/tankz/render/IRender.hx
Executable file
@@ -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<Sprite> {
|
||||||
|
public function draw(game:ITankz):Void;
|
||||||
|
}
|
||||||
36
src/client/haxe/ru/m/tankz/render/Render.hx
Executable file
36
src/client/haxe/ru/m/tankz/render/Render.hx
Executable file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user