Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, ozgur), 1,421 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
moving multiple panels with pan_create help #253516
02/25/09 06:07
02/25/09 06:07
Joined: Jun 2008
Posts: 19
H
halfpint Offline OP
Newbie
halfpint  Offline OP
Newbie
H

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.

Code:
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: halfpint] #253684
02/26/09 00:31
02/26/09 00:31
Joined: Jun 2008
Posts: 19
H
halfpint Offline OP
Newbie
halfpint  Offline OP
Newbie
H

Joined: Jun 2008
Posts: 19
hmmm, maybe i didn't make this entirely clear in my first post. I need some code or a suggestion to the easiest way of making the cars appear and move across the string, if possible a way to make it so more or less cars will spawn at any point for increased difficulty. Thats basically it.

Re: help with frogger / pan_create [Re: halfpint] #253696
02/26/09 05:34
02/26/09 05:34
Joined: Aug 2003
Posts: 2,011
Bucharest, Romania
George Offline

Expert
George  Offline

Expert

Joined: Aug 2003
Posts: 2,011
Bucharest, Romania
You need to create an array of panel pointers. Check out Aum82's workshop (invaders) to see an example.

Re: help with frogger / pan_create [Re: George] #253699
02/26/09 06:00
02/26/09 06:00
Joined: Jun 2008
Posts: 19
H
halfpint Offline OP
Newbie
halfpint  Offline OP
Newbie
H

Joined: Jun 2008
Posts: 19
i have looked at the code and using c-script I can't create an array of pointers it gives me an error.

panel* move_car_pan[50];

error: panel unknown 50

Is the code different for c-script? Or am i doing something else wrong?

Re: help with frogger / pan_create [Re: halfpint] #253718
02/26/09 10:25
02/26/09 10:25
Joined: Aug 2003
Posts: 2,011
Bucharest, Romania
George Offline

Expert
George  Offline

Expert

Joined: Aug 2003
Posts: 2,011
Bucharest, Romania
I'm afraid that you need to use lite-C. The good news is that even lite-C free can do the job.

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 Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Not necessarily!
You could also use a var array and a temp panel pointer:
Code:
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] #253778
02/26/09 19:44
02/26/09 19:44
Joined: Aug 2003
Posts: 2,011
Bucharest, Romania
George Offline

Expert
George  Offline

Expert

Joined: Aug 2003
Posts: 2,011
Bucharest, Romania
This would mean that you can only move a panel every 50 frames, right?

Re: help with frogger / pan_create [Re: Xarthor] #253815
02/27/09 02:48
02/27/09 02:48
Joined: Jun 2008
Posts: 19
H
halfpint Offline OP
Newbie
halfpint  Offline OP
Newbie
H

Joined: Jun 2008
Posts: 19
Originally Posted By: Xarthor

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 Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Originally Posted By: George
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):
Code:

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
H
halfpint Offline OP
Newbie
halfpint  Offline OP
Newbie
H

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.
Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1