Hey guys. Well I got bored and decided to make a small game.
But I have ran into an issue with making walls, ages ago I downloaded a source code for a game with hit detection for walls, and I thought it was decent enough to use here. Its just a Boolean for everytime someone comes in counter with a wall. There are no errors, it is just not very effective. Any tips on making this work more realistic, currently I can go into the wall but it does push me out, and if I go in threw the top of the wall it just pushes me threw (I know what causes it, as I am just adding onto the X and Y coordinate, but I can't think of anything to fix that. Thanks!
ActionScript Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, right);
stage.addEventListener(KeyboardEvent.KEY_DOWN, left);
stage.addEventListener(KeyboardEvent.KEY_DOWN, up);
stage.addEventListener(KeyboardEvent.KEY_DOWN, down);
var hitWall:Boolean = false;
var player:Shape = new Shape();
player.graphics.beginFill(0x0000FF);
player.graphics.drawCircle(5, 5, 5);
player.y = 350;
addChild(player);
var theWall:wall = new wall();
addChild(theWall);
var checkDec:Timer = new Timer(1);
checkDec.addEventListener(TimerEvent.TIMER, checkHitDec);
checkDec.start();
function checkHitDec(event:TimerEvent) : void {
if(Shape(player).hitTestObject(theWall)) {
hitWall=true;
player.x += 1
player.y += 2
hitWall=false
}
}
function up(bmove:KeyboardEvent):void{
if (bmove.keyCode==Keyboard.UP && hitWall==false){
player.y-= 10
}
};
function down(bmove:KeyboardEvent):void{
if (bmove.keyCode==Keyboard.DOWN && hitWall==false){
player.y+= 10
}
};
function right(bmove:KeyboardEvent):void{
if (bmove.keyCode==Keyboard.RIGHT && hitWall==false){
player.x+= 10
}
};
function left(bmove:KeyboardEvent):void{
if (bmove.keyCode==Keyboard.LEFT && hitWall==false) {
player.x-= 10
}
};