# Car game

**URL:** <https://forum.kirupa.com/t/car-game/236360>\
**Category:** Uncategorized\
**Created:** [August 20, 2007, 8:15am UTC](https://forum.kirupa.com/t/car-game/236360 "2007-08-20T08:15:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taxidriver](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Taxidriver](https://forum.kirupa.com/u/Taxidriver)\
**Post date:** [August 20, 2007, 8:15am UTC](https://forum.kirupa.com/t/car-game/236360/1 "2007-08-20T08:15:44Z")

</div>

Hello,  
I am trying to develop a car game; the kind you have a perspective view of the road and of the objects you encounter.  
I cannot manage to generate random objects in a satisfactory way.  
I do like this to generate the trees:

function create trees():Void {  
if (i\<20) {  
attachMovie(“tree”, “tree”+i, i);  
this[“tree”+i].dir = Math.floor(Math.random()\*2);  
i++;  
}  
}  
intervalId = setInterval(this, “createtree”, duration);

so that I have 20 trees and when a tree goes out from the stage I make him reenter in the correct position. I always use the same 20 trees.  
But now the major problems are the cars; if I write a similar code to the one above, at first it goes properly but soon I get an enormous numbers of car and it is difficult to manage them.  
Please help me; I ahve also tries to generate cars like this:

function createcars() {  
if (random(15) == 0) {  
attachMovie(“civic\_traffico”, “b”+k, k, {\_x:(random(110)+220), \_y:190});  
this[“b”+k].\_xscale = 10;  
this[“b”+k].\_yscale = 10;  
this[“b”+k].hit.\_xscale = this[“b”+k].hit.\_yscale=10;  
traffico[traffico.length] = k;  
k++;  
if (((this[“b”+k-1].\_x-this[“b”+k].\_x)\<60) and ((this[“b”+k-1].\_y-this[“b”+k].\_y)\<50)) {  
removeMovieClip(this[“b”+k]);  
}  
}  
}

but after a while my trees disappear and I can see only cars.
