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
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (NnamueN, 1 invisible), 1,489 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
pos_x min and max #314358
03/07/10 23:41
03/07/10 23:41
Joined: Sep 2009
Posts: 155
France
ayks Offline OP
Member
ayks  Offline OP
Member

Joined: Sep 2009
Posts: 155
France
Hi,
I'm trying something in 2D.
I put a square (.jpg) on the screen.
I want to do an action when an object touch it.

so i'm looking for something like it in a first time:
Quote:

if (object.pos_x > square.pos_x_min && object.pos_x< square.pos_x_max)
{
the action
}


but i only know "pos_x" for now.. nothing with min and max.
I searched pos_x in the manual but nothing with it too.
So i'm looking for help :y

Last edited by ayks; 03/07/10 23:42.
Re: pos_x min and max [Re: ayks] #314362
03/08/10 00:04
03/08/10 00:04
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
max_x = object.size_x or bmap_width(object.bmap), same with max_y (height).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: pos_x min and max [Re: Superku] #314363
03/08/10 00:11
03/08/10 00:11
Joined: Sep 2009
Posts: 155
France
ayks Offline OP
Member
ayks  Offline OP
Member

Joined: Sep 2009
Posts: 155
France
huh, looks unknow for me but i will try something with it.
Thx for the fast answer :l

edit : i know size_x but dont understand "max_x = object.size_x" smirk
mb there is a way to do "if pic_A touch pic_B" as condition ?

Last edited by ayks; 03/08/10 00:55.
Re: pos_x min and max [Re: ayks] #314367
03/08/10 01:03
03/08/10 01:03
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
if(panel1.pos_x+panel1.size_x >= panel2.pos_x &&
panel1.pos_y+panel1.size_y >= panel2.pos_y &&
panel1.pos_x <= panel2.pos_x+panel2.size_x &&
panel1.pos_y <= panel2.pos_y+panel2.size_y) {
panel1 touches panel2
}

Should work, but untested. If you don't understand something, think a second about it (or 2), use the manual then feel free to ask.
Have you done the tutorial(s)?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: pos_x min and max [Re: Superku] #314369
03/08/10 01:18
03/08/10 01:18
Joined: Sep 2009
Posts: 155
France
ayks Offline OP
Member
ayks  Offline OP
Member

Joined: Sep 2009
Posts: 155
France
i was trying something like it, near exactly like it, but i think i do something bad for now cause it dont work, but i will try again -

and indeed, this is logical.. will think more next time - smirk
i searched in the manual but i always look for a magic method which don't exist -

i haven't done all the tutorial but i think i did enough of them + i already did mass line of code -
so, thanks for advice, and i go try to make it work and i will post it when it will work, prolly tomorrow.


Last edited by ayks; 03/08/10 01:19.
Re: pos_x min and max [Re: Superku] #314370
03/08/10 01:40
03/08/10 01:40
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
write a check function for it, then just pass the 2 panels to make it easier
Code:
int panel_istouching(PANEL* pnl1, PANEL* pnl2){
	
	//check left
	if((pnl1.pos_x + pnl1.size_x) < pnl2.pos_x){
		return(0);
	}
	
	//check right
	if((pnl1.pos_x > (pnl2.pos_x + pnl2.size_x)){
		return(0);
	}
	
	//check top
	if((pnl1.pos_y + pnl1.size_y) < pnl2.pos_y){
		return(0);
	}
	
	//check bottom
	if((pnl1.pos_y > (pnl2.pos_y + pnl2.size_y)){
		return(0);
	}
	
	return(1);
}

void panel_move(){
	
//...
	if panel_istouching(pnl_ship, pnl_rock){
		//do something
	}


hope this helps
*untested*

Re: pos_x min and max [Re: MrGuest] #314419
03/08/10 14:37
03/08/10 14:37
Joined: Sep 2009
Posts: 155
France
ayks Offline OP
Member
ayks  Offline OP
Member

Joined: Sep 2009
Posts: 155
France
Ok, ur code worked superku, i just forgot to add a "while not your if" {wait(1);} before..

and mr guest, thanks for ur "proper" (not sure that its the correct word here) code :l i will try to use it :v

Last edited by ayks; 03/08/10 14:37.

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