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>;
}

View File

@@ -1,135 +0,0 @@
package ru.m.tankz.proto;
message Person {
required int32 id = 1;
required string name = 2;
}
message Account {
required int32 id = 1;
required string login = 2;
repeated Person persons = 3;
}
message LoginRequest {
required string login = 1;
required string password = 2;
}
message LoginResponse {
required Account account = 1;
}
message PersonSelectRequest {
required int32 person_id = 1;
}
message PersonSelectResponse {
required Person person = 1;
}
message ErrorResponse {
required int32 code = 1;
required string message = 2;
}
enum GameState {
READY = 1;
STARTED = 2;
ENDED = 3;
}
message Game {
required int32 id = 1;
required Person creator = 2;
repeated Person persons = 3;
required GameState state = 4;
}
message GamesSubscribeRequest {
}
message GamesUnSubscribeRequest {
}
message GamesResponse {
repeated Game games = 1;
}
message CreateGameRequest {
}
message CreateGameResponse {
required Game game = 1;
}
message JoinGameRequest {
required int32 game_id = 1;
}
message JoinGameResponse {
required Game game = 1;
}
message LeaveGameRequest {
}
message LeaveGameResponse {
required Game game = 1;
}
message StartGameRequest {
}
message StartGameResponse {
required Game game = 1;
}
/**
Game
*/
enum GameActionType {
MOVE = 1;
SHOT = 2;
STOP = 3;
}
message GameActionRequest {
required GameActionType type = 1;
optional int32 directionX = 2;
optional int32 directionY = 3;
}
enum GameObjectType {
TANK = 1;
BULLET = 2;
}
enum GameChangeType {
MOVED = 1;
DESTROED = 2;
MODIFIED = 3;
APPEND = 4;
DIRECTION = 5;
}
message GameChange {
required GameChangeType type = 1;
required GameObjectType objectType = 2;
optional int32 personId = 3;
required int32 objectId = 4;
optional float x = 5;
optional float y = 6;
optional int32 directionX = 7;
optional int32 directionY = 8;
}
message GameUpdateResponse {
repeated GameChange changes = 1;
}

View File

@@ -0,0 +1,27 @@
syntax = "proto3";
package ru.m.tankz.proto.core;
message Player {
int32 id = 1;
string name = 2;
}
enum GameType {
CLASSIC = 0;
}
enum GameState {
READY = 0;
STARTED = 1;
ENDED = 2;
}
message Game {
int32 id = 1;
GameType type = 2;
Player creator = 3;
repeated Player players = 4;
GameState state = 5;
}

View File

@@ -0,0 +1,33 @@
syntax = "proto3";
package ru.m.tankz.proto.game;
enum GameActionType {
MOVE = 0;
SHOT = 1;
STOP = 2;
}
enum GameObjectType {
TANK = 0;
BULLET = 1;
}
enum GameChangeType {
MOVED = 0;
DESTROED = 1;
MODIFIED = 2;
APPEND = 3;
DIRECTION = 4;
}
message GameChange {
GameChangeType type = 1;
GameObjectType objectType = 2;
int32 objectId = 3;
float x = 4;
float y = 5;
int32 directionX = 6;
int32 directionY = 7;
}

View File

@@ -0,0 +1,56 @@
syntax = "proto3";
import "core.proto";
import "game.proto";
package ru.m.tankz.proto.pack;
message ErrorResponse {
int32 code = 1;
string message = 2;
}
message GameListRequest {}
message GameListResponse {
repeated ru.m.tankz.proto.core.Game games = 1;
}
message CreateGameRequest {
ru.m.tankz.proto.core.GameType type = 1;
}
message CreateGameResponse {
ru.m.tankz.proto.core.Game game = 1;
}
message JoinGameRequest {
int32 game_id = 1;
}
message JoinGameResponse {
ru.m.tankz.proto.core.Game game = 1;
}
message LeaveGameRequest {}
message LeaveGameResponse {
ru.m.tankz.proto.core.Game game = 1;
}
message StartGameRequest {}
message StartGameResponse {
ru.m.tankz.proto.core.Game game = 1;
}
message GameActionRequest {
ru.m.tankz.proto.game.GameActionType type = 1;
int32 directionX = 2;
int32 directionY = 3;
}
message GameUpdateResponse {
repeated ru.m.tankz.proto.game.GameChange changes = 1;
}