Did you see my solution on the problem in tour posting: https://learn.microsoft.com/answers/questions/334628/a-problem-in-my-game.html ?
See the image, the player can move around the obstacle or through the gap but not over the obstracle.
Can someone send me a "Block behaviour" code
Can someone send me a code for a block / shape that you cannot pass throught but the movement of the player needs to be like this :
While 1 = 1
Program.Delay(10)
playerBehaviour()
EndWhile
Sub playerBehaviour
If key[input_upKey] Then
player_y = player_y - player_speed
Shapes.Move(gamePlayer,player_x,player_y)
EndIf
If key[input_downKey] Then
player_y = player_y + player_speed
Shapes.Move(gamePlayer,player_x,player_y)
EndIf
If key[input_leftkey] And canMoveLeft Then
player_x = player_x - player_speed
Shapes.Move(gamePlayer,player_x,player_y)
EndIf
If key[input_rightkey] And canMoveRight Then
player_x = player_x + player_speed
Shapes.Move(gamePlayer,player_x,player_y)
EndIf
EndSub
Sub keyDown
k = GraphicsWindow.LastKey
key[k] = "True"
EndSub
Sub keyUp
k = GraphicsWindow.LastKey
key[k] = "False"
EndSub
3 answers
Sort by: Newest
-
WhTurner 1,611 Reputation points
2021-04-08T11:21:02.04+00:00 -
Kristian Virtanen 126 Reputation points
2021-04-07T16:35:25.463+00:00 Hi again,
if struglin with maths, then this LitDev function comes handy ;)
http://litdev.co.uk/LitDev.html#LDMathConvert2Radial -
Kristian Virtanen 126 Reputation points
2021-04-07T16:22:40.887+00:00 Hi Nomestack.
First of all, you need to keep a track for each shape location. Then you can detect possible collisions. Here is main principle.
object1X = 100
object1Y = 100
Object2X = 200
Object2Y = 200Of course, you can turn those as arrays, but lets go like this for example.
Formula itself is easy, you may study it here https://wumbo.net/formula/distance-between-two-points-2d/
Calculate distance between your player and each object (shape) you have. If distance gets too small, dont allow movement.
You propably keep track of x & y like PlayerX & PlayerY, dont change them before you have checked the collision.