The Homepage of Daniel Hollands: Web Development Graduate!
6 Mar 2009
Here it is, my second published Flash production
It’s not finished yet, as I still need to do things like make a score count only when clicked (like shooting a gun), then add things like ammo and the ability to reload, enemies to avoid, and then make the sprites more interesting (like a crosshair for the hunter, and some random monsters for the prey), but I’m proud of what I have so far.
Once again, here is the code used to make it.
// import classes
import flash.display.Sprite;
import flash.events.MouseEvent;
Mouse.hide();
/* functions */
// generates a random number
function randomBetween(a:Number, b:Number):Number {
return (a + Math.floor(Math.random()*(b-a+1)));
}
// hunter movement
function pullHunter(event:Event)
{
hunter.x = mouseX;
hunter.y = mouseY;
}
// checks if hunter hits prey
function checkHit(event:Event)
{
if (hunter.hitTestObject(prey))
{
prey.x = randomBetween(20, 530);
prey.y = randomBetween(20, 380);
score++;
scoreBoard.text = score.toString();
}
}
/* load objects */
// load prey object
var prey:Sprite = new Sprite();
prey.graphics.beginFill(0xffffff);
prey.graphics.drawCircle(0,0,20);
// move to random location
prey.x = randomBetween(20, 530);
prey.y = randomBetween(20, 380);
addChild(prey);
// load hunter object
var hunter:Sprite = new Sprite();
hunter.graphics.beginFill(0xFF0000);
hunter.graphics.drawCircle(0,0,10);
addChild(hunter);
// load scoreboard object
//var scoreBoard:TextField = new TextField();
//addChild(scoreBoard);
// load score
var score:Number = new Number();
score = 0;
scoreBoard.text = score.toString();
/* listners */
addEventListener(Event.ENTER_FRAME, pullHunter);
addEventListener(Event.ENTER_FRAME, checkHit);
One Response for "Hunter game – so far…"
[...] should be a huge improvement over Hunter, in both game play and [...]