onsdag 14. oktober 2009

shooting

I started by creating a new child, "the bullet" i created it innside a click function. the problem whit this was that i did not have eany access to it outside the function "i need it in update so that i can get the bullets to fly." so i moved decleration of bullet to the global variable area. that made me able to access bullet outside. next problem was to get it moving the same speed in the right derection, after much testing and failing i turned to math, and found that the "unit circle" was what i needed to find out. so i tested sine and cosine to find the "unit circle" x and y cordinates reletive to the mouse and the charecter. but got wild nubers that i was unable to use, or figure out. so i went over to Pytagoras to find the "unit circle" x and y, this worked perfectly.
code i ended up using:

var a:int = _karakter.y - mouseY;
var b:int = _karakter.x - mouseX;

var total:Number = Math.sqrt(a * a + b * b);
var ferdigx:Number = b / total;
var ferdigy:Number = a / total;

bullet.x -= (ferdigx * 6);
bullet.y -= (ferdigy * 6);

mandag 12. oktober 2009

Coding 2 keybord and sprite

I coded the keybord first outside the update function"the one that updates the screen for each frame" doing this i had problems whit moving in 2 directions at a time. "exs: left and up, which only made the charecter go left or up.. the first key that was hit". and it wold have created a other problem when i fixed the animation."it wold have restarted the animation each time a key was hit". so i moved it to the update function which fixed the movment problem. the sprite was too hard to wrap my head around so i w8 whit it to the walk trough in class. It was no problem's implementing it after that.