Example #1
0
def game_main():
    # Instantiate a canvas using the SoftwareX11 rendering engine. This
    # does all the work of creating the canvas, assigning it to the
    # rendering engine and integrating it with the `ecore' loop.
    #
    # From there onwards, the only thing left is add objects to the
    # Canvas, and manipulate these objects. The `ecore' loop will call
    # render automatically on `idle'.
    w, h   = SCREEN_SIZE
    ee     = SoftwareX11(w=w, h=h)
    canvas = ee.evas

    # Setups the game window and field by creating objects and adding
    # them to the canvas.
    setup_field(ee)

    # Sets the framerate of the game to 60FPS
    animator_frametime_set(1.0 / 60.0)

    # Finally, shows all this stuff to the user and enters the main
    # loop. From there ownards the only say we have is on the callbacks
    # from the events we've set to watch.
    ee.title = "Pong"
    ee.size_max_set(*SCREEN_SIZE)
    ee.size_min_set(*SCREEN_SIZE)

    ee.show()
    main_loop_begin()

    # Stops stuff when the game ends
    fire_hooks('the:end')
Example #2
0
    obj = ee.data["obj"]
    canvas = ee.evas
    bg.size = canvas.size
    obj.center = canvas.rect.center


if __name__ == "__main__":
    ee = ecore.evas.SoftwareX11(w=800, h=600)

    canvas = ee.evas
    bg = canvas.Rectangle(color=(255, 255, 255, 255))
    bg.size = canvas.size
    bg.show()

    obj = canvas.Image(file="icon.png")
    w, h = obj.image_size
    obj.size = (w, h)
    obj.fill = (0, 0, w, h)
    obj.center = canvas.rect.center
    obj.show()

    ee.data["bg"] = bg
    ee.data["obj"] = obj
    ee.callback_resize = resize_cb

    ecore.animator_add(animate_obj, ee, obj)

    ee.show()
    ecore.animator_frametime_set(1.0 / 60.0)
    ecore.main_loop_begin()
Example #3
0
        return True


counter2 = 0
def animator_quit_program_after_10():
    global counter2
    counter2 += 1
    print "animator_quit_program_after_10: counter=", counter2
    if counter2 == 10:
        ecore.main_loop_quit()
        return False
    else:
        return True


if __name__ == "__main__":
    # animators will run in 60 frames per second
    ecore.animator_frametime_set(1.0 / 60.0)

    ecore.animator_add(animator1, "arg1", 1234, q=890, p=567)
    ecore.animator_add(animator_run_once)
    ecore.animator_add(animator_run_once2)
    ecore.animator_add(animator_quit_program_after_10)

    # keep animator object so we can stop it from the other animator
    o = ecore.animator_add(animator2)
    ecore.animator_add(animator3, o)

    # without a main loop, animators will not work!
    ecore.main_loop_begin()