# question

## 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
``````

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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 = 200

Of 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.

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi again,

if struglin with maths, then this LitDev function comes handy ;)

· 1

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ok, but you can send me an example code (one that has an impassable block using this method)

Did you see my solution on the problem in tour posting: https://docs.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.

maze.png (1.7 KiB)
· 1

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

yes i managed to create a collision in that game, but if i want another type of movement, like in the game 'sidescroller', if i try to use the movement of the sidescroller game with this collision it will not work, how can i solve this?