home *** CD-ROM | disk | FTP | other *** search
- package game
- {
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.TimerEvent;
-
- public class GameObject extends EventDispatcher
- {
-
-
- public var y:Number;
-
- public var vx:Number = 0;
-
- private var theGame:Game;
-
- public var vy:Number = 0;
-
- public var h:Number;
-
- public var w:Number;
-
- public var ay:Number = 0;
-
- public var ax:Number = 0;
-
- public var x:Number;
-
- public function GameObject(x:int, y:int, w:int, h:int, vx:Number = 0, vy:Number = 0)
- {
- super();
- this.theGame = theGame;
- this.x = x;
- this.y = y;
- this.w = w;
- this.h = h;
- this.vx = vx;
- this.vy = vy;
- }
-
- public function getW() : int
- {
- return w;
- }
-
- public function getX() : int
- {
- return x;
- }
-
- public function move(event:TimerEvent) : void
- {
- if(x < 0)
- {
- vx = -vx;
- x = 0;
- }
- if(x + w > 640)
- {
- vx = -vx;
- x = 640 - w;
- }
- x += vx;
- dispatchEvent(new Event("objectChanged"));
- }
-
- public function setPos(x:int, y:int) : void
- {
- this.x = x;
- this.y = y;
- dispatchEvent(new Event("objectChanged"));
- }
-
- public function isInside(obj:GameObject) : Boolean
- {
- if(x >= obj.x && x <= obj.x + obj.w && y >= obj.y && y <= obj.y + obj.h)
- {
- return true;
- }
- if(x + w >= obj.x && x + w <= obj.x + obj.w && y >= obj.y && y <= obj.y + obj.h)
- {
- return true;
- }
- if(x >= obj.x && x <= obj.x + obj.w && y + h >= obj.y && y + h <= obj.y + obj.h)
- {
- return true;
- }
- if(x + w >= obj.x && x + w <= obj.x + obj.w && y + h >= obj.y && y + h <= obj.y + obj.h)
- {
- return true;
- }
- if(x <= obj.x && x + w >= obj.x + obj.w && y >= obj.y && y + h <= obj.y + obj.h)
- {
- return true;
- }
- if(x >= obj.x && x + w <= obj.x + obj.w && y <= obj.y && y + h >= obj.y + obj.h)
- {
- return true;
- }
- return false;
- }
-
- public function distanceTo(obj:GameObject) : Number
- {
- return Math.sqrt(Math.pow(x + w / 2 - (obj.x + obj.w / 2),2) + Math.pow(y + h / 2 - (obj.y + obj.h / 2),2));
- }
-
- public function update() : void
- {
- dispatchEvent(new Event("objectChanged"));
- }
-
- public function getY() : int
- {
- return y;
- }
-
- public function getH() : int
- {
- return h;
- }
-
- public function destroy() : void
- {
- dispatchEvent(new ObjectChangedEvent(this,"objectDestroyed"));
- Game.timer.removeEventListener("timer",move);
- }
- }
- }
-