Permalink
Browse files

send message added.

  • Loading branch information...
1 parent 5aeb5a1 commit 7a30d54cb2cd40bbca0294d4f119c627d249fff2 @MindScriptAct committed Mar 28, 2012
@@ -1,5 +1,6 @@
package com.mindScriptAct.liveSample.engine.hero {
import com.mindScriptAct.liveSample.constants.MainConfig;
+import com.mindScriptAct.liveSample.messages.EngineMsg;
import com.mindScriptAct.liveSample.view.hero.Hero;
import flash.geom.Point;
import org.mvcexpress.live.Process;
@@ -26,7 +27,7 @@ public class HeroProcess extends Process {
}
override public function run(timer:int):void {
- trace("HeroProcess.run > timer : " + timer);
+ //trace("HeroProcess.run > timer : " + timer +" "+ (lastRunTime-timer));
// move
heroPosition.x += heroDirection.x;
@@ -36,20 +37,24 @@ public class HeroProcess extends Process {
if (heroPosition.x < 0) {
heroPosition.x = -heroPosition.x;
heroDirection.x *= -1;
+ sendMessage(EngineMsg.BORDER_HIT, new Point(0, heroPosition.y));
}
if (heroPosition.x > MainConfig.PLAY_AREA_WIDTH) {
var xOver:int = heroPosition.x - MainConfig.PLAY_AREA_WIDTH;
heroPosition.x = MainConfig.PLAY_AREA_WIDTH - xOver;
heroDirection.x *= -1;
+ sendMessage(EngineMsg.BORDER_HIT, new Point(MainConfig.PLAY_AREA_WIDTH, heroPosition.y));
}
if (heroPosition.y < 0) {
heroPosition.y = -heroPosition.y;
heroDirection.y *= -1;
+ sendMessage(EngineMsg.BORDER_HIT, new Point(heroPosition.x, 0));
}
if (heroPosition.y > MainConfig.PLAY_AREA_HEIGHT) {
var yOver:int = heroPosition.y - MainConfig.PLAY_AREA_HEIGHT;
heroPosition.y = MainConfig.PLAY_AREA_HEIGHT - yOver;
heroDirection.y *= -1;
+ sendMessage(EngineMsg.BORDER_HIT, new Point(heroPosition.x, MainConfig.PLAY_AREA_HEIGHT));
}
// render
@@ -0,0 +1,11 @@
+package com.mindScriptAct.liveSample.messages {
+
+/**
+ * COMMENT
+ * @author Object
+ */
+public class EngineMsg {
+
+ static public const BORDER_HIT:String = "borderHit";
+}
+}
@@ -11,6 +11,7 @@ public class PlayArea extends Sprite {
public function PlayArea() {
this.graphics.lineStyle(0.1, 0xFF0000);
+ this.graphics.beginFill(0xF4F4F4);
this.graphics.drawRect(0, 0, MainConfig.PLAY_AREA_WIDTH, MainConfig.PLAY_AREA_HEIGHT);
this.graphics.endFill();
@@ -2,7 +2,9 @@ package com.mindScriptAct.liveSample.view.playArea {
import com.mindScriptAct.liveSample.constants.FrameTickerId;
import com.mindScriptAct.liveSample.engine.hero.HeroProcess;
import com.mindScriptAct.liveSample.messages.DataMsg;
+import com.mindScriptAct.liveSample.messages.EngineMsg;
import com.mindScriptAct.liveSample.view.hero.Hero;
+import com.mindScriptAct.liveSample.view.playArea.components.CrossMark;
import flash.geom.Point;
import org.mvcexpress.mvc.Mediator;
@@ -19,16 +21,25 @@ public class PlayAreaMediator extends Mediator {
//[Inject]
//public var myProxy:MyProxy;
+ private var cross:CrossMark;
+
override public function onRegister():void {
hero = new Hero();
view.addChild(hero);
mediatorMap.mediate(hero);
processMap.injectTo(HeroProcess, HeroProcess.NAME, hero);
-
+ cross = new CrossMark();
+ view.addChild(cross);
+ addHandler(EngineMsg.BORDER_HIT, handleBorderHit);
}
+ public function handleBorderHit(hitPoint:Point):void {
+ cross.x = hitPoint.x;
+ cross.y = hitPoint.y;
+ }
+
override public function onRemove():void {
@@ -0,0 +1,20 @@
+package com.mindScriptAct.liveSample.view.playArea.components {
+ import flash.display.Shape;
+
+
+/**
+ * COMMENT
+ * @author Object
+ */
+public class CrossMark extends Shape {
+
+ public function CrossMark() {
+ this.graphics.lineStyle(5, 0x008000);
+ this.graphics.moveTo( -10, -10);
+ this.graphics.lineTo( 10, 10);
+ this.graphics.moveTo( 10, -10);
+ this.graphics.lineTo( -10, 10);
+ }
+
+}
+}
@@ -87,6 +87,7 @@ public class ProcessMap implements IProcessMap {
use namespace pureLegsCore;
Process.canConstruct = true;
var process:Process = new processClass() as Process;
+ process.messanger = messenger;
Process.canConstruct = false;
if (!process) {
throw Error("Process creation failed. processClass must extend Procoss class.");
@@ -2,6 +2,7 @@
package org.mvcexpress.live {
import flash.utils.Dictionary;
import org.mvcexpress.namespace.pureLegsCore;
+import org.mvcexpress.messenger.Messenger;
/**
* COMMENT
@@ -10,6 +11,9 @@ import org.mvcexpress.namespace.pureLegsCore;
public class Process {
static pureLegsCore var canConstruct:Boolean;
+
+ /** @private */
+ pureLegsCore var messanger:Messenger;
pureLegsCore var isRunning:Boolean = false;
@@ -49,6 +53,15 @@ public class Process {
protected function addMessageSender():void {
}
+
+ /**
+ * Sends a message with optional params object.
+ * @param type type of the message for Commands and handle function to react to.
+ * @param params Object that will be passed to Command execute() function and to handle functions.
+ */
+ protected function sendMessage(type:String, params:Object = null):void {
+ pureLegsCore::messanger.send(type, params);
+ }
}
}

0 comments on commit 7a30d54

Please sign in to comment.