If I used a wide image instead of a map how would I make it so there would be collisions? If someone could make an example out of this example image it would be nice. Thanks a bunch!
IMAGE
IMAGE
Graphics 640,480,32,2 Global backimage=CreateImage(640,480) SetBuffer ImageBuffer(backimage) ClsColor 0,128,255 Cls Color 0,155,0 Rect 0,480-100,640,100,True Rect 100,300,250,35,True MaskImage backimage,0,128,255 Global charimage=CreateImage(50,50) SetBuffer ImageBuffer(charimage) Color 255,0,0 Rect 0,0,50,50,True SetBuffer BackBuffer() ClsColor 0,128,255 Global px#=20 Global py#=320 Global gravity#=4 Global jumping=False While Not KeyHit(1) Cls DrawImage backimage,0,0 DrawImage charimage,px,py If KeyDown(205) px=px+1 EndIf If KeyDown(203) px=px-1 EndIf If px>690 px=-50 EndIf If px<-50 px=690 EndIf If KeyHit(57) If jumping=False jumping=True EndIf EndIf If jumping=True py=py-gravity gravity=gravity-0.08 If ImagesCollide(backimage,0,0,0,charimage,px,py,0) gravity=4 jumping=False EndIf EndIf Flip Wend End
Graphics 640,480,32,2 Global backimage=CreateImage(640,480) SetBuffer ImageBuffer(backimage) ClsColor 0,128,255 Cls Color 0,155,0 Rect 0,480-100,640,100,True Rect 100,300,250,35,True MaskImage backimage,0,128,255 Global charimage=CreateImage(50,50) SetBuffer ImageBuffer(charimage) Color 255,0,0 Rect 0,0,50,50,True SetBuffer BackBuffer() ClsColor 0,128,255 Global px#=20 Global py#=320 Global gravity#=0 ; Changed this from 4 initially Global jumping=True ; Changed this from false initially ; You can now basically regard the variable you called "jumping" as "blockIsInTheAir" While Not KeyHit(1) Cls DrawImage backimage,0,0 DrawImage charimage,px,py If KeyDown(205) ;X axis collision detection added If Not ImagesCollide(backimage,0,0,0,charimage,px+1,py,0) px=px+1 EndIf EndIf If KeyDown(203) ;X axis collision detection added If Not ImagesCollide(backimage,0,0,0,charimage,px-1,py,0) px=px-1 EndIf EndIf If px>690 px=-50 EndIf If px<-50 px=690 EndIf ; I Changed this bit If KeyHit(57) And jumping = False gravity = 4 jumping=True EndIf If ImagesCollide(backimage,0,0,0,charimage,px,py,0) gravity=0 jumping = False Else py=py-Int(gravity) gravity=gravity-0.08 ; The more complicated bit ; Moves the block up so that it is not in contact with the floor ; This prevents the block from getting stuck in the floor after jumping Repeat If ImagesCollide(backimage,0,0,0,charimage,px,py,0) py=py-1 jumping = False gravity = 0 Else Exit EndIf Forever EndIf ; Changes finish here Flip Wend End
; The more complicated bit If gravity < 0 Repeat If ImagesCollide(backimage,0,0,0,charimage,px,py,0) py=py-1 jumping = False gravity = 0 Else Exit EndIf Forever ElseIf gravity > 0 Repeat If ImagesCollide(backimage,0,0,0,charimage,px,py,0) py=py+1 gravity = 0 Else Exit EndIf Forever EndIf
If gravity < 0 Repeat If ImagesCollide(backimage,0,0,0,charimage,px,py,0) py=py-1 jumping = False gravity = -gravity / 3 Else Exit EndIf Forever ElseIf gravity > 0 Repeat If ImagesCollide(backimage,0,0,0,charimage,px,py,0) py=py+1 gravity = -gravity / 3 Else Exit EndIf Forever EndIf