i'm a bit stick with this platform tile thing, and i can't understand why the following produces such weird results.
normally i'm loading in a level from a file, but i've changes this so that it runs as-is.
basically, the little white square doesn't do what it ought to and i wondered if any of you lot could help me make it work properly.
cheers
charlie
normally i'm loading in a level from a file, but i've changes this so that it runs as-is.
basically, the little white square doesn't do what it ought to and i wondered if any of you lot could help me make it work properly.
SuperStrict 'make level Local tileArray:Int[10, 8] ; For Local i:Int=0To 9 For Local o:Int=0 To 7 If i=0 Or i=9 tileArray[i,o]=1 Else If o=0 Or o=7 tileArray[i,o]=1 Else tileArray[i,o]=0 End If Next Next tilearray[4,4]=1 tilearray[5,4]=1 'variables Graphics 640, 480, 0, 60 Local tilesize:Int = 64 Local x:Float = 2 * tileSize, y:Float = 2 * tileSize Local xVel:Float = 0 Local falling:Int = True Local gravity:Float = 0.1 Local yVel:Float = 0 Local hit:Int = False While Not KeyHit(KEY_ESCAPE) For Local i:Int = 0 To 9 For Local o:Int = 0 To 7 'draw tiles If tileArray[i, o] = 0 SetColor 0, 100, 255 DrawRect i * tilesize, o * tilesize, tilesize, tilesize Else If tileArray[i, o] = 1 SetColor 255, 0, 0 DrawRect i * tilesize, o * tilesize, tilesize, tilesize End If 'wall collisions 'left If rectsOverlap(i * tileSize, o * tileSize, tileSize, tileSize, x, y, 1, 19) And tileArray[i, o] = 1 If x > (i * tileSize) x = (i * tileSize) + 65 End If End If 'right If rectsOverlap(i * tileSize, o * tileSize, tileSize, tileSize, x + 20, y, 1, 19) And tileArray[i, o] = 1 If x + 20 > (i * tileSize) x = (i * tileSize) - 22 End If End If 'bott If rectsOverlap(i * tileSize, o * tileSize, tileSize, tileSize, x + 20, y + 20, 1, 1) And tileArray[i, o] = 1 If falling = True If y + 20 > o falling = False yVel = 0 y = (o * tileSize) - 20 End If End If End If 'top If rectsOverlap(i * tileSize, o * tileSize, tileSize, tileSize, x, y, 1, 1) And tileArray[i, o] = 1 If falling = True If y > o hit = True yVel = -yVel y = (o * tileSize) + 65 End If End If End If 'collide only with tile 0 If hit = False If rectsOverlap(i * tileSize, o * tileSize, tileSize, tileSize, x, y, 20, 20) And tileArray[i, o] = 0 falling = True End If End If Next Next hit = False 'move player If KeyDown(KEY_LEFT) x:-2 If KeyDown(KEY_RIGHT) x:+2 If KeyHit(KEY_UP) And falling = False yVel:-6 falling = True End If If falling = True yVel:+gravity Else yVel = 0 End If y:+yVel SetColor 255, 255, 255 DrawRect x, y, 20, 20 Flip;Cls Wend Function rectsOverlap:Int(x1:Float, y1:Float, w1:Float, h1:Float, x2:Float, y2:Float, .. w2:Float,h2:Float) If x1 > (x2 + w2) Or (x1 + w1) < x2 Then Return False If y1 > (y2 + h2) Or (y1 + h1) < y2 Then Return False Return True End Function
cheers
charlie