Another question
BlitzPlus Forums/BlitzPlus Programming/Another question
| ||
My game is coming along very well so far (I'm an extreme beginner). I'd like to thank Sauer for helping me take out the error message that I was getting in my game and thanks for helping me discover this forum code. Now, I'm trying to make it so that when the player pushes one ORBE into the door, it would be the last and only ORBE. My game source code is below. I wrote in the parts that I'm trying to fix via this marker: ";" ---------------------------------------------- Graphics 900, 900 SetBuffer BackBuffer() EATUM = LoadImage ("Eatum.png") APPLE = LoadImage("Apple.png") ORBE = LoadImage("Orbe.png") DOOR = LoadImage("Door.png") BACKGROUND = LoadImage("Clouds.jpg") Type EATUM Field x,y End Type Type APPLE Field x,y End Type Type ORBE Field x,y End Type Type DOOR Field x,y End Type e.EATUM = New EATUM e\x = 70 e\y = 200 For z = 1 To 5 a.Apple = New Apple a\x = 100+30*z a\y = 90*z Next ;this is the ORBE that I was talking about. I only wanted 1 of these o.ORBE = New ORBE o\x = 100 o\y = -200 d.DOOR = New DOOR d\x = 50 d\y = 50 Score = 0 ScrollRightLeft = -200 While Not KeyDown (1) Cls TileImage BACKGROUND,ScrollRightLeft DrawImage (EATUM,e\x,e\y) For a.APPLE = Each APPLE DrawImage(APPLE,a\x,a\y) If ImagesCollide(EATUM,e\x,e\y,0,APPLE,a\x,a\y,0) Then Delete a score = score + 1 Next Text 150,150, "Score" + Score If KeyDown(203) e\x = e\x - 3 ScrollRightLeft = ScrollRightLeft + 3 If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0) Then o\x = o\x - 3 EndIf If KeyDown(205) e\x = e\x + 3 ScrollRightLeft = ScrollRightLeft - 3 If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0) Then o\x = o\x + 3 EndIf If KeyDown(200) e\y = e\y - 3 If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0) Then o\y = o\y - 3 EndIf If KeyDown(208) e\y = e\y + 3 If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0) Then o\y = o\y + 3 EndIf DrawImage (DOOR,d\x,d\y) ;in essence, I'm trying to have one and only one ORBE to push into the door and delete. But now, everytime I push the ORBE into the door, another ORBE appears. Thus, how do I modify this part to stop the second ORBE from appearing? It appears that it might be something simple, but I don't know what it is. Thanks. DrawImage (ORBE,o\x,o\y) If ImagesCollide(DOOR,d\x,d\y,0,ORBE,o\x,o\y,0) Text 350,300, "Great Job" Delete o o.ORBE = New ORBE score = score + 1 Flip Wend |
| ||
In the line.. If ImagesCollide(DOOR,d\x,d\y,0,ORBE,o\x,o\y,0) Text 350,300, "Great Job" Delete o o.ORBE = New ORBE score = score + 1 o.ORBE = New ORBE is where you are creating a new orb. |
| ||
Additionally, looking through your previous posts on the forum Check that 'o' is actually assigned before trying to use it.. If(o <> Null) Then DrawImage (ORBE, o\x, o\y); If ImagesCollide(DOOR,d\x,d\y,0,ORBE,o\x,o\y,0) Then Text 350,300, "Great Job" Delete o score = score + 1 EndIf EndIf Also as you're a beginner I'd recommend indenting your code, makes it far easier to read and spot mistakes. It's a simple discipline worth adopting. Hope this helps... |
| ||
Graphics 900, 900 SetBuffer BackBuffer() EATUM = LoadImage ("Eatum.png") APPLE = LoadImage("Apple.png") ORBE = LoadImage("Orbe.png") DOOR = LoadImage("Door.png") BACKGROUND = LoadImage("Clouds.jpg") Type EATUM Field x,y End Type Type APPLE Field x,y End Type Type ORBE Field x,y End Type Type DOOR Field x,y End Type e.EATUM = New EATUM e\x = 70 e\y = 200 For z = 1 To 5 a.Apple = New Apple a\x = 100+30*z a\y = 90*z Next ;this is the ORBE that I was talking about. I only wanted 1 of these o.ORBE = New ORBE o\x = 100 o\y = -200 d.DOOR = New DOOR d\x = 50 d\y = 50 Score = 0 ScrollRightLeft = -200 While Not KeyDown (1) Cls TileImage BACKGROUND,ScrollRightLeft DrawImage (EATUM,e\x,e\y) For a.APPLE = Each APPLE DrawImage(APPLE,a\x,a\y) If ImagesCollide(EATUM,e\x,e\y,0,APPLE,a\x,a\y,0) Then Delete a score = score + 1 End If Next Text 0,10, "Score" + Score If KeyDown(203) Then e\x = e\x - 3 ScrollRightLeft = ScrollRightLeft + 3 If(o <> Null) Then If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0) Then o\x = o\x - 3 End If End If EndIf If KeyDown(205) e\x = e\x + 3 ScrollRightLeft = ScrollRightLeft - 3 If(o <> Null) Then If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0) Then o\x = o\x + 3 End If End If EndIf 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 End If End If EndIf 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 End If End If EndIf DrawImage (DOOR,d\x,d\y) If(o <> Null) Then DrawImage (ORBE,o\x,o\y) If ImagesCollide(DOOR,d\x,d\y,0,ORBE,o\x,o\y,0) Delete o score = score + 1 End If Else Text 0,50, "Great Job" End If Flip Wend End Give that a whirl... |