Be a Supporter!

AS: Overhead car

  • 3,884 Views
  • 21 Replies
New Topic Respond to this Topic
UnknownFury
UnknownFury
  • Member since: Aug. 10, 2005
  • Offline.
Forum Stats
Member
Level 26
Programmer
AS: Overhead car 2006-03-04 02:54:42 Reply

AS: Main

This is my first as tutorial so bare with me in places it may be a little bit messy and unclear. I hope you can use this tutorial for a game or similar. So here goes:

You will need to know

AS: _x and _y by True Darkness
AS: ClipEvents by inglor
AS: Movement - Basic
AS: triginometry by BleeBlap

First of all you need to create your car movieclip. Now open the actions panel and give the car movieclip this code:

nClipEvent (load) {
//listen for key presses
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; //how much we should rotate every frame (L/R key is pressed)
accelleration = 5; //how much we should move every frame (when Up key is pressed)
function radtodeg(deg) { //convert radians to degrees (for later)
return (deg/180) * Math.PI;
}
}
onClipEvent (enterFrame) {
if (left) { _rotation -= rotateBy } //rotate counter-clockwise
if (right) { _rotation += rotateBy } //rotate clockwise
if (up) {
if (accelleration < 10) { //if is below accelleration limit then allow to accellerate
accelleration++;
}
//calculate where the car will move to:
angle = _rotation;
angle = radtodeg(angle-90);
by_x = accelleration * Math.cos(angle)
by_y = accelleration * Math.sin(angle)
_x +=by_x //move the car here
_y +=by_y // and here
}
}

This is the code better explained that can easily help you to improve as you can use small extracts from this tutorial:

onClipEvent (load) {

The script inside this is executed ONLY when the movieclip first appears in the movie(not before)

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);

This "listens"(finds out) when the player presses down the arrow keys (left, right, up and down) and stores the result. For example when the down key is pressed the variable for down is set to true

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);

This "listens"(knows) when any one of the arrow keys (left, right, up and down) are released as some say. For example when the down key is released by the player the down variable is set to false again.

rotateBy = 9;
accelleration = 5;
function radtodeg(deg) {
return (deg/180) * Math.PI;
}

RotateBy is the number of "pixels" the movieclip will rotate when the left or right buttons are pressed.
accelleration is simply the accelleration of the movieclip when the up button is pressed

Function radtodeg(deg) { is used for converting radians to degrees, we need this in order to make the trig functions to work the way we want to later in the script.

onClipEvent (enterFrame) {

this executes the script inside every time the frame is loaded (by default 12 times per second)
if (left) { _rotation -= rotateBy }
if (right) { _rotation += rotateBy }

every time the left button is pressed the movieclip will rotate by rot number of degrees (counter-clockwise)

same for the right button, but the other direction (clockwise)

if (up) {

Executes the script inside whenever the up button is pressed

if (accelleration < 10) {
accelleration++;
}

If accelleration is less than 10 then the acceleration will increase by 1. This prevents the movielip from exceeding a certain speed. change the number 10 to a higher number to allow it to go faster.

angle = _rotation;
angle = radtodeg(angle-90);
by_x = accelleration * Math.cos(angle)
by_y = accelleration * Math.sin(angle)
_x +=by_x
_y +=by_y

This part is simple triginometry, it determines the amount the movieclip should move horizontally (x-axis) and vertically (y-axis) and then moves it according to the result it got.

Vengeance
Vengeance
  • Member since: Mar. 18, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: Overhead car 2006-03-04 03:07:56 Reply

seem's good, maybe an exaple.


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature
DannyIsOnFire
DannyIsOnFire
  • Member since: Apr. 14, 2005
  • Offline.
Forum Stats
Member
Level 21
Movie Buff
Response to AS: Overhead car 2006-03-04 09:43:44 Reply

At 3/4/06 03:07 AM, -Vengeance- wrote: seem's good, maybe an exaple.

Yeha it dosent look to bad at all.
Throw an example together =)


|| Portfolio || Facebook || Twitter ||

BBS Signature
UnknownFury
UnknownFury
  • Member since: Aug. 10, 2005
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to AS: Overhead car 2006-03-04 10:05:45 Reply

examples:

http://denvish.net/ulf/1141478333_car example.fla - source file
http://denvish.net/ulf/1141478288_car example.php - view sample

greenbush
greenbush
  • Member since: Oct. 24, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Overhead car 2006-03-04 11:54:35 Reply

Yeah, noticed the 'o' issue. Your gonna get free bumps :D

Nemo
Nemo
  • Member since: Jun. 13, 2003
  • Offline.
Forum Stats
Member
Level 34
Game Developer
Response to AS: Overhead car 2006-03-04 11:57:46 Reply

At 3/4/06 11:54 AM, greenbush wrote: Yeah, noticed the 'o' issue. Your gonna get free bumps :D

It's OK, but you know that a pedal in a car controls acceleration, not speed, and there is no sense of that in your coding.


BBS Signature
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Overhead car 2006-03-04 12:07:30 Reply

horrible tutorial


- Matt, Rustyarcade.com

Pyromaniac
Pyromaniac
  • Member since: Jan. 14, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Overhead car 2006-03-04 12:24:49 Reply

You forgot to metion that you didnt even make the code, and that you got it from a tutorial. Also, I had to help you and fix the codes to make it do what you wanted. You didnt make any part of this code whatsoever.

UnknownFury
UnknownFury
  • Member since: Aug. 10, 2005
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to AS: Overhead car 2006-03-04 12:41:32 Reply

i made this code but it was you who helped me with the next bit that i couldn't do

greenbush
greenbush
  • Member since: Oct. 24, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Overhead car 2006-03-04 12:43:36 Reply

Well if you didnt make the code and you submit it as an AS: "" thread. then shame on you. If your gonna use code ideas from other tutorials then link them. Ive seen a couple of tutorials written this way

NinoGrounds
NinoGrounds
  • Member since: Nov. 28, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS: Overhead car 2006-03-04 12:50:55 Reply

Fix the link, please

Pyromaniac
Pyromaniac
  • Member since: Jan. 14, 2005
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS: Overhead car 2006-03-04 13:22:51 Reply

Liar! You are the biggest liar Ih ave even seen. Do not stel wqork and claim it as you own.
Proof that he is a liar http://www.newground../topic.php?id=442775

UnknownFury
UnknownFury
  • Member since: Aug. 10, 2005
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to AS: Overhead car 2006-03-04 14:23:42 Reply

At whateva, -ryu- wrote: script for overhead car game so far i have just used a tutorial to get this code:

By this i meant i have just used a bunch of tutorials to get this! It really annoys me but i guess you might as well lock this as everyone thinks it is stolen.

shazwoogle
shazwoogle
  • Member since: Sep. 27, 2004
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Overhead car 2006-03-06 04:50:53 Reply

crapola...
bad tut bad idea most probebly stolen

TommyGun
TommyGun
  • Member since: Oct. 14, 2005
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to AS: Overhead car 2006-03-06 06:00:46 Reply

tch...tch...tch...trying to educate us on a subject matter your are uneducated in...the irony is ironic in a parradox kinda way


"It isn't that democrats are ignorant. Far from it. it's just that they know so much that just isn't so"
Ronald Reagan
Proud supporter of the Dinosaur Conspiracy Theory

BBS Signature
cLoSeD
cLoSeD
  • Member since: May. 16, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Overhead car 2006-04-16 09:20:43 Reply

looks a lot like http://www.pixel2lif.._the_keyboard/page1/

thief!

johnfn
johnfn
  • Member since: Aug. 16, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS: Overhead car 2006-04-16 09:53:08 Reply

At 4/16/06 09:20 AM, cLoSeD wrote: looks a lot like http://www.pixel2lif.._the_keyboard/page1/


thief!

Yup, stolen right down to the comments. GJ, creator of this thread.


[6,11,4,10,2,10,-68,5,15,-68,16,4 ,1,-68,-2,1,15,16,-67].map(function(v){ return String.fromCharCode(v + 100) }).join(""); // updated for web 2.0!

BBS Signature
Paranoia
Paranoia
  • Member since: Apr. 22, 2005
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to AS: Overhead car 2006-04-16 12:39:08 Reply

At 4/16/06 09:53 AM, johnfn wrote: Yup, stolen right down to the comments. GJ, creator of this thread.

That's just sad.


BBS Signature
cLoSeD
cLoSeD
  • Member since: May. 16, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Overhead car 2006-04-16 14:22:39 Reply

btw.. you forgot to copy the o from onClipEvent...

Vengeance-1
Vengeance-1
  • Member since: Jun. 27, 2004
  • Offline.
Forum Stats
Member
Level 11
Blank Slate
Response to AS: Overhead car 2006-08-05 04:10:46 Reply

this is a good tutorial, for a tank control. cars don't steer anything like this. there is a much better tutorial on flash kit to make reailistic car movment, in like 30 lines opposed to like 45.

summary:
too complex
unrealistic eg. no sence of proper acceleration or turning
if the statments are correct its stolen to

Dog
Dog
  • Member since: Feb. 8, 2005
  • Offline.
Forum Stats
Member
Level 10
Blank Slate
Response to AS: Overhead car 2006-08-05 04:25:09 Reply

At 4/16/06 09:20 AM, cLoSeD wrote: looks a lot like http://www.pixel2lif.._the_keyboard/page1/


thief!

lol, pwn'd.

You are a dead-set tard.