[common] bullet with bricks collision
This commit is contained in:
@@ -19,7 +19,7 @@ import haxework.provider.Provider;
|
||||
import haxework.gui.frame.FrameSwitcher;
|
||||
import haxework.gui.Root;
|
||||
import openfl.Assets;
|
||||
import ru.m.core.connect.IConnection;
|
||||
import ru.m.connect.IConnection;
|
||||
import haxework.log.TraceLogger;
|
||||
|
||||
@:template("layout/main.json", "layout/styles.json")
|
||||
@@ -56,9 +56,9 @@ class Client implements IConnectionHandler {
|
||||
|
||||
Provider.set(IPacketBuilder, new PacketBuilder());
|
||||
#if flash
|
||||
Provider.set(IConnection, new ru.m.core.connect.flash.FlashConnection("localhost", 5001));
|
||||
Provider.set(IConnection, new ru.m.connect.flash.FlashConnection("localhost", 5001));
|
||||
#elseif html5
|
||||
Provider.set(IConnection, new ru.m.core.connect.js.JsConnection("localhost", 5001));
|
||||
Provider.set(IConnection, new ru.m.connect.js.JsConnection("localhost", 5001));
|
||||
#end
|
||||
|
||||
Provider.get(IConnection).handler.addListener(this);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ru.m.tankz.core;
|
||||
|
||||
import ru.m.geom.Direction;
|
||||
import flash.events.FocusEvent;
|
||||
import flash.ui.Keyboard;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
|
||||
@@ -3,7 +3,8 @@ package ru.m.tankz.render;
|
||||
import haxework.gui.IView;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
|
||||
|
||||
interface IRender extends IView {
|
||||
public function draw(game:IEngine):Void;
|
||||
public function reset():Void;
|
||||
public function draw(game:IEngine):Void;
|
||||
public function reset():Void;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package ru.m.tankz.render;
|
||||
|
||||
import ru.m.tankz.core.IMobileEntity;
|
||||
import ru.m.tankz.core.Entity;
|
||||
import ru.m.tankz.map.Brick;
|
||||
import ru.m.tankz.core.Direction;
|
||||
import ru.m.geom.Direction;
|
||||
import flash.geom.Matrix;
|
||||
import openfl.Assets;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
@@ -38,9 +39,9 @@ class EntityState implements IState<Entity> {
|
||||
public function new() {}
|
||||
|
||||
public function update(object:Entity):Bool {
|
||||
if (x != object.x || y != object.y) {
|
||||
x = object.x;
|
||||
y = object.y;
|
||||
if (x != object.rect.x || y != object.rect.y) {
|
||||
x = object.rect.x;
|
||||
y = object.rect.y;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -90,7 +91,7 @@ class Render extends SpriteView implements IRender {
|
||||
layersForUpdate[upLayer] = true;
|
||||
}
|
||||
}
|
||||
for (entry in game.mobileEntities) {
|
||||
for (entry in game.entities) {
|
||||
if (!states.exists(entry.key)) {
|
||||
states[entry.key] = new EntityState();
|
||||
}
|
||||
@@ -98,6 +99,12 @@ class Render extends SpriteView implements IRender {
|
||||
layersForUpdate[entryLayer] = true;
|
||||
}
|
||||
}
|
||||
for (key in game.removedEntities) {
|
||||
if (states.exists(key)) {
|
||||
states.remove(key);
|
||||
layersForUpdate[entryLayer] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function drawBackground(game:IEngine):Void {
|
||||
@@ -150,20 +157,21 @@ class Render extends SpriteView implements IRender {
|
||||
if (layersForUpdate[entryLayer]) {
|
||||
var g:Graphics = entryLayer.graphics;
|
||||
g.clear();
|
||||
for (e in game.mobileEntities) {
|
||||
for (ent in game.entities) if (Std.is(ent, IMobileEntity)) {
|
||||
var e:IMobileEntity = cast ent;
|
||||
if (Std.is(e, Tank)) {
|
||||
var m = new Matrix();
|
||||
m.rotate(calcRotate(e.direction));
|
||||
m.translate(e.x, e.y);
|
||||
m.translate(e.rect.x, e.rect.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.drawRect(e.rect.x, e.rect.y, e.rect.width, e.rect.height);
|
||||
g.endFill();
|
||||
} else if (Std.is(e, Bullet)) {
|
||||
var m = new Matrix();
|
||||
m.rotate(calcRotate(e.direction));
|
||||
m.translate(e.x, e.y);
|
||||
m.translate(e.rect.x, e.rect.y);
|
||||
g.beginBitmapFill(Assets.getBitmapData("resources/images/bullet/bullet_0.png"), m);
|
||||
g.drawRect(e.x, e.y, e.width, e.height);
|
||||
g.drawRect(e.rect.x, e.rect.y, e.rect.width, e.rect.height);
|
||||
g.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
import protohx.Message;
|
||||
import ru.m.tankz.proto.pack.GameUpdateResponse;
|
||||
import ru.m.core.connect.IConnection;
|
||||
import ru.m.connect.IConnection;
|
||||
import haxework.gui.ViewBuilder;
|
||||
import ru.m.tankz.config.Config;
|
||||
import flash.events.Event;
|
||||
|
||||
Reference in New Issue
Block a user