# Can someone send me a "Block behaviour" code

61 Reputation points
2021-04-07T15:32:45.867+00:00

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
``````
Small BASIC
Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
279 questions

1. 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 = 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.

2. 126 Reputation points
2021-04-07T16:35:25.463+00:00

Hi again,

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