locked
Barrier Problem RRS feed

  • 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
      player = Shapes.AddEllipse(45,45)
      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
        Shapes.AddImage("http://i62.tinypic.com/2hnb9kl.png")
      EndIf
      
      GraphicsWindow.BrushColor = "red"
      
      'Markers
      Marker1 = Shapes.AddEllipse(5,5)
      MarkerText1 = Shapes.AddText(1)
      Shapes.Move(Marker1,102,599)
      Shapes.Move(MarkerText1,95,585)
      
      Marker2 = Shapes.AddEllipse(5,5)
      MarkerText2 = Shapes.AddText(2)
      Shapes.Move(Marker2,140,599)
      Shapes.Move(MarkerText2,145,585)
      
      Marker3 = Shapes.AddEllipse(5,5)
      MarkerText3 = Shapes.AddText(3)
      Shapes.Move(Marker3,102,515)
      Shapes.Move(MarkerText3,102,515)
      
      Marker4 = Shapes.AddEllipse(5,5)
      MarkerText4 = Shapes.AddText(4)
      Shapes.Move(Marker4,143,556)
      Shapes.Move(MarkerText4,143,556)
      
      Marker5 = Shapes.AddEllipse(5,5)
      MarkerText5= Shapes.AddText(5)
      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

Answers

  • 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 Dinomite07 Wednesday, December 3, 2014 2:02 AM
    Tuesday, December 2, 2014 6:37 PM
    Answerer