At 9/20/14 12:06 PM, Etherblood wrote:
At 9/20/14 09:35 AM, 512Pixel wrote:
Dividing the player postion by the tile width and then rounding the number up( the math.round method).
I don't know exactly what this post is intended to do? (Is this a question? There is no question.)
But normally you would use math.floor (round down), not math.round to calculate the array index.
I have now placed the code below. I idn htink the code would help . but i do have an issue the player at some point will always be haflway between a tile. he palyer for exmple on tile1 andtile 2 . This now means i am unable to use a collision detection just by using the tiles in the arraay . As the palyer at some point is inbetween . The array is then either give one resultor the other . its a chioce between tile 1 or tile2.
does anyoneknow a solution to thiis would i set up a 4 corner collision detection
I have been looking and think sometimes set up a 4 point corner collision detection
var mapWidth = 5;
var mapHeight = 4;
var tileWidth = 100;
var tileHeight = 100;
var pets:Array = [
["bockStart","block1",1,0,],
["2nd row","bottblock2",1,0,],
[0,1,1,0,],
[0,0,0,1,1,]
];
for (var i:int=0; i<mapHeight; i++)
{
for (var u:int=0; u<mapWidth; u++){
var cell:MovieClip = new tile();
cell.gotoAndStop(pets[i][u]+1);
cell.x=tileWidth*u
cell.y=tileHeight*i
addChild(cell);
}
};
//based on 100 pixels
//box3.x=0;box3.y=0;
//box4.x=100;box4.y=0;
//
///_______________________________________________________________________________________________
var player2:MovieClip = new player();
addChild(player2);
player2.width = 100;
player2.height = 100;
var playerWidth = player2.width ;
trace("playerWidth = " + playerWidth );
var playerStart = player2.y= 50;
//trace(playerStart);
var speed =5;
//___________________________________________________________________________________________________
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void{
var playerPosRight = player2.x + 50 ;
var colPos =playerPosRight/tileWidth ;
var playerPosY = player2.y + 50;
var rowPos:Number =playerPosY/tileWidth ;
if (e.keyCode == Keyboard.RIGHT){
player2.x += speed;
trace("player2.x" + player2.x );
trace("playerPosRight " +playerPosRight );
trace(pets[rowPos][colPos]);
if(pets[rowPos][colPos] ==1){
player2.x += -25;
trace("hit");
}
}
if (e.keyCode == Keyboard.LEFT){
player2.x += -speed;
}
if (e.keyCode == Keyboard.DOWN){
player2.y += speed;
trace(player2.y)
trace(playerPosY );
trace("colPos = " + colPos);
trace("rowPos = " + rowPos);
trace( "col pos and row" +pets[rowPos][colPos]);
if(pets[rowPos][colPos] ==1){
player2.y += -25;
trace("hit");
}
}
if (e.keyCode == Keyboard.UP){
player2.y += -speed;
}
}