Jack loves to do jumping jacks. Create a simulation of Jack consisting of a stick figure and three buttons: start, stop, and quit. If the user clicks the start button, Jack begins jumping; if the user clicks the stop button, Jack stops jumping; if the user clicks the quit button, the program terminates (including closing the window). If the user clicks on the screen anywhere outside of a button, no action occurs. Supply instructions to the user when the simulation starts.

That is the problem i am trying to solve. I created jack and bottons but how am i gonna make it jump up and down ?

If you provide the code you have for making the stick figure and buttons we should be able to figure out the best way for your program, otherwise we don't know what toolkit you're using (Tk, GTK, QT, WX, some derivative of pyGame).

Perhaps you could hook an event to the button that would call a method to replace the image of Jack with an animated GIF of him jumping?

- Joe

from graphics import*


win = GraphWin ("GraphicsWin", 900,700)
circ = Circle(Point(200,400),30)
circ.draw(win)

line1 = Line(Point(200,430),Point(200,530))
line1.draw(win)

line2 = Line(Point(200,450),Point(180,500))
line2.draw(win)

line3 = Line(Point(200,450),Point(220,500))
line3.draw(win)

line4 = Line(Point(200,530),Point(180,580))
line4.draw(win)

line5 = Line(Point(200,530),Point(220,580))
line5.draw(win)

rect1 = Rectangle(Point(300,250),Point(400,300))
rect1.draw(win)

rect2 = Rectangle(Point(400,250),Point(500,300))
rect2.draw(win)

rect3 = Rectangle(Point(500,250),Point(600,300))
rect3.draw(win)

t = Text(Point(350,275),"Start")
t.draw(win)

t = Text(Point(450,275),"Stop")
t.draw(win)

t = Text(Point(550,275),"Quit")
t.draw(win)

I would suggest putting the stick figure in a class that has an update method. The update will raise and lower the stick figures y position up and down. You will also need a while loop for the main code, so you can call the update method you created. You can base the y on it's current position. I.E. if y < someValue then add to y.

You don't need to put it in a class, your basically needing to manipulate the stick figures y position inside a while loop.

I think graphics has an undraw() method, you'll have to check to be sure, but set a variable to True or False. If True, call function_1 which undraws "standing" and draws "jump" and set variable=False. If False, call function_2 and do the reverse. It would be much easier if all of figure 1 is in list_1, and all of figure 2 is in list 2. A pseudo-example:

win = GraphWin ("GraphicsWin", 900,700)

def draw_1(list_1):
    for object in list_1:
        object.draw(win)

def undraw_1(list_1):
    for object in list_1:
        object.undraw()

def stand():
    ret_list=[]
    circ = Circle(Point(200,400),30)
    ret_list.append(circ)

    line1 = Line(Point(200,430),Point(200,530))
    ret_list.append(line1)

    ## etc
    return ret_list

list_1 = stand()
for ctr in range(5):
    draw_1(list_1)
    time.sleep(1.5)
    undraw_1(list_1)
    time.sleep(1.5)

I like this :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.