locked
X and Y Variables RRS feed

  • Question

  • So I am working on an Armegatron like game, and I am almost complete. However, I'm having trouble getting my shape to "crash when it hits the top and left walls (where x=0 and y=0). I have tried coding it a million different ways, and it I have no idea why it's not crashing. The code allows for the shape to crash at the right and bottom walls though. This is part of my current  code:

    player= Shapes.AddEllipse(15,40)
    x=0
    y=0
    Moving= "true"
    Start:
    If (Moving= "true") Then
    X = x+delX
    Y = y+delY
    GraphicsWindow.TextInput= MoveCycle
    Shapes.Move(player,x,y)
    If (x>5 and y>5) Then
      If(GraphicsWindow.GetPixel(x+15/2+2,y+40/2+2) <> "#000000") Then
      GraphicsWindow.ShowMessage("You have crashed, and are banished from Kyragetron!", name+", YOU ARE BANISHED!")
      Goto Restart
      ElseIf (x>1000 or x<5) then
      GraphicsWindow.ShowMessage("You have crashed, and are banished from Kyragetron!", name+", YOU ARE BANISHED!")
      Goto Restart
      ElseIf (y>650 or y<5) then
      GraphicsWindow.ShowMessage("You have crashed, and are banished from Kyragetron!", name+", YOU ARE BANISHED!")
      Goto Restart
      EndIf
    Endif
    There are many lines missing before and following this chunk of the code obviously, but any comments as to why it's not working would be appreciated!
    Friday, November 23, 2012 6:22 PM

Answers

  •  if you get pixel values out of window,  it crashes.

    PLZ see    VFQ142-2  

         
    Wednesday, November 28, 2012 7:37 AM
    Answerer

All replies

  • My guess is that somewhere you are doing an operation using x and y that are outside the graphics window size, probably the GetPixel or some other command you are not showing.

    Suggest you do a TextWindow.WriteLine of the values you are using and you should see the problem just before it crashes, or test by deliberately doing some test commands on coordinates outside the graphicswindow to test this causes a crash.

    Friday, November 23, 2012 6:45 PM
  • I am using a GetPixel command later in the program, and I need to keep it. How does it affect this part of the program? What would you suggest I do to have the cycle "crash" at the edge of the screen like I want it to?
    Friday, November 23, 2012 6:57 PM
  • I you could post the whole program, that would be helpful.

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

    Saturday, November 24, 2012 1:00 AM
    Answerer
  • pleasehelpmeicantcode  For example,   this makes "crash" 5 times.

    1) red rectangle 2)blue rectangle 3)x>280  4)y>320  5) X=0&Y=0

    GraphicsWindow.BackgroundColor="#000000"    '  Black
    GraphicsWindow.BrushColor="Red"             ' #FF0000
    GraphicsWindow.FillRectangle(100,100,30,20)
    GraphicsWindow.BrushColor="Blue"            ' #0000FF
    GraphicsWindow.FillRectangle(180,150,30,20)
    player= Shapes.AddEllipse(15,40)
    name="Test"
    delX=2
    delY=2
    Moving= "true"

    while Moving= "true"
      X = x+delX
      Y = y+delY
      Shapes.Move(player,x,y)
      GraphicsWindow.Title="X= "+X+"   Y= "+Y   '  to see where it is
      If (GraphicsWindow.GetPixel(x,y) ="#FF0000" or GraphicsWindow.GetPixel(x,y) ="#0000FF") Then
        GraphicsWindow.ShowMessage("You have crashed, and are banished from Kyragetron!", name+", YOU ARE BANISHED!")
        x=X+35         '  to skip  rectangle
      elseIf x=0 and y=0 then ' left top corner
        GraphicsWindow.ShowMessage("You have crashed  !", name+", YOU ARE BANISHED!")
        Moving= "false"   ' to stop
      elseIf x>280 then
        GraphicsWindow.ShowMessage("You have crashed, and are banished from Kyragetron!", name+", YOU ARE BANISHED!")
        delx=-delx      ' turn left   delX<0
      ElseIf y>320  then
        GraphicsWindow.ShowMessage("You have crashed, and are banished from Kyragetron!", name+", YOU ARE BANISHED!")
        delx=-delx      '  delx>0
        X=-delx             '  return   home ;  x=x+delx   becomes 0
        y=-dely
      EndIf
      Program.Delay(50)
    endwhile

    Saturday, November 24, 2012 3:13 AM
    Answerer
  • Ok the import code for the part of my program I need help with is VFQ142. As you will see, the cycle crashes at the bottom wall and the right wall, but not the top or left wall.

    Monday, November 26, 2012 6:53 PM
  • PLZ see this image. 

    line31....If (x>5 and y>5) Then  is the problem.

    Remove this.   and change to

     line35....(x>1000 or x<delx)

     line38....(y>650 or y<dely)

    *shape is rotated(90deg).           so, xlength =40 and delx=12

    *line32.... If (GraphicsWindow.GetPixel(x+40/2+12,y+40/2+12) <> "#000000") Then   ......needs more consideration .

    This phenomenon occurs.


    Monday, November 26, 2012 11:54 PM
    Answerer
  • PLZ see    VFQ142-0  

    If (GraphicsWindow.GetPixel(x+40/2+delX,y+40/2+delY) <> "#000000") Then  

    Tuesday, November 27, 2012 1:24 AM
    Answerer
  • I ran this program (the import code you wrote at the top of your last reply) and a very large error screen appeared every time I crashed into the top and left walls. Not exactly what I want to happen, but closer! Does anybody know why that happened?
    Tuesday, November 27, 2012 5:40 PM
  •  if you get pixel values out of window,  it crashes.

    PLZ see    VFQ142-2  

         
    Wednesday, November 28, 2012 7:37 AM
    Answerer
  • That runs perfectly! Thank you very much!
    Wednesday, November 28, 2012 6:41 PM