00:00
00:00
Newgrounds Background Image Theme

SpeakyDooman just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

as help 2006-03-02 10:49:29


script for overhead car game so far i have just used a tutorial to get this code:

onClipEvent (load) {

downCapture = new Object();
downCapture.onKeyDown = function () {
switch (Key.getCode()) {
case Key.LEFT: left = true; break;
case Key.RIGHT: right = true; break;
case Key.UP: up = true; break;
case Key.DOWN: down = true; break;
}
}
Key.addListener(downCapture);
//listen for key returns
upCapture = new Object();
upCapture.onKeyUp = function () {
switch (Key.getCode()) {
case Key.LEFT: left = false; break;
case Key.RIGHT: right = false; break;
case Key.UP: up = false; break;
case Key.DOWN: down = false; break;
}
};
Key.addListener(upCapture);
rotateBy = 9;
accelleration = 5;
function radtodeg(deg) {
return (deg/180) * Math.PI;
}
}
onClipEvent (enterFrame) {
if (left) { _rotation -= rotateBy }
if (right) { _rotation += rotateBy }
if (up) {
if (accelleration < 10) {
accelleration++;
}
angle = _rotation;
angle = radtodeg(angle-90);
by_x = accelleration * Math.cos(angle)
by_y = accelleration * Math.sin(angle)
_x +=by_x
_y +=by_y
}
}

There may be a few errors as after 30mins of staring at a screen trying to figure this out i got bored and typed out how i think it went copying exactlly roughly the last 10lines.

My question is: how would i stop the car from rotating on the spot. I just cant figure it out!

Response to as help 2006-03-02 10:52:16


have a variable called "moving" and have it 0 if the car isnt moving and 1 if it is. then make an if statemant saying that if moving==0, dont rotate

Response to as help 2006-03-02 10:55:26


How about
onClipEvent (enterFrame) {
if (left && accelleration>0) { _rotation -= rotateBy }
if (right && accelleration>0) { _rotation += rotateBy }

Assuming that when accelleration is speed. I can't find speed.


SIG YOINK!

BBS Signature

Response to as help 2006-03-02 11:05:15


At 3/2/06 10:55 AM, James_Prankard_Inc wrote: How about
onClipEvent (enterFrame) {
if (left && accelleration>0) { _rotation -= rotateBy }
if (right && accelleration>0) { _rotation += rotateBy }

Assuming that when accelleration is speed. I can't find speed.

i tried this is still spins on the spot, and -fenix- can u explain what you mean and how i create a varible of whether it is moving or not?

Response to as help 2006-03-02 11:14:51


on the Car MC, at the top of the code add:

onClipEvent(load){
moving=0;
}

or if you already havea bunch of variables, just add it to the list,

then put this under the onClipEvent(enterFrame){ :

if(speed>=0){
moving=1;
}else{
moving=0;
}

replace speed with whatever variable you are using for speed

and then where your rotation code is, put this around it:

if(moving==1){
//rotation code
}

Response to as help 2006-03-02 11:21:13


okay so here is what i have as the code now following what fenix said:

onClipEvent (load) {

downCapture = new Object();
downCapture.onKeyDown = function () {
switch (Key.getCode()) {
case Key.LEFT: left = true; break;
case Key.RIGHT: right = true; break;
case Key.UP: up = true; break;
case Key.DOWN: down = true; break;
}
}
Key.addListener(downCapture);
//listen for key returns
upCapture = new Object();
upCapture.onKeyUp = function () {
switch (Key.getCode()) {
case Key.LEFT: left = false; break;
case Key.RIGHT: right = false; break;
case Key.UP: up = false; break;
case Key.DOWN: down = false; break;
}
};
Key.addListener(upCapture);
rotateBy = 9;
accelleration = 5;
function radtodeg(deg) {
return (deg/180) * Math.PI;
}
}
onClipEvent (enterFrame) {
if(speed>=0){
moving=1;
}else{
moving=0;
}
if(moving==1){
if (left) { _rotation -= rotateBy }
if (right) { _rotation += rotateBy }
}
if (up) {
if (accelleration < 10) {
accelleration++;
}
angle = _rotation;
angle = radtodeg(angle-90);
by_x = accelleration * Math.cos(angle)
by_y = accelleration * Math.sin(angle)
_x +=by_x
_y +=by_y
}
}

it still dont work with this code!

Response to as help 2006-03-02 12:26:40


can any1 help?

Response to as help 2006-03-02 12:39:34


change speed to acceleration

Response to as help 2006-03-02 18:51:07


pyro's should work

Response to as help 2006-08-03 00:20:11


Just was I was looking for, however I need the "arrow down" button to move my mc down. Any chance?