diff --git a/src/client/haxe/layout/frames/auth.json b/src/client/haxe/layout/frames/auth.json index 6e5308d..da6f75b 100644 --- a/src/client/haxe/layout/frames/auth.json +++ b/src/client/haxe/layout/frames/auth.json @@ -1,18 +1,29 @@ { "pWidth": 100, "pHeight": 100, "layoutMargin": 3, "views": [ + { + "@type": "haxework.gui.LabelView", + "pWidth": 100, "height": 44, "text": "Authorization", + "@style": "label" + }, { "@type": "haxework.gui.HGroupView", "contentSize": true, "views": [ { "@type": "haxework.gui.LabelView", - "width": 150, "height": 25, "text": "Login" + "width": 150, "height": 44, "text": "Login", + "@style": "label" }, { "id": "loginInput", "@type": "haxework.gui.InputView", - "skin": {"@type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"}, - "width": 200, "height": 25, "text": "" + "skin": { + "@type": "haxework.gui.skin.BitmapSkin", + "image": "@asset:image:resources/images/map/map_3-0.png", + "fillType": "REPEAT" + }, + "width": 220, "height": 44, "text": "", + "@style": "label" } ] }, @@ -22,12 +33,18 @@ "views": [ { "@type": "haxework.gui.LabelView", - "width": 150, "height": 25, "text": "Password" + "width": 150, "height": 44, "text": "Password", + "@style": "label" }, { "id": "passwordInput", "@type": "haxework.gui.InputView", - "skin": {"@type": "haxework.gui.skin.ColorSkin", "color": "0xffffff"}, - "width": 200, "height": 25, "text": "" + "skin": { + "@type": "haxework.gui.skin.BitmapSkin", + "image": "@asset:image:resources/images/map/map_3-0.png", + "fillType": "REPEAT" + }, + "width": 220, "height": 44, "text": "", + "@style": "label" } ] }, @@ -35,8 +52,8 @@ { "id": "authButton", "@type": "haxework.gui.ButtonView", - "width": 100, "height": 45, - "text": "Auth", + "width": 132, "height": 44, + "text": "Submit", "@style": "button_skin" } ] diff --git a/src/client/haxe/layout/frames/game.json b/src/client/haxe/layout/frames/game.json index d6f7546..54ba073 100644 --- a/src/client/haxe/layout/frames/game.json +++ b/src/client/haxe/layout/frames/game.json @@ -3,7 +3,8 @@ "views": [ { "id": "name", "@type": "haxework.gui.LabelView", - "pWidth": 100, "height": 25, "text": "" + "pWidth": 100, "height": 44, "text": "", + "@style": "label" }, { "id": "render", "@type": "ru.m.tankz.render.Render", diff --git a/src/client/haxe/layout/frames/game_list.json b/src/client/haxe/layout/frames/game_list.json index c466a82..ffe1e4a 100644 --- a/src/client/haxe/layout/frames/game_list.json +++ b/src/client/haxe/layout/frames/game_list.json @@ -3,11 +3,12 @@ "views": [ { "id": "name", "@type": "haxework.gui.LabelView", - "pWidth": 100, "height": 25, "text": "" + "pWidth": 100, "height": 44, "text": "", + "@style": "label" }, { "id": "create", "@type": "haxework.gui.ButtonView", - "width": 100, "height": 45, + "width": 132, "height": 44, "text": "Create", "@style": "button_skin" }, diff --git a/src/client/haxe/layout/frames/game_ready.json b/src/client/haxe/layout/frames/game_ready.json index 5804b37..e5a8d7e 100644 --- a/src/client/haxe/layout/frames/game_ready.json +++ b/src/client/haxe/layout/frames/game_ready.json @@ -3,17 +3,18 @@ "views": [ { "id": "name", "@type": "haxework.gui.LabelView", - "pWidth": 100, "height": 25, "text": "" + "pWidth": 100, "height": 44, "text": "", + "@style": "label" }, { "id": "start", "@type": "haxework.gui.ButtonView", - "width": 100, "height": 45, + "width": 132, "height": 44, "text": "Start", "@style": "button_skin" }, { "id": "exit", "@type": "haxework.gui.ButtonView", - "width": 100, "height": 45, + "width": 132, "height": 44, "text": "Exit", "@style": "button_skin" }, diff --git a/src/client/haxe/layout/frames/person_list.json b/src/client/haxe/layout/frames/person_list.json index a2b0e05..97e5f0f 100644 --- a/src/client/haxe/layout/frames/person_list.json +++ b/src/client/haxe/layout/frames/person_list.json @@ -1,6 +1,11 @@ { "pWidth": 100, "pHeight": 100, "layoutMargin": 3, "paddings": 10, "views": [ + { + "@type": "haxework.gui.LabelView", + "pWidth": 100, "height": 44, "text": "Person select", + "@style": "label" + }, { "id": "list", "@type": "haxework.gui.list.VListView", "factory": "@class:ru.m.tankz.view.frames.list.PersonView", diff --git a/src/client/haxe/layout/main.json b/src/client/haxe/layout/main.json index 306c63a..6438736 100755 --- a/src/client/haxe/layout/main.json +++ b/src/client/haxe/layout/main.json @@ -4,12 +4,22 @@ "views": [ { "id":"top", "@type": "haxework.gui.HGroupView", - "pWidth": 100, "height": 30, - "skin": {"@type": "haxework.gui.skin.ColorSkin", "color": "0x105000"}, + "pWidth": 100, "height": 44, + "skin": { + "@type": "haxework.gui.skin.BitmapSkin", + "image": "@asset:image:resources/images/map/map_5.png", + "fillType": "REPEAT" + }, "views": [ + { + "id": "name", "@type": "haxework.gui.LabelView", + "pWidth": 100, "height": 44, + "text": "@res:text:userName", + "@style": "label" + }, { "id": "logout", "@type": "haxework.gui.ButtonView", - "width": 100, "height": 30, + "width": 132, "height": 44, "text": "Logout", "@style": "button_skin" } @@ -18,7 +28,11 @@ { "id": "switcher", "@type": "haxework.gui.frame.FrameSwitcher", "pWidth": 100, "pHeight": 100, - "skin": {"@type": "haxework.gui.skin.BitmapSkin", "image": "@asset:image:resources/images/background.png", "fillType": "REPEAT"}, + "skin": { + "@type": "haxework.gui.skin.BitmapSkin", + "image": "@asset:image:resources/images/map/map_1.png", + "fillType": "REPEAT" + }, "views": [ { "id": "auth", diff --git a/src/client/haxe/layout/other.json b/src/client/haxe/layout/other.json new file mode 100644 index 0000000..1290909 --- /dev/null +++ b/src/client/haxe/layout/other.json @@ -0,0 +1,18 @@ +{ + "person": { + "width": 440, "height": 44, + "skin": { + "@type": "haxework.gui.skin.BitmapSkin", + "image": "@asset:image:resources/images/map/map_3-0.png", + "fillType": "REPEAT" + }, + "views": [ + { + "id": "nameLabel", + "@type": "haxework.gui.LabelView", + "pWidth": 100, "height": 44, "text": "Выбор персонажа", + "@style": "label" + } + ] + } +} \ No newline at end of file diff --git a/src/client/haxe/layout/styles.json b/src/client/haxe/layout/styles.json index c5ff294..715f02e 100644 --- a/src/client/haxe/layout/styles.json +++ b/src/client/haxe/layout/styles.json @@ -2,11 +2,21 @@ "button_skin": { "skin": { "@type": "haxework.gui.skin.ButtonBitmapSkin", - "upImage": "@asset:image:resources/images/control/button_normal.png", - "downImage": "@asset:image:resources/images/control/button_down.png", - "overImage": "@asset:image:resources/images/control/button_over.png", - "fillType": "NINEPATH" + "image": "@asset:image:resources/images/map/map_4.png", + "fillType": "REPEAT" }, - "fontColor": "0xffffff" + "fontColor": "0xffffff", + "fontEmbed": true, + "fontFamily": "@res:text:fontName", + "fontSize": 16, + "shadowColor": "0x000000" + }, + + "label": { + "fontColor": "0xffffff", + "fontEmbed": true, + "fontFamily": "@res:text:fontName", + "fontSize": 16, + "shadowColor": "0x000000" } } \ No newline at end of file diff --git a/src/client/haxe/ru/m/tankz/Client.hx b/src/client/haxe/ru/m/tankz/Client.hx index 2ab4edf..c552ac6 100755 --- a/src/client/haxe/ru/m/tankz/Client.hx +++ b/src/client/haxe/ru/m/tankz/Client.hx @@ -1,5 +1,7 @@ package ru.m.tankz; +import haxework.resources.Resources; +import haxework.resources.IResources; import haxework.gui.VGroupView; import haxework.gui.ViewBuilder; import haxework.gui.ButtonView; @@ -35,16 +37,14 @@ class Client implements IConnectionHandler { private var view:MainView; - private var switcher:FrameSwitcher; public function new() { - view = new MainView(); - Root.bind(view); - switcher = view.switcher; - view.logout.onPress = this; - + Provider.setFactory(IResources, Resources); Provider.setFactory(GameData, GameData); - Provider.set(IFrameSwitcher, switcher); + + var font = Assets.getFont("resources/fonts/8-BIT WONDER.TTF"); + Provider.get(IResources).text.put("fontName", font.fontName); + Provider.set(IPacketBuilder, new PacketBuilder()); #if flash Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001)); @@ -53,7 +53,12 @@ class Client implements IConnectionHandler { #end Provider.get(IConnection).handler.addListener(this); - switcher.change(AuthFrame.ID); + + view = new MainView(); + Provider.set(IFrameSwitcher, view.switcher); + Root.bind(view); + view.logout.onPress = this; + view.switcher.change(AuthFrame.ID); } public function onPress(view:ButtonView):Void { @@ -66,11 +71,11 @@ class Client implements IConnectionHandler { public function onConnected():Void {} public function onDisconnected():Void { - switcher.change(AuthFrame.ID); + view.switcher.change(AuthFrame.ID); } public function onError(error:Dynamic):Void { L.e(TAG, "", error); - switcher.change(AuthFrame.ID); + view.switcher.change(AuthFrame.ID); } } diff --git a/src/client/haxe/ru/m/tankz/render/Render.hx b/src/client/haxe/ru/m/tankz/render/Render.hx index 58ac37d..20979b4 100755 --- a/src/client/haxe/ru/m/tankz/render/Render.hx +++ b/src/client/haxe/ru/m/tankz/render/Render.hx @@ -1,5 +1,8 @@ package ru.m.tankz.render; +import ru.m.tankz.core.Direction; +import flash.geom.Matrix; +import openfl.Assets; import ru.m.tankz.core.Bullet; import ru.m.tankz.core.Tank; import flash.display.Sprite; @@ -51,22 +54,34 @@ class Render extends SpriteView implements IRender { for (e in game.mobileEntities) { if (Std.is(e, Tank)) { - g.beginFill(0xff0000); + var m = new Matrix(); + m.rotate(calcRotate(e.direction)); + m.translate(e.x, e.y); + g.beginBitmapFill(Assets.getBitmapData("resources/images/tank/player/tank_p0_0-0.png"), m); g.drawRect(e.x, e.y, e.width, e.height); g.endFill(); - g.beginFill(0x990000); - g.drawRect( - e.x + e.width / 2 - e.width / 8 + e.direction.x * e.width / 4, - e.y + e.height / 2 - e.height / 8 + e.direction.y * e.height / 4, - e.width / 4, - e.height / 4 - ); - g.endFill(); } else if (Std.is(e, Bullet)) { - g.beginFill(0xff0000); + var m = new Matrix(); + m.rotate(calcRotate(e.direction)); + m.translate(e.x, e.y); + g.beginBitmapFill(Assets.getBitmapData("resources/images/bullet/bullet_0.png"), m); g.drawRect(e.x, e.y, e.width, e.height); g.endFill(); } } } + + private function calcRotate(direction:Direction):Float { + return (if (direction == Direction.RIGHT) { + 0; + } else if (direction == Direction.LEFT) { + 180; + } else if (direction == Direction.TOP) { + 270; + } else if (direction == Direction.BOTTOM) { + 90; + } else { + 0; + }) / (Math.PI * 2); + } } diff --git a/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx index 5d1264f..c0ebcf0 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/AuthFrame.hx @@ -1,5 +1,6 @@ package ru.m.tankz.view.frames; +import haxework.resources.IResources; import haxework.gui.ViewBuilder; import ru.m.core.connect.IConnection; import ru.m.tankz.data.GameData; @@ -63,6 +64,7 @@ class AuthFrame extends VGroupView implements ViewBuilder implements IPacketHand so.setProperty("login", loginInput.text); so.setProperty("password", passwordInput.text); so.flush(); + Provider.get(IResources).text.put("userName", packet.account.login); Provider.get(GameData).account = packet.account; Provider.get(IFrameSwitcher).change(PersonListFrame.ID); } diff --git a/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx index db961c4..bf16293 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/PersonListFrame.hx @@ -11,10 +11,10 @@ import ru.m.core.connect.IConnection; import ru.m.tankz.data.GameData; import haxework.provider.Provider; import ru.m.tankz.proto.Person; -import haxework.gui.HGroupView; +import haxework.gui.VGroupView; @:template("layout/frames/person_list.json", "layout/styles.json") -class PersonListFrame extends HGroupView implements ViewBuilder implements IPacketHandler implements ListViewListener { +class PersonListFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements ListViewListener { private static inline var TAG = "PersonListFrame"; diff --git a/src/client/haxe/ru/m/tankz/view/frames/list/PersonView.hx b/src/client/haxe/ru/m/tankz/view/frames/list/PersonView.hx index ecf686b..4d2dbe0 100755 --- a/src/client/haxe/ru/m/tankz/view/frames/list/PersonView.hx +++ b/src/client/haxe/ru/m/tankz/view/frames/list/PersonView.hx @@ -1,28 +1,16 @@ package ru.m.tankz.view.frames.list; +import haxework.gui.ViewBuilder; import haxework.gui.list.ListView.IListItemView; -import haxework.gui.LabelView; import ru.m.tankz.proto.Person; -import haxework.gui.skin.ColorSkin; import haxework.gui.HGroupView; -class PersonView extends HGroupView implements IListItemView { +@:template("layout/other.json@person", "layout/styles.json") +class PersonView extends HGroupView implements ViewBuilder implements IListItemView { public var item_index(default, default):Int; public var data(default, set):Person; - private var nameLabel:LabelView; - - public function new() { - super(); - pWidth = 100; - height = 50; - skin = new ColorSkin(0xffffff); - - nameLabel = new LabelView(); - addView(nameLabel); - } - private function set_data(value:Person):Person { this.data = value; nameLabel.text = this.data.name; diff --git a/src/client/resources/fonts/8-BIT WONDER.TTF b/src/client/resources/fonts/8-BIT WONDER.TTF new file mode 100644 index 0000000..6d9b397 Binary files /dev/null and b/src/client/resources/fonts/8-BIT WONDER.TTF differ diff --git a/src/client/resources/fonts/8-BIT WONDER.eot b/src/client/resources/fonts/8-BIT WONDER.eot new file mode 100644 index 0000000..e2c9e2a Binary files /dev/null and b/src/client/resources/fonts/8-BIT WONDER.eot differ diff --git a/src/client/resources/fonts/8-BIT WONDER.svg b/src/client/resources/fonts/8-BIT WONDER.svg new file mode 100644 index 0000000..266614a --- /dev/null +++ b/src/client/resources/fonts/8-BIT WONDER.svg @@ -0,0 +1,161 @@ + + +!"#$%&'()*+,-./0123456789:;å<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_` abcdefghijklmnopqrstuvwxyz|{}~ \ No newline at end of file diff --git a/src/client/resources/fonts/8-BIT WONDER.woff b/src/client/resources/fonts/8-BIT WONDER.woff new file mode 100644 index 0000000..5902288 Binary files /dev/null and b/src/client/resources/fonts/8-BIT WONDER.woff differ diff --git a/src/common/haxe/ru/m/core/connect/neko/NekoConnection.hx b/src/common/haxe/ru/m/core/connect/neko/NekoConnection.hx index 6ea0e44..a8899cf 100755 --- a/src/common/haxe/ru/m/core/connect/neko/NekoConnection.hx +++ b/src/common/haxe/ru/m/core/connect/neko/NekoConnection.hx @@ -31,6 +31,7 @@ class NekoConnection extends BaseConnection { socket.output.write(bytes); socket.output.flush(); } catch (e:Dynamic) { + trace("Error send packet: " + packet); trace(e); } } diff --git a/src/common/haxe/ru/m/tankz/config/TankzConfig.hx b/src/common/haxe/ru/m/tankz/config/TankzConfig.hx index c5339d8..0dcbd11 100644 --- a/src/common/haxe/ru/m/tankz/config/TankzConfig.hx +++ b/src/common/haxe/ru/m/tankz/config/TankzConfig.hx @@ -14,8 +14,8 @@ typedef TankzConfig = { class DEFAULT { public static var CONFIG:TankzConfig = { map: { - cellWidth: 20, - cellHeight: 20, + cellWidth: 22, + cellHeight: 22, gridWidth: 26, gridHeight: 26 } diff --git a/src/common/haxe/ru/m/tankz/core/Bullet.hx b/src/common/haxe/ru/m/tankz/core/Bullet.hx index 32f0780..45f95be 100644 --- a/src/common/haxe/ru/m/tankz/core/Bullet.hx +++ b/src/common/haxe/ru/m/tankz/core/Bullet.hx @@ -7,7 +7,7 @@ class Bullet extends MobileEntity { public function new(personId:Int, id:Int, x:Float, y:Float, speed:Float, direction:Direction) { super(id, x, y, speed, direction); this.personId = personId; - this.width = 10; - this.height = 10; + this.width = 12; + this.height = 12; } } diff --git a/src/common/haxe/ru/m/tankz/core/Direction.hx b/src/common/haxe/ru/m/tankz/core/Direction.hx index a1bf855..1c8de77 100644 --- a/src/common/haxe/ru/m/tankz/core/Direction.hx +++ b/src/common/haxe/ru/m/tankz/core/Direction.hx @@ -13,7 +13,7 @@ class Direction { public var x(default, null):Int; public var y(default, null):Int; - public function new(x, y) { + private function new(x, y) { this.x = x; this.y = y; directions.set(x + y * 10, this); @@ -22,4 +22,8 @@ class Direction { public function reverse():Direction { return directions.get(-x + (-y) * 10); } + + public static function from(x:Int, y:Int):Direction { + return directions.get(x + y * 10); + } } diff --git a/src/common/haxe/ru/m/tankz/core/Tank.hx b/src/common/haxe/ru/m/tankz/core/Tank.hx index f000253..32d9d32 100755 --- a/src/common/haxe/ru/m/tankz/core/Tank.hx +++ b/src/common/haxe/ru/m/tankz/core/Tank.hx @@ -14,8 +14,8 @@ class Tank extends MobileEntity { public function new(personId:Int, id:Int, x:Float, y:Float, direction:Direction) { super(id, x, y, 4, direction); this.personId = personId; - width = 34; - height = 34; + width = 36; + height = 36; } public function shot():Null { diff --git a/src/common/haxe/ru/m/tankz/engine/Engine.hx b/src/common/haxe/ru/m/tankz/engine/Engine.hx index b2b4ac8..9b30ef6 100755 --- a/src/common/haxe/ru/m/tankz/engine/Engine.hx +++ b/src/common/haxe/ru/m/tankz/engine/Engine.hx @@ -71,18 +71,18 @@ class Engine implements IEngine { case GameChangeType.APPEND: switch (change.objectType) { case GameObjectType.TANK: - var tank:Tank = buildTank(change.personId, change.objectId, change.x, change.y, new Direction(change.directionY, change.directionY)); + var tank:Tank = buildTank(change.personId, change.objectId, change.x, change.y, Direction.from(change.directionY, change.directionY)); mobileEntities.set(tank.id, tank); tanks.set(tank.personId, tank); case GameObjectType.BULLET: - var bullet:Bullet = new Bullet(change.personId, change.objectId, change.x, change.y, 0, new Direction(change.directionY, change.directionY)); + var bullet:Bullet = new Bullet(change.personId, change.objectId, change.x, change.y, 0, Direction.from(change.directionY, change.directionY)); mobileEntities.set(bullet.id, bullet); } case GameChangeType.DESTROED: mobileEntities.remove(change.objectId); case GameChangeType.DIRECTION: var target = mobileEntities.get(change.objectId); - target.direction = new Direction(change.directionX, change.directionY); + target.direction = Direction.from(change.directionX, change.directionY); case GameChangeType.MOVED: var target = mobileEntities.get(change.objectId); target.x = change.x; diff --git a/src/server/haxe/ru/m/tankz/server/game/GameManager.hx b/src/server/haxe/ru/m/tankz/server/game/GameManager.hx index 36b21a8..ba56d65 100644 --- a/src/server/haxe/ru/m/tankz/server/game/GameManager.hx +++ b/src/server/haxe/ru/m/tankz/server/game/GameManager.hx @@ -163,7 +163,7 @@ class GameManager { ); } case GameActionType.MOVE: - tank.move(new Direction(action.directionX, action.directionY)); + tank.move(Direction.from(action.directionX, action.directionY)); changes.push(new GameChange() .setType(GameChangeType.DIRECTION) .setObjectType(GameObjectType.TANK)