Okay, I’m writing a simple game to learn AS3, basically, sasquatches walk down the screen and stop when they get to a barrier, they attack the barrier until it breaks down and then beat the player if they have not shot down the sasquatch by this point(pseudo 1st person shooter basically like those annoying shoot whatever banner ads). So far I have sasquatches being created, walking down the screen, registering contact with the wall, but I’m not sure how to get the sasquatch to stop walking at the wall, not sure how to pass Y value. Code for 3 different files below. I figure I need to change the y++ value in the Sasquatch file, but how?
Main file/code
package{
import flash.display.*;
import flash.events.*;
public class SQD extends MovieClip{
//an array and a wall to bump into
public var squatchArray:Array = new Array();
public var bigWall:Wall = new Wall();
//this function instantiates a Wall, listens for collision and mouse press and creates 3 Sasquatches
public function SQD(){
addChild(bigWall);
stage.addEventListener(Event.ENTER_FRAME, collide2);
for(var i:int =0; i<3; i++){
squatchArray.push(new Sasquatch());
var s:Sasquatch = squatchArray*;
s.addEventListener(MouseEvent.MOUSE_DOWN, attack);
s.x = Math.random()* 500;
s.y = Math.random()* 20;
addChild(s);
}
}
//checks when stage is clicked whether it hits sasquatch
public function attack(m:MouseEvent){
trace('Kung Fu Attack');
var s:* = m.currentTarget;
if(s.hitTestPoint(m.stageX, m.stageY, true)){
trace(s.name + " Kung Fu Attacks!");
}
}
//checks if "walking" sasquatches are bumping into wall
public function collide2(evt:Event){
for(var z:int = 0; z<3; z++){
if(squatchArray[z].hitTestObject(bigWall)){
trace('Wall collisions');
}
}
}
}
}
Sasquatch file/code
package{
import flash.display.*;
import flash.events.*;
//when Sas is created adds event listener that gets him moving.
public class Sasquatch extends MovieClip{
public function Sasquatch(){
trace('this works too');
this.addEventListener(Event.ENTER_FRAME, sasMove);
}
//walks sas down the screen
public function sasMove(Evt:Event){
trace('I am moving!');
this.y ++;
}
}
}
Wall code
package{
import flash.display.*;
import flash.events.*;
//gives location for wall (bottome center of screen)
public class Wall extends MovieClip{
public function Wall(){
this.x = 275;
this.y = 350;
}
}
}
help