This would mean that you can only move a panel every 50 frames, right?
Nope.
If you have one function which updates the car panel position than you can cycle through the whole array in one frame.
Depending on the numbers of panels this _might_ give a lag, but I used this method with 30 panels you don't notice anything.
@halfpint:
First of all I'm not entirely sure if the following code works, because its not tested at all. I rewrote the car module like I would write it if I would make a frogger like game. I chose all names of the vars so they are self-explanatory, but if there are any questions ask here or via PM.
The only function you would have to call on game start is:
init_Cars()
Here is the code (C-Script):
var cars_max = 50;
var car_panel[50];
var max_MoveSpeed = 10;
var car_MoveSpeed[50]; // individual move speed per car
var max_DelayTime = 20; // 20 seconds
var car_DelayTime[50];
var lanes_max = 10;
var lane_offset = 20;
var lane_size = 40;
panel* move_pan;
panel* setLane_pan;
var status_Cars = 0;
function set_RandomLane(_nr)
{
var new_lane;
new_lane = int(random(lanes_max));
setLane_pan = car_panel[_nr];
setLane_pan.pos_y = new_lane * lane_size + lane_offset;
}
function draw_CarPanels()
{
var i;
while(status_Cars)
{
i = 0;
while(i < cars_max)
{
temp_pan = car_panel[i];
if(total_secs >= car_DelayTime[i])
{
temp_pan.pos_x -= car_MoveSpeed * time_step;
if(temp_pan.pos_x < -bmap_width(temp_pan.bmap))
{
temp_pan.pos_x = screen_size.x + 10;
set_RandomLane(i);
}
}
i += 1;
}
wait(1);
}
}
function init_Cars()
{
var i;
i = 0;
while(i < cars_max)
{
car_panel[i] = pan_create("bmap = car; flags = visible, refresh,overlay;",3);
car_MoveSpeed[i] = int(random(max_MoveSpeed)) + 1;
car_DelayTime[i] = int(random(max_DelayTime)) + total_secs;
set_RandomLane(i);
i += 1;
}
status_Cars = 1;
draw_CarPanels();
}
Damn I just noticed that there need to be a delay, otherwise you'd have all cars run over the screen immediately.
I'll work on that and repost the code here.
edit:
Inserted the new code and added the delay time.
I also forgot to set a random lane at start, now its there.
All that's missing now is a destroy function which removes the panels etc. on restart.
Hint: The collision detection between car and player panel would go into the interal loop of draw_CarPanels