This works pretty well, except it isn't smooth when you are against the tree
AppTitle "Across The Land; Need Help With Collisions!"
Graphics 800,600,0,1
SetBuffer BackBuffer()
AutoMidHandle True
SeedRnd MilliSecs()
Global ScrollX = 0
Global ScrollY = 0
Global FieldMusic = PlayMusic("A.L Field.wav")
Type Player;The Players Type
Field x,y,hit,image,frame,TrueX,TrueY,Atk1,Atk2,Atk3,Atk4,Atk5,Atk6,Sleep
Field Paralyze,Confuse,Poison10,Poison20,Poison30,Poison40,Poison50,GP
Field UnderControl,DecoyGnome1,DecoyGnome2,DecoyGnome3,MaxHit,Item1,Item2,Item3,Item4,Item5,Item6
Field Atk1Name,Atk2Name,Atk3Name,Atk4Name,Atk5Name,Atk6Name
End Type
Global Player.Player = New Player;Make A New Player
Player\x = 400
Player\y = 300
Player\image = LoadImage("Across The Land Gnome.bmp")
Player\frame = 0
Type Terrain;The Type For The Trees, And Other Terrain.(Such As Water, Boulders,Ect.)
Field x,y,TrueX,TrueY,image
End Type
Global ALTreei = LoadImage("A.L Tree Tile.bmp")
Global StopLeft = 0
Global StopRight = 0
Global StopUp = 0
Global StopDown = 0
Global BoardImage = LoadImage("A.L Field BackGround.bmp")
;Make 1 Tree
MakeTree(100,300)
While Not KeyDown(1)
Cls
If Not ChannelPlaying(FieldMusic);If The Music Stops, Restart It.
FieldMusic = PlayMusic("A.L Field.wav")
End If
TileImage BoardImage,Scrollx,ScrollY;Tile The BackGround Image
DrawImage Player\image,Player\x,Player\y,Player\Frame;Draw The Player
MovePlayer();Move The Player
DrawTree();Draw The Trees, And Check Collisions Between Tree And Player.
Flip
Wend
End
Function MakeTree(x,y)
Tree.Terrain = New Terrain
Tree\x = x
Tree\y = y
Tree\TrueX = x
Tree\TrueY = y
Tree\image = ALTreei
End Function
Function DrawTree()
If KeyDown(205)
ScrollX = ScrollX - 5
MoveRight = 1
End If
If KeyDown(203)
MoveLeft = 1
ScrollX = ScrollX + 5
End If
If KeyDown(200)
MoveUp = 1
ScrollY = ScrollY + 5
End If
If KeyDown(208)
ScrollY = ScrollY - 5
MoveDown = 1
End If
For Tree.Terrain = Each Terrain
DrawImage Tree\image,Tree\x,Tree\y
Tree\x = Scrollx + Tree\TrueX
Tree\y = Scrolly + Tree\TrueY
If ImagesOverlap(Player\image,Player\x,Player\y,Tree\image,Tree\x,Tree\y)
If ImagesCollide(Player\image,Player\x,Player\y,0,Tree\image,Tree\x,Tree\y,0)
If MoveRight = 1
ScrollX = ScrollX + 10
End If
If MoveLeft = 1
ScrollX = ScrollX - 10
End If
If MoveUp = 1
ScrollY = ScrollY - 10
End If
If MoveDown = 1
ScrollY = ScrollY + 10
EndIf
TreeHit = 1
Else
TreeHit = 0
EndIf
EndIf
;Check Collisions Between Tree And Player.This is What I need Help With.
;If You Can Come Up With A Better Way To Do This, I Would Be Truly GreatFul.
;
;Currently It Works Like This,
;When The Player Hits The Left Side Of The Tree(Tree\x-50),The Variable StopRight = 1.
;And In The Move Player Function,You Will Notice That The Player Can Only Move Right,
;If StopRight = 0.
;So When The Player Hits The Left Edge Of The Tree, He Can No Longer Move Right.
If TreeHit = 1
;But If The Player Is Not Touching The Right Edge Of The Tree, StopRight Then = 0,
;So That He Can Move Right.
;Because OtherWise, The First Time That The Player Touched The Tree He Would No Longer
;Be Able To Move Right AT ANY TIME!. Even While Not Touching The Tree.
ElseIf TreeHit = 0
End If
;You Can Uncomment These 3 Sections Of Code If You Want.They Work Just Like The Above, Except For
;The Right,Bottom, And Top Sides Of The Tree
;If ImagesCollide(Player\image,400,300,0,Tree\image,Tree\x+50,Tree\y,0)
;StopLeft = 1
;ElseIf Not ImagesCollide(Player\image,400,300,0,Tree\image,Tree\x+50,Tree\y,0)
;StopLeft = 0
;End If
;If ImagesCollide(Player\image,400,300,0,Tree\image,Tree\x,Tree\y+50,0)
;StopUp = 1
;ElseIf Not ImagesCollide(Player\image,400,300,0,Tree\image,Tree\x,Tree\y+50,0)
;StopUp = 0
;End If
;If ImagesCollide(Player\image,400,300,0,Tree\image,Tree\x+50,Tree\y-50,0)
;StopDown = 1
;ElseIf Not ImagesCollide(Player\image,400,300,0,Tree\image,Tree\x+50,Tree\y-50,0)
;StopDown = 0
;End If
;Make Sure The Tree Stays Firmly Glued To Where It's Supposed To Be.
Next
End Function
Function MovePlayer()
;Scroll The Screen In The Appropiate Direction While The Player Is Holding Down One Of The Arrow Keys.
End Function