Making Items scroll with background
BlitzPlus Forums/BlitzPlus Programming/Making Items scroll with background
| ||
I'm trying to figure out how to make my apples scroll with the background so that I can go away from them when need be and come back to them when need be unless they are collected. Below, I commented on the parts that I'm trying to change to make it easier to find. Thanks:
Graphics 900, 900
SetBuffer BackBuffer()
EATUM = LoadImage ("Eatum.png")
APPLE = LoadImage("Apple.png")
ORBE = LoadImage("Orbe.png")
DOOR = LoadImage("Door.png")
DOOR2 = LoadImage ("RDoor.png")
DOOR3 = LoadImage ("GDOOR.png")
DOOR4 = LoadImage ("PDOOR.png")
PANCAKES = LoadImage ("Pancakes.png")
INVISIBLEPATCH = LoadImage ("Invisible Patch.png")
MUSIC = LoadSound ("Track1.mp3")
COLLECTIONSOUND = LoadSound ("Collectionsound.mp3")
BACKGROUND = LoadImage("Clouds.jpg")
BACKGROUND2 = LoadImage("backgroundtree.jpg")
BACKGROUND3 = LoadImage("Background3.jpg")
BACKGROUND4 = LoadImage ("Barber Shop.jpg")
BACKGROUND5 = LoadImage ("Background5.jpg")
BACKGROUND6 = LoadImage ("Background6.jpg")
BACKGROUND7 = LoadImage ("Armsup.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
Type DOOR2
Field x,y
End Type
Type DOOR3
Field x,y
End Type
Type DOOR4
Field x,y
End Type
Type PANCAKES
Field x,y
End Type
Type INVISIBLEPATCH
Field x,y
End Type
Type BACKGROUND
Field x,y
Field image
End Type
e.EATUM= New EATUM
e\x = 70
e\y = 200
;I'm trying to get this array of apples to move with the background
;kind of like the coins in Super Mario Bros 3 where one can either walk
;far away from the coins or towards the coins and the coins would
;still be in the same place (unless they are collected). That is, I'm
;trying to make these apples be that way.
For z = 1 To 5
a.Apple = New Apple
a\x = 50*z
a\y = 30
Next
o.ORBE = New ORBE
o\x = 100
o\y = -200
d.DOOR = New DOOR
d\x = 50
d\y = 50
b.BACKGROUND = New BACKGROUND
b\x = -200
b\y = 20
b\image = BACKGROUND
Score = 0
amx = 1
PlaySound MUSIC
While Not KeyDown (1)
Cls
TileImage (b\image,b\x,b\y)
Text 150,90, "Score " + Score
;Once again, here is the part that I would like to see scrolling with the
;background (unless they are collected).
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
PlaySound (COLLECTIONSOUND)
EndIf
Next
If KeyDown(203)
e\x = e\x - 3
b\x = b\x + 3
If (o <> Null) Then
If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0)
o\x = o\x - 3
EndIf
EndIf
EndIf
If KeyDown(205)
e\x = e\x + 3
b\x = b\x - 3
If (o <> Null) Then
If ImagesCollide(EATUM,e\x,e\y,0,ORBE,o\x,o\y,0)
o\x = o\x + 3
EndIf
EndIf
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
EndIf
EndIf
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
EndIf
EndIf
EndIf
If (o <> Null) Then
DrawImage (ORBE,o\x,o\y)
If (d <> Null) Then
DrawImage (DOOR,d\x,d\y)
If ImagesCollide(DOOR,d\x,d\y,0,ORBE,o\x,o\y,0) Then
Delete o
Delete d
score = score + 1
b\image = BACKGROUND2
p.PANCAKES = New PANCAKES
p\x = 20
p\y = 20
EndIf
EndIf
EndIf
If (p <> Null) Then
DrawImage (PANCAKES,p\x,p\y)
If ImagesCollide (EATUM,e\x,e\y,0,PANCAKES,p\x,p\y,0) Then
Delete p
score = score + 1
b\image = BACKGROUND3
d2.DOOR2 = New DOOR2
d2\x = 20
d2\y = 120
EndIf
EndIf
If (d2 <> Null) Then
DrawImage (DOOR2,d2\x,d2\y)
If ImagesCollide (EATUM,e\x,e\y,0,DOOR2,d2\x,d2\y,0) Then
Delete d2
b\image = BACKGROUND4
d3.DOOR3 = New DOOR3
d3\x = 300
d3\y = 420
EndIf
EndIf
If (d3 <> Null) Then
DrawImage (DOOR3,d3\x,d3\y)
If ImagesCollide (EATUM,e\x,e\y,0,DOOR3,d3\x,d3\y,0)
Delete d3
b\image = BACKGROUND5
d4.DOOR4 = New DOOR4
d4\x = 30
d4\y = 30
EndIf
EndIf
If (d4 <> Null) Then
DrawImage (DOOR4,d4\x,d4\y)
If ImagesCollide (EATUM,e\x,e\y,0, DOOR4,d4\x,d4\y,0)
Delete d4
b\image = BACKGROUND6
i.INVISIBLEPATCH = New INVISIBLEPATCH
i\x = 40
i\y = -200
EndIf
EndIf
If (i <> Null) Then
DrawImage (INVISIBLEPATCH,i\x,i\y)
If ImagesCollide (EATUM,e\x,e\y,0,INVISIBLEPATCH,i\x,i\y,0)
Delete i
b\image = BACKGROUND7
EndIf
EndIf
DrawImage (EATUM,e\x,e\y)
Flip
Wend
|
| ||
| Hi, Without trying it, just add the background x offset to the apple position.. Something like:
For a.APPLE = Each Apple
DrawImage(APPLE,(a\x + b\x),a\y)
If ImagesCollide(EATUM,e\x,e\y,0,APPLE,(a\x + b\x),a\y,0) Then
Delete a
score = score + 1
PlaySound (COLLECTIONSOUND)
EndIf
Next
Bear in mind your background starts at -200 on the x co-ords, so you'll now need to offest your apples by +200 when you initialise them in order to see them where they were originally. eg..
For z = 1 To 5
a.Apple = New Apple
a\x = 250*z ;(+200 hundred to account for background offset)
a\y = 30
Next
Regards, |
| ||
| Thanks Yeshu. It worked! |
| ||
| No worries. I guess you are learning a lot on here, However, it should be..
For z = 1 To 5
a.Apple = New Apple
a\x = 200+(50*z) ; as 200 is an absolute offset
a\y = 30
Next
Otherwise your apples will be cast far and adrift. 8o) Best Regards, |