Gamestudio Links
Zorro Links
Newest Posts
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
1 registered members (M_D), 1,430 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Collision problem #329762
06/22/10 17:21
06/22/10 17:21
Joined: Jun 2007
Posts: 15
Norway
G
Gastara Offline OP
Newbie
Gastara  Offline OP
Newbie
G

Joined: Jun 2007
Posts: 15
Norway
I’m playing with code from the AUM 84 where collision is done by checking the color of the pixels near the player. I'm doing some test with some simple graphic. When this line is divided by 2:
Code:
coords1_x = my_player.pos_x + bmap_width(player_tga) / 2;

the half of the player is moving through the corner when half of the players width are outside of the red color’s top. I want all the width of the player sprite to be blocked so I remove the /2 from the line above. That works fine, but just on one corner of the red color's top. At the opposite side, it’s not blocking when some part of the players width are outside the red color’s top (see picture below). How is it possible to avoid this, so that the player is not moving on the inside or through the corners of the red color? It works fine on one side, but not on both.

Here it's the collision fine (the small quadrangle is player)



Here it's moving through and on the inside of the corner



Here is the code:

Code:
function collisions_startup()
{
	wait (3); // wait until the video functions are available
	var coords1_x, coords1_y, coords2_x, coords2_y, coords3_x, coords3_y, coords4_x, coords4_y;
	var format, pixel1, pixel2, pixel3, pixel4;
	COLOR pixel1_color, pixel2_color, pixel3_color, pixel4_color;
 
	while (1)
	{
		
		// check player's feet
      coords1_x = my_player.pos_x + bmap_width(player_tga); // 
		coords1_y = my_player.pos_y + bmap_height(player_tga); // play with 2 or - 20
		format = bmap_lock (level_tga, 0);
		pixel1 = pixel_for_bmap(level_tga, coords1_x, coords1_y);
		pixel_to_vec (pixel1_color, NULL, format, pixel1); // store the color of the pixel1 in pixel1_color 
		if (pixel1_color.red == 255) // detected a red pixel below player's feet?
		{
			my_player.pos_y -= 2;
			}
	
		bmap_unlock (level_tga);
		wait (1);
	}
	
}





Last edited by Gastara; 06/22/10 17:52.
Re: Collision problem [Re: Gastara] #329809
06/22/10 22:45
06/22/10 22:45
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!

I believe that the /2 is done to get the radius of the object.


Hope this helps!
Ottawa laugh

Ver 7.86.2 Pro and Lite-C
Re: Collision problem [Re: Ottawa] #329833
06/23/10 07:14
06/23/10 07:14
Joined: Jun 2007
Posts: 15
Norway
G
Gastara Offline OP
Newbie
Gastara  Offline OP
Newbie
G

Joined: Jun 2007
Posts: 15
Norway
I was also thinking about that, but in this example it divides the width of the player by 2. So when more than half of the player is outside the corner, it passes through and is no longer blocked (see picture below). As I understand it, this is because the half of the player’s width is not blocked since it’s divided by to. When I remove / 2, it blocks all the width on one corner fine, but on the other corner it stop blocking when just one pixel are outside the red color.



Re: Collision problem [Re: Gastara] #329836
06/23/10 08:02
06/23/10 08:02
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
it actually divides the whole thing in 2 with your code...
use brackets to add half the bitmap size. and make sure the center_x/y are set to the middle if it's a panel.

and then use this:
Code:
coords1_x = my_player.pos_x + (bmap_width(player_tga) / 2);



that should work.

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Collision problem [Re: Helghast] #329837
06/23/10 08:26
06/23/10 08:26
Joined: Aug 2008
Posts: 482
B
bart_the_13th Offline
Senior Member
bart_the_13th  Offline
Senior Member
B

Joined: Aug 2008
Posts: 482
You need to check the pixel twice. First at:
Code:
y = my_player.pos_y + bmap_height(player_tga);



Then at:
Code:
y = my_player.pos_y;



Re: Collision problem [Re: bart_the_13th] #329930
06/23/10 23:20
06/23/10 23:20
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!



Have you looked at collision in the manual
You could solve your problem with c_setminmax


Hope this helps!
Ottawa laugh

Ver 7.86.2 Pro and Lite-C
Re: Collision problem [Re: Ottawa] #329952
06/24/10 09:08
06/24/10 09:08
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline
Expert
Rei_Ayanami  Offline
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
@Ottawa : huh? this is all 2D tongue so c_setminmax makes no sense wink

Re: Collision problem [Re: Rei_Ayanami] #329982
06/24/10 14:08
06/24/10 14:08
Joined: Jun 2007
Posts: 15
Norway
G
Gastara Offline OP
Newbie
Gastara  Offline OP
Newbie
G

Joined: Jun 2007
Posts: 15
Norway
Thanks for all response. Done a lot of testing with if statements where I added and subtracted the width of the sprite (40 in this case), but no result. It works fine on one side but not on the other… So I end up with this solution. Not the best or must genius solution I think, but it works. The screen size is 1400, so I give coords1_x a value of 700. I use that value when doing the check and now it works fine.

Anyway, I’m shore it’s a better way to do it.

Code:
function collisions_startup()
{
	wait (3); 
	
	var coords1_x, coords1_y;
	var format, pixel1;
	COLOR pixel1_color;
 
	while (1)
	{
		
		// This check the bottom of the player sprite
		
                coords1_x = 700;
		
		if (coords1_x <= (my_player.pos_x + bmap_width(player_tga))) 
		{
		coords1_x = my_player.pos_x + bmap_width(player_tga) - 40;
	   }
		if (coords1_x >= (my_player.pos_x + bmap_width(player_tga))) 
		{
		coords1_x = my_player.pos_x + bmap_width(player_tga);	
		}	
	 
		coords1_y = my_player.pos_y + 40;
		format = bmap_lock (level_tga, 0);
		pixel1 = pixel_for_bmap(level_tga, coords1_x, coords1_y);
		pixel_to_vec (pixel1_color, NULL, format, pixel1); 
		if (pixel1_color.red == 255) 
		{
			my_player.pos_y -= 2;
			}
	
		bmap_unlock (level_tga);
		wait (1);
	}

}



Last edited by Gastara; 06/24/10 14:09.
Re: Collision problem [Re: Rei_Ayanami] #329983
06/24/10 14:10
06/24/10 14:10
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!

@Rei_Ayanami : Yes, your right!

@Gastara : Looked at aum84 and now the question is this

Did you finish the exercise and was everything working fine at the end?

Ottawa wink

edit : Why are you using only a part of the code provided in 2dcollision4.c
Are your bitmaps dimensions a power of 2?

Last edited by Ottawa; 06/24/10 14:54.
Re: Collision problem [Re: Ottawa] #330007
06/24/10 17:53
06/24/10 17:53
Joined: Jun 2007
Posts: 15
Norway
G
Gastara Offline OP
Newbie
Gastara  Offline OP
Newbie
G

Joined: Jun 2007
Posts: 15
Norway
Hi

@Ottawa: I just posted the function for the bottom of the player since I started to solve that problem first. When that was done, I use the same principle for the head of the player with some modifications.

@Ottawa: Yes, my bitmaps dimension is a power of two.

The function works fine now for player’s bottom and head. Still some glitch at the corner when players left side meet the red color. Need to solve that problem now smile

Here's my progress

Code:
function collisions_startup()
{
	wait (3); 
	
	var coords1_x, coords1_y, coords2_x, coords2_y, coords3_x, coords3_y, coords4_x, coords4_y;
	var format, pixel1, pixel2, pixel3, pixel4;
	COLOR pixel1_color, pixel2_color, pixel3_color, pixel4_color;
 
	while (1)
	{
		
		// check player's bottom
		// Problem solved
		coords1_x = 700;
		
		if (coords1_x <= (my_player.pos_x + bmap_width(player_tga))) 
		{
		coords1_x = my_player.pos_x + bmap_width(player_tga) - 40;
	   }
		if (coords1_x >= (my_player.pos_x + bmap_width(player_tga))) 
		{
		coords1_x = my_player.pos_x + bmap_width(player_tga);	
		}	
	 
		coords1_y = my_player.pos_y + 40;
		format = bmap_lock (level_tga, 0);
		pixel1 = pixel_for_bmap(level_tga, coords1_x, coords1_y);
		pixel_to_vec (pixel1_color, NULL, format, pixel1); 
		if (pixel1_color.red == 255) 
		{
			my_player.pos_y -= 2;
			}
			
			
	// check player's top
	// Problem solved
      coords2_x = 700;
		
		if (coords2_x <= (my_player.pos_x + bmap_width(player_tga))) 
		{
		coords2_x = my_player.pos_x + bmap_width(player_tga) - 40;
	   }
		if (coords2_x >= (my_player.pos_x + bmap_width(player_tga))) 
		{
		coords2_x = my_player.pos_x + bmap_width(player_tga);	
		}	
	
	   coords2_y = my_player.pos_y; 
		pixel2 = pixel_for_bmap(level_tga, coords2_x, coords2_y);
		pixel_to_vec (pixel2_color, NULL, format, pixel2); 
		if (pixel2_color.red == 255) 
		{
			my_player.pos_y += 2;
		}
		
		// Check players left side
		// Not solved, blocking fine, but still a glitch at the corners.
		// Player follow the edge around the corner when moving
		
		coords3_y = 450;
		
	   if (coords3_y <= (my_player.pos_y + bmap_width(player_tga))) 
		{
		coords3_y = my_player.pos_y + bmap_width(player_tga) - 40;
	   }
	   if (coords3_y >= (my_player.pos_y + bmap_width(player_tga))) 
		{
		coords3_y = my_player.pos_y + bmap_width(player_tga);
	   }
		
		coords3_x = my_player.pos_x + 2; // play with 2
		pixel3 = pixel_for_bmap(level_tga, coords3_x, coords3_y);
	   pixel_to_vec (pixel3_color, NULL, format, pixel3); 
		if (pixel3_color.red == 255) 
		{
			my_player.pos_x += 2;
		}
		
		// Check players left side
		// Not done yet
		
		
	
	
		bmap_unlock (level_tga);
		wait (1);
	}

}



Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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