The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.38 / 5.00 36,385 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 13,902 ViewsonClipEvent (enterFrame) {
if (Key.isDown(87)) {
speed += 5;
}
if (Key.isDown(83)) {
speed -= 5;
}
if (Math.abs(speed)>20) {
speed *= .7;
}
if (Key.isDown(65)) {
_rotation -= 15;
}
if (Key.isDown(68)) {
_rotation += 15;
}
speed *= .60;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*speed*-1
;
if (!_root.land.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.8;
}
}
This code has been retrieved from a tutorial here in Newgrounds. In some reason the code does not work. The MC does rotate, but it doesn't move fovard or backward.
PS. I replaced the arrow keys with WASD buttons, but the problem existed before the replacement.
you need to declare the value of speed before you can change it. place this code before your code:
onClipEvent(load){
var speed:Number = 0;
}
onClipEvent(load){
speed= 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(87)) {
_x +=speed;
}
if (Key.isDown(83)) {
_x -=speed;
}
if (Math.abs(speed)>20) {
speed *= .7;
}
if (Key.isDown(65)) {
_rotation -= 15;
}
if (Key.isDown(68)) {
_rotation += 15;
}