Two statements in small basics arent working together

159 views Asked by At

For an assignment in IT we have to create a house using small basics, to get a higher level we are told to make the colours of the windows change colour. I've done this; I've tried to accomplish a higher level by adding moving clouds also, the two different statements aren't working together.

My code is below:

'background
GraphicsWindow.Title= "My House Assessment"
GraphicsWindow.Height= "600"
GraphicsWindow.Width= "1000"
GraphicsWindow.BackgroundColor="#198cFF"
'grass
GraphicsWindow.PenColor= "#2bf90b"
GraphicsWindow.BrushColor= "#2bf90b"
GraphicsWindow.PenColor= "#0000000"
GraphicsWindow.DrawRectangle(0,400,1000,500)
GraphicsWindow.FillRectangle(0,400,1000,500)
'path
GraphicsWindow.BrushColor= "#34000d
GraphicsWindow.PenColor= "#34000d"
GraphicsWindow.DrawTriangle(700,600,300,300,0,1000)
GraphicsWindow.FillTriangle(700,600,300,300,0,1000)
'top floor
GraphicsWindow.BrushColor="#173cf0"
GraphicsWindow.DrawRectangle(100,100,750,200)
GraphicsWindow.FillRectangle(100,100,750,200)
'ground floor
GraphicsWindow.BrushColor="#ffffcc"
GraphicsWindow.DrawRectangle(100,300,750,200)
GraphicsWindow.FillRectangle(100,300,750,200)
'roof
GraphicsWindow.BrushColor="#808080"
GraphicsWindow.DrawTriangle(100,100,425,10,850,100)
GraphicsWindow.FillTriangle(100,100,425,10,850,100)
'door
GraphicsWindow.BrushColor="#000000"
GraphicsWindow.PenColor="#000000"
GraphicsWindow.DrawRectangle(400,350,100,150)
GraphicsWindow.FillRectangle(400,350,100,150)
''number on door
GraphicsWindow.BrushColor="#FFFFFF"
GraphicsWindow.DrawText(450,400,"45")
'doorknob
GraphicsWindow.BrushColor="#FFFFFF"
GraphicsWindow.DrawEllipse(475,420,10,10)
GraphicsWindow.FillEllipse(475,420,10,10)

'windows on floor one
For i= 1 To 5000000
GraphicsWindow.BrushColor= GraphicsWindow.GetRandomColor()
GraphicsWindow.DrawEllipse (200,120,150,150)
GraphicsWindow.FillEllipse(200,120,150,150)
GraphicsWindow.DrawEllipse (600,120,150,150)
GraphicsWindow.FillEllipse(600,120,150,150)
timer.Interval=1000
EndFor
'clouds
Sball = Shapes.AddEllipse(100, 100)
Sball2 = Shapes.AddEllipse(100,100)
Sball3 = Shapes.AddEllipse(100,100)
start:
Shapes.Move(Sball,400,50)
Shapes.Move(Sball2,450,50)
Shapes.Move(Sball3,500,50)
x = 200
Shapes.Animate(Sball,800,50,x)
Shapes.Animate(Sball2,850,50,x)
Shapes.Animate(Sball3,900,50,x)
Program.Delay(500)
If (Shapes.GetLeft(Sball) = x) Then
Shapes.Animate(Sball, 0, 340, 500)
EndIf
If (Shapes.GetLeft(Sball2) = x)Then
Shapes.Animate(Sball, 0, 340, 500)
EndIf

Shapes.Move(Sball,800,50)
Shapes.Move(Sball2,850,50)
Shapes.Move(Sball3,900,50)
x = 200
Shapes.Animate(Sball,400,50,x)
Shapes.Animate(Sball2,450,50,x)
Shapes.Animate(Sball3,500,50,x)
Program.Delay(500)
If (Shapes.GetLeft(Sball) = x) Then
Shapes.Animate(Sball, 0, 340, 500)
EndIf
If (Shapes.GetLeft(Sball2) = x)Then 
Shapes.Animate(Sball, 0, 340, 500)
EndIf
If (Shapes.GetLeft(Sball3) = x)Then
Shapes.Animate(Sball, 0, 340, 500)
EndIf
Goto start
1

There are 1 answers

0
Zock77 On BEST ANSWER

The first thing I noticed is that you are using Shapes.GetLeft for getting the position of the animated shape. This will not work because Animated shapes will always return the endpoint as their position, even while they are moving.

The second thing is this:

For i= 1 To 5000000
GraphicsWindow.BrushColor= GraphicsWindow.GetRandomColor()
GraphicsWindow.DrawEllipse (200,120,150,150)
GraphicsWindow.FillEllipse(200,120,150,150)
GraphicsWindow.DrawEllipse (600,120,150,150)
GraphicsWindow.FillEllipse(600,120,150,150)
timer.Interval=1000
EndFor

This will not work because timer.Interval=1000 is not a delay. It sets the interval between calling the timer event (you aren't using it here). What you want is Program.Delay(1000).

Also, the For statement is not the way to go. Use a while :D. Once you hit a for loop, the program cannot pass it until it is completed. So that is why the rest of the program isn't working.

Try this program:

GraphicsWindow.BrushColor="#000000"
GraphicsWindow.PenColor="#000000"
GraphicsWindow.DrawRectangle(400,350,100,150)
GraphicsWindow.FillRectangle(400,350,100,150)
''number on door
GraphicsWindow.BrushColor="#FFFFFF"
GraphicsWindow.DrawText(450,400,"45")
'doorknob
GraphicsWindow.BrushColor="#FFFFFF"
GraphicsWindow.DrawEllipse(475,420,10,10)
GraphicsWindow.FillEllipse(475,420,10,10)

Cloud1 = Shapes.AddEllipse(30,30)
Cloud2 = Shapes.AddEllipse(30,30)
Cloud3 = Shapes.AddEllipse(30,30)

xpos = 100

'windows on floor one
While 1 = 1 'This will repeat while the statement is true (1 always = 1)
GraphicsWindow.BrushColor= GraphicsWindow.GetRandomColor()
GraphicsWindow.DrawEllipse (200,120,150,150)
GraphicsWindow.FillEllipse(200,120,150,150)
GraphicsWindow.DrawEllipse (600,120,150,150)
GraphicsWindow.FillEllipse(600,120,150,150)


'Clouds
xpos = - xpos 
Shapes.Animate(Cloud1,xpos+300,100,1000)
Shapes.Animate(Cloud2,-xpos+300,150,1000)
Shapes.Animate(Cloud3,xpos+400,100,1000)
Program.Delay(1000)
EndWhile