A Shorter Version of my Question

BlitzPlus Forums/BlitzPlus Beginners Area/A Shorter Version of my Question

En929(Posted 2009) [#1]
Here's a shorter version of my question so that there isn't as much to sift through (I hope). I was trying to make it so that when the player gets to the ORBE character, it pushes the ORBE in whichever direction the player is going. But, I ran into some problems.

1) When the player goes up, the ORBE goes up when the player has NOT collided with the ORBE.

2) The ORBE is not colliding at all, even when I have the "ImageCollide" commands in it

3) My problems actually started at the command that goes as follows:


If (o <> Null) Then


DrawImage (ORBE,(b\x + o\x),o\y)

EndIf

Maybe I did something wrong here or I didn't put it in right. I hope that I could get help with this. Below, inside the code, I commented where I think the problems are located so that they could be more easily found. Thanks!






Graphics 900, 900
SetBuffer BackBuffer()

;Loading images
 
EATUM = LoadImage ("Eatum.png") 
ORBE = LoadImage("Orbe.png")
BACKGROUND =  LoadImage("Clouds.jpg")


;Setting up the image types

Type EATUM

Field x,y


End Type 	

Type ORBE

	Field x,y

End Type 

Type BACKGROUND
	
	Field x,y
	Field image
	
	
End Type 



;giving the images a shorter name and telling their locations

e.EATUM= New EATUM

e\x = 70
e\y = 200


o.ORBE = New ORBE
o\x = 100
o\y = -200

b.BACKGROUND = New BACKGROUND

b\x = -500
b\y = 20
b\image = BACKGROUND 




While Not KeyDown (1)  


Cls

		
		

TileImage (b\image,b\x,b\y)





;this moves the player to the left and if the player runs into the 
;ORBE, the ORBE is supposed to be pushed to the left

If KeyDown(203)
b\x = b\x + 4

 
	If (o <> Null) Then
	
	
			If ImagesCollide(EATUM, e\x, e\y,0,ORBE, o\x, o\y,0) Then 
			
			o\x = o\x - 3

			EndIf 
	EndIf
	
EndIf
	


;this moves the player to the right and if the player runs into the 
;ORBE, the ORBE is supposed to be pushed to the rght

If KeyDown(205)
 

b\x = b\x - 4

 

	If (o <> Null) Then
	

		If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0) Then 
				
			 o\x = o\x + 3
	
	
	
		EndIf 

	EndIf

EndIf 


;Here's one of the problems that I've had. I was trying to make it 
;so that when the player collides with the ORBE, the ORBE goes 
;up when  the player collides with it. But, the problem is that 
;when the player goes up and gets to a certain proximity to the 
;ORBE, the ORBE goes up at a time when the player HAS NOT 
;collided with it. So thus, I was wondering what am I doing wrong 
;here. Gosh, computers do some strange things...


If KeyDown(200)
 e\y = e\y - 3


	If (o <> Null) Then

		If ImagesCollide(EATUM,e\x,e\y,0,ORBE, o\x,o\y,0) Then 
		
			 o\y = o\y - 3
 

		EndIf 

	EndIf
	
EndIf 	
			

;this moves the player down and if the player runs into the ORBE 
;while going down, the ORBE is supposedly to be pushed down.


If KeyDown(208) 
e\y = e\y + 3

	If (o <> Null) Then


		If ImagesCollide(EATUM,e\x,e\y,0,ORBE, o\x,o\y,0) Then
		
			  o\y = o\y + 3


		EndIf 


	EndIf 
	
EndIf 



;here's where another problem lies. Here, I was trying to make it 
;so that the player has to actually get to the ORBE in order
;to push it. But, it won't collide at all even though I put in 
;the "ImagesCollide" command. And once again, when the player 
;pushes the up button, when it gets to a certain PROXIMITY to 
;the ORBE, the ORBE may moves up when the player HASN'T 
;collided with it. Thus, how do I fix this. Thanks


If (o <> Null) Then

	
			DrawImage (ORBE,(b\x + o\x),o\y) 

EndIf 




DrawImage (EATUM,e\x,e\y)
	
	
	Flip

Wend 				




okee(Posted 2009) [#2]
Actually this line is probably the culprit
DrawImage (ORBE,(b\x + o\x),o\y)

Your drawing the ORBE image at the coordinates (b\x + o\x), o\y
but you do a collision detection with o\x,o\y


Yeshu777(Posted 2009) [#3]
The DrawImage is correct, as the ORBE scrolls with the background offset.

But you are indeed correct, this offset also needs to be added to the collision detection.


En929(Posted 2009) [#4]
I was able to get the ORBE character to stop going up without the character first colliding with it by using:


;this makes the player (EATUM) go up and when the ORBE collides with
;the player, the player pushed the ORBE up with it.

If KeyDown(200)
 e\y = e\y - 3


	If (o <> Null) Then

		If ImagesCollide(EATUM,e\x,e\y,0,ORBE,(b\x + o\x),o\y,0) Then 
		
			 o\y = o\y - 3
 

		EndIf 

	EndIf
	
EndIf 	
			

;this moves the player  down and if the player runs into the ORBE, the 
;ORBE will be pushed down with it.


If KeyDown(208) 
e\y = e\y + 3

	If (o <> Null) Then


		If ImagesCollide(EATUM,e\x,e\y,0,ORBE,(b\x + o\x),o\y,0) Then
		
			  o\y = o\y + 3


		EndIf 


	EndIf 
	
EndIf 





Thus, that part works. However, for some reason, it's not working for when I try to get it to work when the player is going from left to right. That is, when the player is going to the right and collides with the ORBE, the ORBE doesn't move to the right with the player. I have the same problem when the player is going to the left and collides with the ORBE. Below is what I tried to do for going from right to left. Using Imagescollide I tried to put in b\x + o\x, but it didn't work correctly, thus, I didn't include it.


  

 


;this moves the player to the left and if the player runs into the ORBE, 
;the ORBE is supposed to be pushed to the left with the player, but it 
;doesn't.

If KeyDown(203)


b\x = b\x + 4

 
	If (o <> Null) Then
	
	
			If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0) Then 
			
			o\x = o\x - 3

			EndIf 
	EndIf
	
EndIf
	


;this moves the player to the right and if the player runs into the 
;ORBE, the ORBE is supposed to be pushed to the right with the 
;player.

If KeyDown(205)
 

b\x = b\x - 4

 

	If (o <> Null) Then
	

		If ImagesCollide(EATUM, e\x,e\y,0,ORBE, o\x,o\y,0) Then 
				
			 o\x = o\x + 3
	
	
	
		EndIf 

	EndIf

EndIf 




...By the way, which command do I use to make an array of 5 apples disappear when the player goes into a door (a new scene)? I tried Delete a (for deleting the APPLES), for when the player collides with the door, but I saw that it wasn't the right command for deleting all of them.


Yeshu777(Posted 2009) [#5]
Not tested but it should go something like this..


;// Example Apple Type

Type apple	

	Field x,y
	Field image

End Type 

red_apple_image = LoadImage("redapple.bmp")

;// To Create 5 Apples

For nof_fruits = 1 To 5

     fruit.apple = New apple
     fruit\x = Rnd(0,900)
     fruit\y = Rnd(0,900)
     fruit\image = red_apple_image

Next

;// To Draw

For fruit.apple = Each apple

    DrawImage(fruit\image, fruit\x, fruit\y);

Next

;// To Delete

For fruit.apple = Each apple

    Delete fruit

Next




okee(Posted 2009) [#6]
En929

You probably can get away with it but i don't think it's a good idea to
name your image variables the same as your types.
You should try doing something like:

Type TOrbe
 Field x,y
 Field image
End Type

Global Orbe.TOrbe = New TOrbe
Orbe\x = 100
Orbe\y = 200
Orbe\image = LoadImage("Orbe.png")


Also makes it a bit more readable.

With the push problem
The left and right has b\x = b\x + 4 for moving the background
which seem to be the only difference between them and the up and
down controls
Maybe try just having an 800,600
display without the scrolling background and work on
getting the object moving within that and then work on the
scrolling


En929(Posted 2009) [#7]
Okee, thanks for helping me. I tried what you said at first; that is, the player was able to move the ORBE character in each direction before I included the scrolling background, and it worked well. It's just that ever since I put in the lines of:


If (o <> Null) Then

	
	DrawImage (ORBE,(b\x + o\x),o\y) 

EndIf 
  


It stopped working correctly. I tried doing a collision detection with o\x,o\y using:


If KeyDown(203)


b\x = b\x + 4

 
	If (o <> Null) Then
	
	
			If ImagesCollide(EATUM,e\x,e\y,0,ORBE,(b\x + o\x),o\y,0) Then 
			
			o\x = o\x - 3

			EndIf 
	EndIf
	
EndIf
	


;this moves the player to the right and if the player runs into the 
;ORBE, the ORBE is supposed to be pushed to the right with the 
;player.

If KeyDown(205)
 

b\x = b\x - 4

 

	If (o <> Null) Then
	

		If ImagesCollide(EATUM, e\x,e\y,0,ORBE, (b\x + o\x),o\y,0) Then 
				
			 o\x = o\x + 3
	
	
	
		EndIf 

	EndIf

EndIf 



But such didn't work right (I'm sure it's wrong). Thus, what do I do to fix this part?

BTW, thanks again Yeshu. The lines for the apples worked out.


_Skully(Posted 2009) [#8]
You could go proximity. If the player is within a distance, the object is added to a list of items influenced (if not already)...

when the player then moves, he moves the object as well... or, you could even child the Orbe to the player...

As for why the collisions aren't working as expected... I don't have the time right now to sift through it... maybe later


En929(Posted 2009) [#9]
I'm going to start including screenshots of my game to describe things that I'm trying to do. A screen shot of my game and what I'm trying to do is in the URL below.

http://authorhenryemphrey.tripod.com/gallery/