This commit is contained in:
2018-01-05 18:01:51 +03:00
parent fbbeec9c86
commit 54abb75102
23 changed files with 248 additions and 676 deletions

View File

@@ -1,25 +1,20 @@
package ru.m.tankz;
import ru.m.tankz.proto.LeaveGameRequest;
import ru.m.tankz.proto.LeaveGameResponse;
import ru.m.tankz.proto.GameUpdateResponse;
import ru.m.tankz.proto.GameActionRequest;
import ru.m.tankz.proto.pack.LeaveGameRequest;
import ru.m.tankz.proto.pack.LeaveGameResponse;
import ru.m.tankz.proto.pack.GameUpdateResponse;
import ru.m.tankz.proto.pack.GameActionRequest;
import ru.m.core.connect.IConnection;
import protohx.Message;
import ru.m.tankz.proto.LoginRequest;
import ru.m.tankz.proto.LoginResponse;
import ru.m.tankz.proto.PersonSelectRequest;
import ru.m.tankz.proto.PersonSelectResponse;
import ru.m.tankz.proto.ErrorResponse;
import ru.m.tankz.proto.GamesSubscribeRequest;
import ru.m.tankz.proto.GamesUnSubscribeRequest;
import ru.m.tankz.proto.GamesResponse;
import ru.m.tankz.proto.CreateGameRequest;
import ru.m.tankz.proto.CreateGameResponse;
import ru.m.tankz.proto.JoinGameRequest;
import ru.m.tankz.proto.JoinGameResponse;
import ru.m.tankz.proto.StartGameRequest;
import ru.m.tankz.proto.StartGameResponse;
import ru.m.tankz.proto.pack.ErrorResponse;
import ru.m.tankz.proto.pack.GameListRequest;
import ru.m.tankz.proto.pack.GameListResponse;
import ru.m.tankz.proto.pack.CreateGameRequest;
import ru.m.tankz.proto.pack.CreateGameResponse;
import ru.m.tankz.proto.pack.JoinGameRequest;
import ru.m.tankz.proto.pack.JoinGameResponse;
import ru.m.tankz.proto.pack.StartGameRequest;
import ru.m.tankz.proto.pack.StartGameResponse;
class PacketBuilder implements IPacketBuilder {
@@ -27,24 +22,21 @@ class PacketBuilder implements IPacketBuilder {
0x00 => [
0x0001 => ErrorResponse
],
0x01 => [
0x0001 => LoginRequest,
0x0002 => LoginResponse,
0x0003 => PersonSelectRequest,
0x0004 => PersonSelectResponse
],
/*0x01 => [
],*/
0x02 => [
0x0001 => GamesSubscribeRequest,
0x0002 => GamesResponse,
0x0001 => GameListRequest,
0x0002 => GameListResponse,
0x0003 => CreateGameRequest,
0x0004 => CreateGameResponse,
0x0005 => JoinGameRequest,
0x0006 => JoinGameResponse,
0x0007 => StartGameRequest,
0x0008 => StartGameResponse,
0x0009 => LeaveGameRequest,
0x000a => LeaveGameResponse,
0x000b => GamesUnSubscribeRequest
0x0005 => GameListResponse,
0x0006 => JoinGameRequest,
0x0007 => JoinGameResponse,
0x0008 => StartGameRequest,
0x0009 => StartGameResponse,
0x000a => LeaveGameRequest,
0x000b => LeaveGameResponse
],
0x03 => [
0x0001 => GameActionRequest,

View File

@@ -1,23 +1,75 @@
package ru.m.tankz.config;
import ru.m.tankz.proto.core.GameType;
import ru.m.tankz.core.Direction;
typedef MapConfig = {
var cellWidth:Float;
var cellHeight:Float;
var gridWidth:Int;
var gridHeight:Int;
var cellWidth:Float;
var cellHeight:Float;
var gridWidth:Int;
var gridHeight:Int;
}
enum SpawnPointType {
PLAYER;
BOT;
EAGLE;
}
typedef SpawnPoint = {
var type:SpawnPointType;
var index:Int;
var x:Int;
var y:Int;
var direction:Direction;
}
typedef TankzConfig = {
var map:MapConfig;
var map:MapConfig;
var points:Array<SpawnPoint>;
}
class DEFAULT {
public static var CONFIG:TankzConfig = {
map: {
cellWidth: 22,
cellHeight: 22,
gridWidth: 26,
gridHeight: 26
class ConfigData {
public static var CLASSIC:TankzConfig = {
map: {
cellWidth: 22,
cellHeight: 22,
gridWidth: 26,
gridHeight: 26
},
points: [
{
type: SpawnPointType.PLAYER,
index: 0,
x: 8,
y: 24,
direction: Direction.TOP
},
{
type: SpawnPointType.PLAYER,
index: 1,
x: 16,
y: 24,
direction: Direction.TOP
}
]
};
public static function get(type:Int):TankzConfig {
switch (type) {
case GameType.CLASSIC:
return CLASSIC;
case _:
return null;
}
}
public static function findSpawnPoint(config:TankzConfig, type:SpawnPointType, index:Int):SpawnPoint {
for (point in config.points) {
if (point.type == type && point.index == index) {
return point;
}
}
return null;
}
};
}

View File

@@ -1,10 +1,10 @@
package ru.m.tankz.engine;
import ru.m.tankz.core.Bullet;
import ru.m.tankz.proto.GameObjectType;
import ru.m.tankz.proto.GameChangeType;
import ru.m.tankz.proto.GameChange;
import ru.m.tankz.proto.Person;
import ru.m.tankz.proto.game.GameObjectType;
import ru.m.tankz.proto.game.GameChangeType;
import ru.m.tankz.proto.game.GameChange;
import ru.m.tankz.proto.core.Player;
import ru.m.tankz.core.Direction;
import ru.m.tankz.core.IMobileEntity;
//import flash.geom.Rectangle;
@@ -30,8 +30,8 @@ class Engine implements IEngine {
tanks = new Map<Int, Tank>();
}
private function buildTank(personId:Int, id:Int, x:Float, y:Float, direction:Direction):Tank {
return new Tank(personId, id, x, y, direction);
private function buildTank(personId:Int, id:Int, cellX:Float, cellY:Float, direction:Direction):Tank {
return new Tank(personId, id, cellX * map.cellWidth, cellY * map.cellHeight, direction);
}
public function init(config:TankzConfig):Void {
@@ -43,18 +43,17 @@ class Engine implements IEngine {
y_limit = map.gridHeight * map.cellHeight;
}
public function initTanks(persons:Array<Person>):Array<GameChange> {
public function initTanks(players:Array<Player>):Array<GameChange> {
var changes = new Array<GameChange>();
for (person in persons) {
var x = 0;
var y = 100 * persons.indexOf(person);
var tank = buildTank(person.id, 0, x, y, Direction.BOTTOM);
for (index in 0...players.length) {
var player:Player = players[index];
var point:SpawnPoint = ConfigData.findSpawnPoint(config, SpawnPointType.PLAYER, index);
var tank = buildTank(player.id, 0, point.x, point.y, point.direction);
this.tanks.set(tank.personId, tank);
this.mobileEntities.set(tank.id, tank);
changes.push(new GameChange()
.setType(GameChangeType.APPEND)
.setObjectType(GameObjectType.TANK)
.setPersonId(tank.personId)
.setObjectId(tank.id)
.setX(tank.x)
.setY(tank.y)
@@ -94,7 +93,7 @@ class Engine implements IEngine {
}
}
public function updateFromChanges(changes:Array<GameChange>):Void {
/*public function updateFromChanges(changes:Array<GameChange>):Void {
for (change in changes) {
switch (change.type) {
case GameChangeType.APPEND:
@@ -117,10 +116,10 @@ class Engine implements IEngine {
target.x = change.x;
target.y = change.y;
case GameChangeType.MODIFIED:
//
}
}
}
}*/
public function update():Array<GameChange> {
var changes = new Array<GameChange>();
@@ -173,7 +172,6 @@ class Engine implements IEngine {
changes.push(new GameChange()
.setType(GameChangeType.MOVED)
.setObjectType(objectType)
.setPersonId(personId)
.setObjectId(entiny.id)
.setX(entiny.x)
.setY(entiny.y)
@@ -187,7 +185,6 @@ class Engine implements IEngine {
changes.push(new GameChange()
.setType(GameChangeType.DESTROED)
.setObjectType(objectType)
.setPersonId(personId)
.setObjectId(entiny.id)
);
}

View File

@@ -1,9 +1,9 @@
package ru.m.tankz.engine;
import ru.m.tankz.proto.GameChange;
import ru.m.tankz.proto.game.GameChange;
import ru.m.tankz.core.IMobileEntity;
import ru.m.tankz.core.Tank;
import ru.m.tankz.proto.Person;
import ru.m.tankz.proto.core.Player;
import ru.m.tankz.config.TankzConfig;
import ru.m.tankz.map.ITankzMap;
@@ -15,8 +15,8 @@ interface IEngine {
public function clear():Void;
public function init(config:TankzConfig):Void;
public function initTanks(persons:Array<Person>):Array<GameChange>;
public function initTanks(players:Array<Player>):Array<GameChange>;
public function action(tankId:Int, action:TankAction):Void;
public function updateFromChanges(changes:Array<GameChange>):Void;
//public function updateFromChanges(changes:Array<GameChange>):Void;
public function update():Array<GameChange>;
}