Question

# Question

• Friday, October 12, 2012 10:19 AM

Hey guys!

I want create a shape, which can't move throw other shapes. I) created a little game but the "player" can move throw the walls(that's the other shapes).The problem is, I want make the walls/shapes random. Is there any way to do it?

My game: FKF978

Greetings Timo

### All Replies

• Friday, October 12, 2012 12:21 PM

sorry Timo Sö, but I can not try your game because you use some - to me unknown - extension. You should also write into your "Question" which extensions you use.

By the way "Question" is not really a good title for a thread. Most questioning-threads imply that there are some questions being asked. You should be more specific.

But your problem: you should either activate and use some physics or track positions of walls in some kind of 2-dimensional array like: field[X][Y] where you put "empty" in if that certain field is empty or put the name of the thing that is at this position. Then your program can easily check, if that field[x][y] is empty and your player can go there.

You might do it somehow like that:

```field[0][0] = "wall"
field[0][1] = "wall"'...field[7][5] = "empty"'...
' and so on
' later in your code you can check if player wants to go
' to field[X][Y] if it's possible to go there like

if field[X][Y] = "empty" then
' player can go there
' so move there...elseif field[X][Y] = "wall" then' a wall is here' so don't go thereendif
'but WARNING: you can not use just this code by copy & pasting it into your program```

you've got to figure out some way for your special needs by yourself.

If you got the idea, you might think about putting in shapes-name instead of "wall". Use your brains!

it's not a bug- it's a feature

• Edited by Friday, October 12, 2012 3:47 PM
•
• Friday, October 12, 2012 10:44 PM

You can make them random by storing variables in an array like this:

```For i = 1 To 20
X[i] = Math.GetRandomNumber(GraphicsWindow.Width)
Y[i] = Math.GetRandomNumber(GraphicsWindow.Height)
Width[i] = Math.GetRandomNumber(10)+20
Height[i] = Math.GetRandomNumber(10)+20
EndFor```

Then using those variables like this:

```For i = 1 To 20
Shapes.Move(Wall[i],X[i],Y[i])
EndFor```

Then to ensure the player can't go through the walls, you could do something like this:

```For i = 1 to 20
If NewPlayerX > X[i] And NewPlayerX < X[i]+Width[i] And NewPlayerY > Y[i] And NewPlayerY < Y[i]+Height[i] Then
'Make the player bounce away from the wall.
EndIf
EndFor```

I am a 10 year old that loves math, games, and computers. "Everyone is potentially great, you just have to turn it into kinetic greatness."

• Edited by Friday, October 12, 2012 11:51 PM
•
• Friday, October 12, 2012 11:00 PM

Perhaps something like the below:

`Colors()GraphicsWindow.BackgroundColor = "Black"For i = 1 To 20   X[i] = Math.GetRandomNumber(GraphicsWindow.Width)   Y[i] = Math.GetRandomNumber(GraphicsWindow.Height)  Width[i] = Math.GetRandomNumber(10)+20  Height[i] = Math.GetRandomNumber(10)+20 EndForFor i = 1 To 20  GraphicsWindow.BrushColor = Color[Math.GetRandomNumber(ColorsNumber)]  Wall[i] = Shapes.AddRectangle(Width[i],Height[i])  Shapes.Move(Wall[i],X[i],Y[i])EndForPlayerWidth = 50PlayerHeight = 50PlayerX = Math.GetRandomNumber(GraphicsWindow.Width)  PlayerY = Math.GetRandomNumber(GraphicsWindow.Height)While NewPlayerX+PlayerWidth > X[i] And NewPlayerX < X[i]+Width[i] And NewPlayerY+PlayerHeight > Y[i] And NewPlayerY < Y[i]+Height[i]  PlayerX = Math.GetRandomNumber(GraphicsWindow.Width)  PlayerY = Math.GetRandomNumber(GraphicsWindow.Height)EndWhileSpeed = 2Player = Shapes.AddEllipse(PlayerWidth,PlayerHeight)Shapes.Move(Player,PlayerX,PlayerY)GraphicsWindow.KeyDown = KeyDownGraphicsWindow.KeyUp = KeyUpWhile 1 = 1  If Up Then    NewPlayerY = PlayerY-Speed  EndIf  If Down Then    NewPlayerY = PlayerY+Speed  EndIf  If Left Then    NewPlayerX = PlayerX-Speed  EndIf  If Right Then    NewPlayerX = PlayerX+Speed  EndIf  PlayerMove()  Shapes.Move(Player,NewPlayerX,NewPlayerY)  PlayerX = NewPlayerX  PlayerY = NewPlayerY  Program.Delay(10)EndWhileSub PlayerMove  For i = 1 to 20    If NewPlayerX+PlayerWidth > X[i] And NewPlayerX < X[i]+Width[i] And NewPlayerY+PlayerHeight > Y[i] And NewPlayerY < Y[i]+Height[i] Then      NewPlayerX = PlayerX      NewPlayerY = PlayerY    EndIf  EndForEndSubSub KeyDown  Key = GraphicsWindow.LastKey  If Key = "Left" Then    Left = "True"  ElseIf Key = "Right" Then    Right = "True"  ElseIf Key = "Up" Then    Up = "True"  ElseIf Key = "Down" Then    Down = "True"  ElseIf Key = "Space" Then    Space = "True"  EndIfEndSubSub KeyUp  Key = GraphicsWindow.LastKey  If Key = "Left" Then    Left = "False"  ElseIf Key = "Right" Then    Right = "False"  ElseIf Key = "Up" Then    Up = "False"  ElseIf Key = "Down" Then    Down = "False"  ElseIf Key = "Space" Then    Space = "False"  EndIfEndSubSub Colors  ColorsNumber = 11  Color[1] = "White"  Color[2] = "Red"  Color[3] = "Blue"  Color[4] = "Green"  Color[5] = "Yellow"  Color[6] = "Magenta"  Color[7] = "Brown"  Color[8] = "Purple"  Color[9] = "DarkRed"  Color[10] = "DarkBlue"  Color[11] = "DarkGreen"EndSub`

Is that any good?

I am a 10 year old that loves math, games, and computers. "Everyone is potentially great, you just have to turn it into kinetic greatness."

• Friday, October 12, 2012 11:42 PM

Then to ensure the player can't go through the walls, you could do something like this:
```For i = 1 to 20
If PlayerX > X[i] And PlayerX < X[i]+Width[i] And PlayerY > Y[i] And PlayerY < Y[i]+Height[i] Then
'Stop the player from moving
EndIf
EndFor```

ouch, I'm stuck inside the wall, someone help me out please!

- free again, finally- ignore this post...

it's not a bug- it's a feature

• Edited by Friday, October 12, 2012 11:50 PM
•
• Friday, October 12, 2012 11:49 PM

Then to ensure the player can't go through the walls, you could do something like this:

```For i = 1 to 20
If PlayerX > X[i] And PlayerX < X[i]+Width[i] And PlayerY > Y[i] And PlayerY < Y[i]+Height[i] Then
'Stop the player from moving
EndIf
EndFor```

ouch, I'm stuck inside the wall, someone help me out please!

it's not a bug- it's a feature

Okay, bad word choice on my part. But I've fixed that.

I am a 10 year old that loves math, games, and computers. "Everyone is potentially great, you just have to turn it into kinetic greatness."

• Edited by Friday, October 12, 2012 11:50 PM
•
• Saturday, October 13, 2012 8:33 PM

Thanks guys! :D

I will try it.

Greetings Timo

• Wednesday, October 17, 2012 12:42 AM

Is it still a problem?

I am a 10 year old that loves math, games, and computers. "Everyone is potentially great, you just have to turn it into kinetic greatness."