|
|
moving multiple panels with pan_create help
#253516
02/25/09 06:07
02/25/09 06:07
|
Joined: Jun 2008
Posts: 19
halfpint
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 19
|
I have made a simple frogger game nothing serious just something to practice 2d and such. I have completed the entire game in a couple of hours except for one minor detail, ok so its a big detail but still. When i create a car panel with pan_create then i run a different function to move the panel its fine, but when i create another panel and try to move that one the first one stops. I know it is doing this because I am overwriting the panel pointer so my question is how to do this? Here is what i have so far. function move_car(new_car,lane)
{
car_speed = random(.4) + min_speed;
move_car_pan = new_car;
while(move_car_pan.visible == ON)
{
if(lane <= 3){move_car_pan.pos_x -= car_speed;}
else{move_car_pan.pos_x += car_speed;}
if(move_car_pan.pos_x < 0){move_car_pan.visible = OFF;}
if(move_car_pan.pos_x > 800){move_car_pan.visible = OFF;}
wait(1);
}
}
function create_car(lane)
{
car_pos.y = lane*50 + 50;
if(lane <= 3){car_pos.x = 800;}
else{car_pos.x = 0;}
new_car = pan_create("bmap = car; flags = visible, refresh,overlay;",3);
new_car.pos_x = car_pos.x;
new_car.pos_y = car_pos.y;
move_car(new_car,lane);
wait(1);
}
The lane variable is just which lane the car is spawned in. Any help would be appreciated, thanks. I just changed a number.
Last edited by halfpint; 02/26/09 02:12.
|
|
|
Re: help with frogger / pan_create
[Re: George]
#253720
02/26/09 10:39
02/26/09 10:39
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
Not necessarily! You could also use a var array and a temp panel pointer:
var myPanels[50];
panel* temp_pan;
Now save the panels at a certain position and hand the id of that position over to the move function which will set the temp_pan pointer each frame to the panel at that position and move it then using the temp_pan pointer.
|
|
|
Re: help with frogger / pan_create
[Re: Xarthor]
#253815
02/27/09 02:48
02/27/09 02:48
|
Joined: Jun 2008
Posts: 19
halfpint
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 19
|
Now save the panels at a certain position and hand the id of that position over to the move function which will set the temp_pan pointer each frame to the panel at that position and move it then using the temp_pan pointer.
Im not entirely sure of what your saying here? Maybe its how you said it that is confusing me or I am just not good enough to understand what I am supposed to do. If you could write it out that would be great.
|
|
|
Re: help with frogger / pan_create
[Re: George]
#253858
02/27/09 12:26
02/27/09 12:26
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
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
Last edited by Xarthor; 02/27/09 12:31.
|
|
|
Re: help with frogger / pan_create
[Re: Xarthor]
#253972
02/28/09 01:16
02/28/09 01:16
|
Joined: Jun 2008
Posts: 19
halfpint
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 19
|
Thank you very much xarathor, this problem has caused be to not complete 2 of my game ideas and now i should be able to do them rather easily. There are however two itty bitty problems that i can not figure out.
1. There is a fat delay of probably around 10 seconds at least of which the cars sit there on the left side, I dont see a delay or anything to maybe its lag from all the panels being made. I will see if i can get that.
2. The cars all bunch up then there are no cars for a while, then all the cars spawn then a gap again... etc. Maybe there is a way to check the distance between the cars but since its created on separate lanes i would have to check all the cars and I am pretty sure there is an easier way.
Thanks for the help, I really appreciate it.
edit: Forgot to mention that collision works perfectly.
Last edited by halfpint; 02/28/09 02:01.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|