Making rectangle move across screen with graphics file

后端 未结 1 1606
猫巷女王i
猫巷女王i 2021-01-26 04:08
from graphics import *

def main():
    win = GraphWin(\"Polygon\", 500, 500)
    r= Rectangle(Point(10,500),Point(150,450))
    r.draw(win)
    while r.getP1()<=450          


        
1条回答
  •  生来不讨喜
    2021-01-26 04:51

    It looks like you are having an odd interaction between a Point and an Integer.

    Namely this line here:

    r=Rectange(Point(r.getP1()+1),(Point(r.getP2()+1)))
    

    You are trying to add 1 to a Point.

    This is likely not doing what you expect it to - try re-writing this so that you get the original P1/P2 values and then increment the specific x/y as necessary.

    Additionally, Rectangle is spelt incorrectly, you should probably be creating a new Rectangle and returning it rather than overriding the existing one (may also cause issues), and you could've tried debugging this by adding a print(r.getP1() + " " + r.getP2()) before and after assignment.

    Another addendum: Your functions should ideally only have one purpose. rectMaker seems to not just make rectangles, but re-draw them, try to change an existing rectangle and then return it. The usual style for games is something like

    def main():
         load()
         while(playing):
             input()
             update()
             draw()
         unload()
    

    0 讨论(0)
提交回复
热议问题