Quote: "I fixed it with this code."
That's only going to work if your ground is always at the same height. Once you start getting into changing your landscape...It wont work
My idea would be to create a function to determine the Players points of contacts with Grounds[SpriteID]
Using GetSpriteHeight(Grounds[SPriteID]) and GetSpriteWidth(Grounds[SPriteID])
Your going to need to get the width and height of all the ground sprites to determine where the bounds start and end. Also you will need the Sprites Position GetSpriteXPos and GetSpriteYPos
^ This is all just a
theory and it has me interested in creating an example. I will get back to you
Edit: I sort of got it to work...Its nothing worth sharing...I might have another go at it some time later.
Ill just go ahead and share it
You never know someone might chime in tell me the actual way to do it
// Project: Physics Test 2
// Created: 2015-09-25
// set window properties
SetWindowTitle( "Physics Test 2" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
Global Dim Ground[100]
Ground[1] = CreateSprite(0)
SetSpriteSize(Ground[1],1024,50)
SetSpritePosition(Ground[1],0,768-50)
Ground[2] = CreateSPrite(0)
SetSpriteSize(Ground[2],100,100)
SetSpritePosition(Ground[2],400,768-150)
Ground[3] = CreateSprite(0)
SetSPriteSize(Ground[3],100,100)
SetSpritePosition(Ground[3],600,768-300)
Ground[4] = CreateSprite(0)
SetSpriteSize(Ground[4], 100,100)
SetSpritePosition(Ground[4],800,768-150)
Player = CreateSprite(0)
SetSPriteSize(Player,30,60)
Global Player
Global YVelocity# = 5
Global XVelocity# = 5
Global Collision = 0
do
PlayerX# = GetSpriteX(Player)
PlayerY# = GetSpriteY(Player)
YVelocity# = 5
XVelocity# = 5
GroundCollision()
If GetRawKeyState(37) = 1
SetSpritePosition(Player,PlayerX# - XVelocity#,PlayerY# )
elseif GetRawKeyState(39) = 1
SetSpritePosition(Player,PlayerX# + XVelocity#,PlayerY#)
ElseIf GetRawKeyState(38) = 1 and Collision = 1
YVelocity#=5
SetSpritePosition(Player,PlayerX#,PlayerY# - YVelocity#)
ElseIf GetrawKeyState(38) = 1
SetSpritePosition(Player,PlayerX#,PlayerY# - YVelocity#)
ElseIf GetRawKeyState(40) = 1
SetSpritePosition(Player,PlayerX#,PlayerY# + YVelocity#)
endif
Print(GetRawLastKey())
Print( ScreenFPS() )
Sync()
loop
Function GroundCollision()
For ID = 1 to 4
GroundWidth# = GetSpriteWidth(Ground[ID])
GroundHeight# = GetSpriteHeight(Ground[ID])
GroundX# = GetSpriteX(Ground[ID])
GroundY# = GetSpriteY(Ground[ID])
PlayerXPos# = GetSpriteX(Player)
PlayerYPos# = GetSpriteY(Player)
PlayerHeight# = GetSpriteHeight(Player)
PlayerYPos# = PlayerYPos# + PlayerHeight#
//If PlayerXPos# > GroundX# and PlayerYPos# > GroundY# and PlayerXPos# < GroundX# + GroundWidth# and PlayerYPos# < GroundY# + GroundHeight#
If PlayerXPos# > GroundX# and PlayerXPos# < GroundX# + GroundWidth# and PlayerYPos# > GroundY# and PlayerYPos# < GroundY# + 10
YVelocity# = 0
Collision = 1
endif
Next ID
EndFunction
This is only checking to see if the sprite is in contact with the top of each Ground sprite.
If PlayerXPos# > GroundX# and PlayerXPos# < GroundX# + GroundWidth# and PlayerYPos# > GroundY# and PlayerYPos# < GroundY# + 10
^ this is what I am worried about....Something about it just feels wrong...Too many ands...
Move around with the arrow keys (Up,Right,Left,Down)
Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim