# Barrier Problem

• ### Question

• ```graphicwindow()
Levels()
moving()
player()

Sub graphicwindow
GraphicsWindow.Title = "Dungeon Master"
gw = 800
gh = 600
Level = 1
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
EndSub

While ("True")
processKey()
Shapes.Move(player,playerX-25,playerY-25)
Program.Delay(10)
EndWhile

Sub player
playerX = 127
playerY = 580
speed = 3
Shapes.Move(player,playerX-25,playerY-25)
EndSub

Sub moving
GraphicsWindow.KeyDown = OnKeyDown
GraphicsWindow.KeyUp = OnKeyUp
keyLeft = 0
keyRight = 0
keyUp = 0
keyDown = 0
EndSub

Sub OnKeyDown
lastKey = GraphicsWindow.LastKey
If (lastKey = "A") Then
keyLeft = 1
ElseIf (lastKey = "D") Then
keyRight = 1
ElseIf (lastKey = "W") Then
keyUp = 1
ElseIf (lastKey = "S") Then
keyDown = 1
ElseIf (lastKey = "Escape") Then
Program.End()
EndIf
EndSub

Sub OnKeyUp
lastKey = GraphicsWindow.LastKey
If (lastKey = "A") Then
keyLeft = 0
ElseIf (lastKey = "D") Then
keyRight = 0
ElseIf (lastKey = "W") Then
keyUp = 0
ElseIf (lastKey = "S") Then
keyDown = 0
EndIf
EndSub

Sub processKey
'Move object - note it can move diagonally if 2 keys are pressed
If (keyLeft = 1) Then
playerX = playerX-speed
EndIf
If (keyRight = 1) Then
playerX = playerX+speed
EndIf
If (keyUp = 1) Then
playerY = playerY-speed
EndIf
If (keyDown = 1) Then
playerY = playerY+speed
EndIf

If Level = 1 Then

'Barriers

'Marker 1 and 2
If (playerX >= 102 And playerX <= 140) and (playerY >= 580) Then
playerY = 580
EndIf

'Marker 1 and 3
If (playerY >= 515 And playerY <= 600) and (playerX <= 122) Then
playerX = 127
EndIf

'Marker 2 and 4
If (playerY >= 556 And playerY <= 600) and (playerX >= 127) Then
playerX = 127
EndIf

'Marker 3 and 5
If (playerX >= 102 And playerX <= 356) and (playerY >= 515) Then
playerY = 537
EndIf

EndIf
EndSub

sub Levels

'Level One Background
If Level = 1 then
EndIf

GraphicsWindow.BrushColor = "red"

'Markers
Shapes.Move(Marker1,102,599)
Shapes.Move(MarkerText1,95,585)

Shapes.Move(Marker2,140,599)
Shapes.Move(MarkerText2,145,585)

Shapes.Move(Marker3,102,515)
Shapes.Move(MarkerText3,102,515)

Shapes.Move(Marker4,143,556)
Shapes.Move(MarkerText4,143,556)

Shapes.Move(Marker5,356,512)
Shapes.Move(MarkerText5,356,512)

EndSub```

Barrier 3 to 5 is messing up the other barriers. I know what is wrong but I don't know how to fix it.
Tuesday, December 2, 2014 1:15 AM

• Dinomite07, There is something wrong in the test for barrier 3-5, the if statemnent should be:

playerY <= 515  (( with < instead of > )).

I had some problems with testing as my virusscanner (Kaspersky) wouldn't let me run your program. I just switched of teh scanner for some time and found the problem with that statement, but more testing without virusscanner doesn't look advisable.

Jan [ WhTurner ] The Netherlands

• Marked as answer by Wednesday, December 3, 2014 2:02 AM
Tuesday, December 2, 2014 6:37 PM