So i'm making my first as3 game and its just a simple avoider style game. I've got most of the basics working but the objects that are being avoided are circles and since im using hitTestObject i get a square hit box :p. Is it possible to create a circular hit box?
Heres my code
ActionScript Code: package { import flash.display.*; import flash.events.*; import flash.text.*; import flash.utils.Timer; import flash.utils.getDefinitionByName; public class mattGame extends MovieClip { var ship:Ship; var gameTimer:Timer; var army:Array; var score:int = 0; const speed:Number = 7.0; public function mattGame() { army = new Array(); var newEnemy = new Enemy( 250, -15 ); army.push( newEnemy ); addChild( newEnemy ); ship = new Ship(); addChild(ship); gameTimer = new Timer( 25 ); gameTimer.addEventListener( TimerEvent.TIMER, onTick ); gameTimer.start(); } public function onTick( timerEvent:TimerEvent ):void { if ( Math.random() < 0.1 ){ var randomX:Number = Math.random() * 500; var newEnemy:Enemy = new Enemy( randomX, -15 ); army.push( newEnemy ); addChild( newEnemy ); } ship.x = mouseX; ship.y = mouseY; for each ( var enemy:Enemy in army ){ enemy.moveDownABit(); if ( ship.hitTestObject( enemy ) ){ gameTimer.stop(); } } } }}
end the enemy class to
ActionScript Code: package { import flash.display.MovieClip; public class Enemy extends MovieClip { public function Enemy( startX:Number, startY:Number ) { x = startX; y = startY; } public function moveDownABit():void { y = y + 7; } }}
can a round hit box be made?
Thursday, May 31, 2012
[Action Script] can a round hit box be made? May,2012
Posted by Bimo Hery Prabowo at 3:13 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment