The Homepage of Daniel Hollands: Web Development Graduate!
8 Mar 2009
Presenting Hunter 2
This should be a huge improvement over Hunter, in both game play and graphics.
The game play now requires that you click to shoot the enemy, rather than just hover over it like in the previous game, which works fine, apart from the fact that in order for the click to register as a hit, the cross-hair graphic ends up behind the enemy, rather than on top. I also built in a function that makes this site load when you click on the logo in the bottom right corner – but the same issue that causes a problem with the cross-hair and monster, means that this feature also doesn’t work.
I’m going to work on Hunter 3 today, and hopefully by the end of the week it should be finished. This should provide some additional improvements over that of Hunter 2 by including features such as limited ammo, with the ability to reload, a sound when the gun is fired, a gradual fading in of the monster when it reappears, an explosion to indicate that the monster has been hit, and a working link back to the homepage. It should also be more modular as I start to explore some of the OO aspects of ActionScript.
Before I post the code for this game, I would like to very much thank Sofi for providing the graphics and concept for the night vision, one which I think works fantastically well. Anyway, here is the code.
// hide the mouse
Mouse.hide();
var link:URLRequest = new URLRequest("http://www.theworldofdan.co.uk/");
/* functions */
// generates a random number
function randomBetween(a:Number, b:Number):Number
{
return (a + Math.floor(Math.random()*(b-a+1)));
}
function shootPrey(event:MouseEvent):void
{
// trace("Hit");
prey_mc.x = randomBetween(50, 500);
prey_mc.y = randomBetween(50, 350);
score = score+1000;
scoreBoard.text = score.toString();
}
// hunter movement
function moveHunter(event:Event)
{
hunter_mc.x = mouseX-30;
hunter_mc.y = mouseY-30;
}
// load homepage
function loadHomepage(event:Event)
{
navigateToURL(link);
}
/* main code */
// move prey
prey_mc.x = randomBetween(50, 500);
prey_mc.y = randomBetween(50, 350);
// load score
var score:Number = new Number();
score = 0;
scoreBoard.text = score.toString();
/* listeners */
hunter_mc.addEventListener(Event.ENTER_FRAME, moveHunter);
prey_mc.addEventListener(MouseEvent.CLICK, shootPrey);
logo_mc.addEventListener(MouseEvent.CLICK, loadHomepage);