[common] add engine interface
This commit is contained in:
@@ -10,9 +10,9 @@ import promhx.Promise;
|
|||||||
import ru.m.animate.Animate;
|
import ru.m.animate.Animate;
|
||||||
import ru.m.animate.OnceAnimate;
|
import ru.m.animate.OnceAnimate;
|
||||||
import ru.m.geom.Point;
|
import ru.m.geom.Point;
|
||||||
import ru.m.tankz.engine.Engine;
|
import ru.m.tankz.engine.IEngine;
|
||||||
import ru.m.tankz.game.Game.GameListener;
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
import ru.m.tankz.render.RenderItem;
|
import ru.m.tankz.render.RenderItem;
|
||||||
|
|
||||||
class Render extends SpriteView implements GameListener {
|
class Render extends SpriteView implements GameListener {
|
||||||
@@ -42,18 +42,16 @@ class Render extends SpriteView implements GameListener {
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function drawBackground(game:Engine):Void {
|
private function drawBackground(engine:IEngine):Void {
|
||||||
var mapWidth = game.map.gridWidth * game.map.cellWidth;
|
|
||||||
var mapHeight = game.map.gridHeight * game.map.cellHeight;
|
|
||||||
var g:Graphics = backgroundLayer.graphics;
|
var g:Graphics = backgroundLayer.graphics;
|
||||||
g.clear();
|
g.clear();
|
||||||
g.beginFill(0x000000);
|
g.beginFill(0x000000);
|
||||||
g.drawRect(0, 0, mapWidth, mapHeight);
|
g.drawRect(0, 0, engine.map.width, engine.map.height);
|
||||||
g.endFill();
|
g.endFill();
|
||||||
setContentSize(mapWidth, mapHeight);
|
setContentSize(engine.map.width, engine.map.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function draw(game:Engine):Void {
|
public function draw(game:IEngine):Void {
|
||||||
for (brick in game.map.bricks) if (brick.config.index > 0) {
|
for (brick in game.map.bricks) if (brick.config.index > 0) {
|
||||||
if (!items.exists(brick.key)) {
|
if (!items.exists(brick.key)) {
|
||||||
var item:RenderItem<Dynamic, Dynamic> = switch(brick.config.type) {
|
var item:RenderItem<Dynamic, Dynamic> = switch(brick.config.type) {
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import flash.media.Sound;
|
|||||||
import flash.media.SoundChannel;
|
import flash.media.SoundChannel;
|
||||||
import flash.media.SoundTransform;
|
import flash.media.SoundTransform;
|
||||||
import openfl.utils.Assets;
|
import openfl.utils.Assets;
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
import ru.m.tankz.game.GameEvent;
|
import ru.m.tankz.game.GameEvent;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
|
|
||||||
class SoundManager implements GameListener {
|
class SoundManager implements GameListener {
|
||||||
private static var TAG(default, never):String = 'SoundManager';
|
private static var TAG(default, never):String = 'SoundManager';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.tankz.view.common;
|
package ru.m.tankz.view.common;
|
||||||
|
|
||||||
import haxework.view.IView;
|
import haxework.view.IView;
|
||||||
import ru.m.tankz.game.Game.GameListener;
|
import ru.m.tankz.game.IGame;
|
||||||
|
|
||||||
interface IGamePanel extends IView<Dynamic> extends GameListener {
|
interface IGamePanel extends IView<Dynamic> extends GameListener {
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,11 @@ import ru.m.tankz.core.Entity;
|
|||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
import ru.m.tankz.core.MobileEntity;
|
import ru.m.tankz.core.MobileEntity;
|
||||||
import ru.m.tankz.core.Tank;
|
import ru.m.tankz.core.Tank;
|
||||||
|
import ru.m.tankz.engine.IEngine;
|
||||||
import ru.m.tankz.map.Grid;
|
import ru.m.tankz.map.Grid;
|
||||||
import ru.m.tankz.map.LevelMap;
|
import ru.m.tankz.map.LevelMap;
|
||||||
|
|
||||||
interface EngineListener {
|
@:yield @:dispatcher(EngineListener) class Engine implements IEngine {
|
||||||
public function onCollision(entity:EntityType, with:EntityType):Void;
|
|
||||||
}
|
|
||||||
|
|
||||||
@:yield @:dispatcher(EngineListener) class Engine {
|
|
||||||
|
|
||||||
public var config(default, default):Config;
|
public var config(default, default):Config;
|
||||||
public var map(default, null):LevelMap;
|
public var map(default, null):LevelMap;
|
||||||
@@ -134,6 +131,7 @@ interface EngineListener {
|
|||||||
if (!isStop || Std.is(entity, Bullet)) {
|
if (!isStop || Std.is(entity, Bullet)) {
|
||||||
entity.rect.x += entity.mx * (d / 30);
|
entity.rect.x += entity.mx * (d / 30);
|
||||||
entity.rect.y += entity.my * (d / 30);
|
entity.rect.y += entity.my * (d / 30);
|
||||||
|
moveSignal.emit(entityType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/common/haxe/ru/m/tankz/engine/IEngine.hx
Normal file
36
src/common/haxe/ru/m/tankz/engine/IEngine.hx
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package ru.m.tankz.engine;
|
||||||
|
|
||||||
|
import haxework.signal.Signal;
|
||||||
|
import ru.m.tankz.config.Config;
|
||||||
|
import ru.m.tankz.core.Entity;
|
||||||
|
import ru.m.tankz.core.EntityType;
|
||||||
|
import ru.m.tankz.core.Tank;
|
||||||
|
import ru.m.tankz.map.LevelMap;
|
||||||
|
|
||||||
|
interface IEngine {
|
||||||
|
public var entities(default, null):Map<Int, Entity>;
|
||||||
|
public var config(default, default):Config;
|
||||||
|
public var map(default, null):LevelMap;
|
||||||
|
|
||||||
|
public var collisionSignal(default, null):Signal2<EntityType, EntityType>;
|
||||||
|
public var moveSignal(default, null):Signal1<EntityType>;
|
||||||
|
|
||||||
|
public function spawn(entity:Entity):Void;
|
||||||
|
|
||||||
|
public function destroy(entity:Entity):Void;
|
||||||
|
|
||||||
|
public function update():Void;
|
||||||
|
|
||||||
|
public function iterTanks(filter:Tank->Bool):Iterator<Tank>;
|
||||||
|
|
||||||
|
public function connect(listener:EngineListener):Void;
|
||||||
|
|
||||||
|
public function disconnect(listener:EngineListener):Void;
|
||||||
|
|
||||||
|
public function dispose():Void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EngineListener {
|
||||||
|
public function onCollision(entity:EntityType, with:EntityType):Void;
|
||||||
|
public function onMove(entity:EntityType):Void;
|
||||||
|
}
|
||||||
@@ -4,13 +4,11 @@ import ru.m.tankz.bundle.IConfigBundle;
|
|||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
import ru.m.tankz.engine.Engine;
|
import ru.m.tankz.engine.Engine;
|
||||||
|
import ru.m.tankz.engine.IEngine;
|
||||||
import ru.m.tankz.game.GameState;
|
import ru.m.tankz.game.GameState;
|
||||||
|
import ru.m.tankz.game.IGame;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
interface GameListener {
|
|
||||||
public function onGameEvent(event:GameEvent):Void;
|
|
||||||
}
|
|
||||||
|
|
||||||
@:dispatcher(GameListener) class Game implements IGame implements GameListener {
|
@:dispatcher(GameListener) class Game implements IGame implements GameListener {
|
||||||
|
|
||||||
private static var TAG(default, never):String = "Game";
|
private static var TAG(default, never):String = "Game";
|
||||||
@@ -18,7 +16,7 @@ interface GameListener {
|
|||||||
public var type(default, null):GameType;
|
public var type(default, null):GameType;
|
||||||
public var teams(default, null):Map<TeamId, Team>;
|
public var teams(default, null):Map<TeamId, Team>;
|
||||||
public var config(default, null):Config;
|
public var config(default, null):Config;
|
||||||
public var engine(default, null):Engine;
|
public var engine(default, null):IEngine;
|
||||||
public var winner(default, null):Null<TeamId>;
|
public var winner(default, null):Null<TeamId>;
|
||||||
|
|
||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import ru.m.tankz.core.Eagle;
|
|||||||
import ru.m.tankz.core.Entity;
|
import ru.m.tankz.core.Entity;
|
||||||
import ru.m.tankz.core.EntityType;
|
import ru.m.tankz.core.EntityType;
|
||||||
import ru.m.tankz.core.Tank;
|
import ru.m.tankz.core.Tank;
|
||||||
import ru.m.tankz.engine.Engine;
|
import ru.m.tankz.engine.IEngine;
|
||||||
import ru.m.tankz.game.Game;
|
import ru.m.tankz.game.IGame;
|
||||||
import ru.m.tankz.game.Spawner;
|
import ru.m.tankz.game.Spawner;
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
@@ -232,6 +232,10 @@ class GameRunner implements EngineListener implements GameListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onMove(entity:EntityType):Void {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private function spawnBonus(?type:BonusType):Void {
|
private function spawnBonus(?type:BonusType):Void {
|
||||||
var bonusConfig:BonusConfig = type != null ? game.config.getBonus(type) : game.config.bonuses[Math.floor(Math.random() * game.config.bonuses.length)];
|
var bonusConfig:BonusConfig = type != null ? game.config.getBonus(type) : game.config.bonuses[Math.floor(Math.random() * game.config.bonuses.length)];
|
||||||
var bonus = new Bonus(bonusConfig);
|
var bonus = new Bonus(bonusConfig);
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ package ru.m.tankz.game;
|
|||||||
|
|
||||||
import haxework.signal.Signal;
|
import haxework.signal.Signal;
|
||||||
import ru.m.tankz.config.Config;
|
import ru.m.tankz.config.Config;
|
||||||
import ru.m.tankz.engine.Engine;
|
import ru.m.tankz.engine.IEngine;
|
||||||
import ru.m.tankz.game.Game;
|
|
||||||
import ru.m.tankz.Type;
|
import ru.m.tankz.Type;
|
||||||
|
|
||||||
interface IGame {
|
interface IGame {
|
||||||
public var type(default, null):GameType;
|
public var type(default, null):GameType;
|
||||||
public var teams(default, null):Map<TeamId, Team>;
|
public var teams(default, null):Map<TeamId, Team>;
|
||||||
public var config(default, null):Config;
|
public var config(default, null):Config;
|
||||||
public var engine(default, null):Engine;
|
public var engine(default, null):IEngine;
|
||||||
public var winner(default, null):Null<TeamId>;
|
public var winner(default, null):Null<TeamId>;
|
||||||
public var state(default, null):GameState;
|
public var state(default, null):GameState;
|
||||||
|
|
||||||
public var gameEventSignal(default, null):Signal<GameEvent>;
|
public var gameEventSignal(default, null):Signal<GameEvent>;
|
||||||
|
|
||||||
public function connect(listener:GameListener):Void;
|
public function connect(listener:GameListener):Void;
|
||||||
@@ -25,3 +25,7 @@ interface IGame {
|
|||||||
|
|
||||||
public function getPlayer(playerId:PlayerId):Player;
|
public function getPlayer(playerId:PlayerId):Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface GameListener {
|
||||||
|
public function onGameEvent(event:GameEvent):Void;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package ru.m.tankz.game.record;
|
|||||||
|
|
||||||
import flash.events.Event;
|
import flash.events.Event;
|
||||||
import flash.Lib;
|
import flash.Lib;
|
||||||
import ru.m.tankz.game.Game.GameListener;
|
import ru.m.tankz.game.IGame;
|
||||||
|
|
||||||
class GameRecorder implements GameListener {
|
class GameRecorder implements GameListener {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user