locked
Moving Smoothly RRS feed

  • Question

  • I have gotten my light cycle to turn and move but it doesnt move continuously.  What I want is for it to instead of stopping when it turns before moving again, I want it to flow into a continuous no stopping motion. Here is my Sub code..
    Sub MoveCycle
      If (GraphicsWindow.LastKey= "D") Then 
        x=x+5
        Shapes.Rotate(player,90)
        Shapes.Move(player,x,y)
      ElseIf (GraphicsWindow.LastKey= "A") Then
        Shapes.Rotate(player,90)
        x=x-5
        Shapes.Move(player,x,y)
      ElseIf (GraphicsWindow.LastKey="S") Then
        y=y+5
        Shapes.Move(player,x,y)
        Shapes.Rotate(player,0)
      ElseIf (GraphicsWindow.LastKey="W") Then
        y=y-5
        Shapes.Move(player,x,y)
        Shapes.Rotate(player,0)
        EndIf
      EndSub

    Wednesday, November 21, 2012 6:03 PM

Answers

  • I believe that this question was answered here.

    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    Wednesday, November 21, 2012 7:07 PM
  • Here you go. it'll move smothly and trace a line.

    gw = 700   '  GraphicsWindow's  Width
    gh = 600   '  GraphicsWindow's  Height

    w = 15     '  Player's Width
    h = 40     '  Player's Height
    s = 5      '  Player's Size

    x = gw/2   '  Player's Initial X Position
    y = gh/2   '  Player's Initial Y Position

    GraphicsWindow.CanResize = "False"
    GraphicsWindow.Width  = gw
    GraphicsWindow.Height = gh
    GraphicsWindow.BackgroundColor = "Black"
    GraphicsWindow.BrushColor = "Blue"
    GraphicsWindow.KeyUp = KU
    GraphicsWindow.KeyDown = Kd
    GraphicsWindow.PenColor   = "White"

    player = Shapes.AddEllipse(w,h)  ' Creates Player's Object
    MoveCycle()  '  Makes Player Move to Its Initial Position

    GraphicsWindow.TextInput = MoveCycle  ' Sets Keyboard Trigger Event Sub

    While 1 = 1
    Program.Delay(5)
    MoveCycle()
    EndWhile

    Sub KD
      key = GraphicsWindow.LastKey
      EndSub

    Sub Ku
      dx = 0
      dy = 0
      key = ""
      EndSub
    Sub MoveCycle
      x = x + dx
      y = y + dy
      If (Key = "D") Then
        dx = s
        dy = 0
      ElseIf (Key = "A") Then
        dx = -s
        dy = 0
      ElseIf (Key = "S") Then
        dy = s
        dx = 0
      ElseIf (Key = "W") Then
        dy = -s
        dx = 0
      EndIf
     
      If x < 0 Then           '  Checks Screen's Width Limits
        x = gw - w
      ElseIf x > gw - w Then
        x = 0
      EndIf
     
      If y < 0 Then           '  Checks Screen's Height Limits
        y = gh - h
      ElseIf y > gh - h Then
        y = 0
      EndIf
     
      Shapes.Move(player,x,y) '  Moves Player
     
      GraphicsWindow.SetPixel(x+w/2, y+h/2  "Green")  ' Leaves a Point Trail
     
    EndSub


    a spark to start a fire is necessary. But mainly you need dry kindling.

    Wednesday, November 21, 2012 8:12 PM
    Answerer

All replies

  • I believe that this question was answered here.

    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    Wednesday, November 21, 2012 7:07 PM
  • Here you go. it'll move smothly and trace a line.

    gw = 700   '  GraphicsWindow's  Width
    gh = 600   '  GraphicsWindow's  Height

    w = 15     '  Player's Width
    h = 40     '  Player's Height
    s = 5      '  Player's Size

    x = gw/2   '  Player's Initial X Position
    y = gh/2   '  Player's Initial Y Position

    GraphicsWindow.CanResize = "False"
    GraphicsWindow.Width  = gw
    GraphicsWindow.Height = gh
    GraphicsWindow.BackgroundColor = "Black"
    GraphicsWindow.BrushColor = "Blue"
    GraphicsWindow.KeyUp = KU
    GraphicsWindow.KeyDown = Kd
    GraphicsWindow.PenColor   = "White"

    player = Shapes.AddEllipse(w,h)  ' Creates Player's Object
    MoveCycle()  '  Makes Player Move to Its Initial Position

    GraphicsWindow.TextInput = MoveCycle  ' Sets Keyboard Trigger Event Sub

    While 1 = 1
    Program.Delay(5)
    MoveCycle()
    EndWhile

    Sub KD
      key = GraphicsWindow.LastKey
      EndSub

    Sub Ku
      dx = 0
      dy = 0
      key = ""
      EndSub
    Sub MoveCycle
      x = x + dx
      y = y + dy
      If (Key = "D") Then
        dx = s
        dy = 0
      ElseIf (Key = "A") Then
        dx = -s
        dy = 0
      ElseIf (Key = "S") Then
        dy = s
        dx = 0
      ElseIf (Key = "W") Then
        dy = -s
        dx = 0
      EndIf
     
      If x < 0 Then           '  Checks Screen's Width Limits
        x = gw - w
      ElseIf x > gw - w Then
        x = 0
      EndIf
     
      If y < 0 Then           '  Checks Screen's Height Limits
        y = gh - h
      ElseIf y > gh - h Then
        y = 0
      EndIf
     
      Shapes.Move(player,x,y) '  Moves Player
     
      GraphicsWindow.SetPixel(x+w/2, y+h/2  "Green")  ' Leaves a Point Trail
     
    EndSub


    a spark to start a fire is necessary. But mainly you need dry kindling.

    Wednesday, November 21, 2012 8:12 PM
    Answerer
  • Zock,

    Thank you for your great contributions in this forum! Can you email me? It's edprice at Microsoft.

    Thanks!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    Friday, December 7, 2012 9:29 PM