声明:本文为刘兴(http://deepfuture.iteye.com/)原创,如转载请注明来源http://deepfuture.iteye.com/blog/722156
gamemain.as /******************************************************************************* * PushButton Engine * Copyright (C) 2009 PushButton Labs, LLC * For more information see http://www.pushbuttonengine.com * * This file is licensed under the terms of the MIT license, which is included * in the License.html file at the root directory of this SDK. ******************************************************************************/ package mymain { import flash.display.Sprite; import com.pblabs.engine.PBE; import tools.mygameapi; [SWF(width="800", height="600", frameRate="60")] public class gamemain extends Sprite { public function gamemain() { // Start up PBE PBE.startup(this); new MyRes(); // Set up a simple scene entity mygameapi.createScene(); // Create a simple avatar entity mygameapi.createPlane(); mygameapi.createBackground(); // createDd(); } } } DdControllerComponent.as package mymain { import com.pblabs.engine.PBE; import com.pblabs.engine.components.TickedComponent; import com.pblabs.engine.entity.PropertyReference; import flash.geom.Point; public class DdControllerComponent extends TickedComponent { public var positionReference:PropertyReference; public var dname:String; public function DdControllerComponent(name:String){ dname=name; } // onTick() is called every frame public override function onTick(tickRate:Number):void { var position:Point = owner.getProperty(positionReference); // Look at our input keys to see which direction we should move. Left is -x, right is +x. position.y-=5; // Finally, add some boundary limits so that we don't go off the edge of the screen. if (position.y > 260 || position.y < -260) { // Set our position at the wall edge position.y=-400; } // Send our manipulated spatial variables back to the spatial manager owner.setProperty(positionReference, position); if (position.y==-400){ owner.removeComponent(owner.lookupComponentByName(dname+"Render")); owner.removeComponent(owner.lookupComponentByName(dname+"Controller")); } } } } PlaneControllerComponent.as /******************************************************************************* * PushButton Engine * Copyright (C) 2009 PushButton Labs, LLC * For more information see http://www.pushbuttonengine.com * * This file is licensed under the terms of the MIT license, which is included * in the License.html file at the root directory of this SDK. ******************************************************************************/ package mymain { import com.pblabs.engine.PBE; import com.pblabs.engine.components.TickedComponent; import com.pblabs.engine.core.InputKey; import com.pblabs.engine.entity.PropertyReference; import com.pblabs.rendering2D.*; import flash.display.Sprite; import flash.geom.Point; import tools.mygameapi; // Make a ticked component so that it can update itself every frame with onTick() public class PlaneControllerComponent extends TickedComponent { // Keep a property reference to our entity's position. public var positionReference:PropertyReference; public var ddno:uint; public function PlaneControllerComponent() { ddno=0; } // onTick() is called every frame public override function onTick(tickRate:Number):void { var position:Point = owner.getProperty(positionReference); // Look at our input keys to see which direction we should move. Left is -x, right is +x. if (PBE.isKeyDown(InputKey.RIGHT)) { // Move our hero to the right position.x += 15; } if (PBE.isKeyDown(InputKey.LEFT)) { // Move our hero to the left position.x -= 15; } if (PBE.isKeyDown(InputKey.UP)) { // Move our hero to the right position.y -= 15; } if (PBE.isKeyDown(InputKey.DOWN)) { // Move our hero to the left position.y += 15; } if (PBE.isKeyDown(InputKey.F)) { // Move our hero to the left createDd(new Point(position.x,position.y-80)); } // Finally, add some boundary limits so that we don't go off the edge of the screen. if (position.x > 375) { // Set our position at the wall edge position.x = 375; } else if (position.x < -375) { // Set our position at the wall edge position.x = -375; } if (position.y > 260) { // Set our position at the wall edge position.y = 260; } else if (position.y < -260) { // Set our position at the wall edge position.y = -260; } // Send our manipulated spatial variables back to the spatial manager owner.setProperty(positionReference, position); } private function createDd(firstpos:Point):void { // Allocate an entity for our hero avatar var ddname:String=ddno.toString(); mygameapi.createSpatial( owner, // with location of 0,0... firstpos, ddname+"Spatial", new Point(10,50) ); if (ddno
注意按F键发导弹