I'm new on here and needing a little help. Basically I'm designing a Pac-man like game which it has to be based on Wind in the Willows, so Mole-man it is!!
Anyway, I've done the basics of it, I've made my 2d mole, made him move, made him react to button presses etc. and now trying to get the walls to work, starting with the outer walls.
I made 4 rectangles around the edge, merged them to one shape and called it "outerWalls". I've been using hitTestObject to try and get it to work but with no success.
I did a test to make it work with moleman.xIncrement = -5 which makes him immediately move backwards without touching any walls. I am curious as to if this is because he is inside of the walls and it classes 4 outer walls as a square overall and as he is already inside the theoretical square moves him out? I am unsure. Have some code!!
Actions layer - frame 1:
import flash.events.KeyboardEvent;
var moleman = this.addChild(new Moleman_mc());
moleman.x = 100;
moleman.y = 200;
moleman.width = 24;
moleman.height = 24;
moleman.xIncrement = 5;
moleman.yIncrement = 0;
stage.addEventListener(KeyboardEvent.KEY_DOWN, doKeyDown);
function doKeyDown (e:KeyboardEvent):void
{
switch(e.keyCode)
{
case Keyboard.UP:
moleman.xIncrement = 0;
moleman.yIncrement = -5;
moleman.rotation = -90;
break;
case Keyboard.DOWN:
moleman.xIncrement = 0;
moleman.yIncrement = 5;
moleman.rotation = 90;
break;
case Keyboard.LEFT:
moleman.xIncrement = -5;
moleman.yIncrement = 0;
moleman.rotation = 180;
break;
case Keyboard.RIGHT:
moleman.xIncrement = 5;
moleman.yIncrement = 0;
moleman.rotation = 0;
break;
}
}
Actions layer - frame 2:
import flash.events.Event;
var collectCounter:int = 0;
moleman.x += moleman.xIncrement;
moleman.y += moleman.yIncrement;
if(moleman.hitTestObject(collect))
{
collectCounter ++;
collect.visible = false;
}
moleman.addEventListener(Event.ENTER_FRAME, wallHit);
function wallHit(event:Event):void
{
if(moleman.hitTestObject(outerWalls))
{
moleman.stop();
}
}
Actions layer - frame 3:
gotoAndPlay(2);
In addition, I cannot get the collect (e.g. collectables) to work, the plan would be to make it so each time you collect one "collect" item, that one disappears, you add one to collectCounter but all others stay visible. Currently if you collect one "collect" item, moleman just stops and stays where he is while another moleman appears and continues, not very useful. Any help on this would also be appreciated, not sure where to take it from there.
Any help is much appreciated, I am new at this but hoping it can go well :)
All help is much appreciated. John.