# Constant Motion • ### Question

• How do I make my shape turn and move in constant motion so that a one side of the shape stays the "back end" for the whole game??

```GraphicsWindow.BackgroundColor= "Black"
GraphicsWindow.Height="1000"
GraphicsWindow.Width="1000"
GraphicsWindow.BrushColor=colour
GraphicsWindow.PenColor= "White"
GraphicsWindow.TextInput=MoveCycle
x=0
y=0
Sub MoveCycle
If (GraphicsWindow.LastKey= "D") Then
x=x+5
Shapes.Move(player,x,y)
ElseIf (GraphicsWindow.LastKey= "A") Then
x=x-5
Shapes.Move(player,x,y)
ElseIf (GraphicsWindow.LastKey="S") Then
y=y+5
Shapes.Move(player,x,y)
ElseIf (GraphicsWindow.LastKey="W") Then
y=y-5
Shapes.Move(player,x,y)
EndIf
EndSub```

Wednesday, November 21, 2012 5:36 PM

• Here you go.

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:14 PM
• I just wanted to rectify 1 of my comments -> s = 5   ' Player's Size is wrong!

Correct -> s = 5   '  Player's Speed   :P

Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

Wednesday, November 21, 2012 10:26 PM

### All replies

• Here you go. Replace your sub with this.

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

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

Wednesday, November 21, 2012 5:41 PM
• Thank You!!
Wednesday, November 21, 2012 5:46 PM
• You may also take a look at this thread from just 1 day ago! -> Constant Mo

It's also about Sub MoveCycle!   ;-)

Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

Wednesday, November 21, 2012 6:37 PM
• Here you go.

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:14 PM
• I just wanted to rectify 1 of my comments -> s = 5   ' Player's Size is wrong!

Correct -> s = 5   '  Player's Speed   :P