Exemple #1
0
def main():

    pygame.init()
    globals.pygame = pygame
    update_display_mode()
    clock = pygame.time.Clock()

    entities = []

    entities.append(Tank(100, 100))

    loop = True

    while(loop):
        clock.tick(60)  # 60 FPS
        globals.window.fill((255, 255, 255))  # Fill window white

        globals.events = pygame.event.get()

        for entitiy in entities:
            entitiy.update()

        for entitiy in entities:
            entitiy.draw()

        if isKeyJustPressed(pygame.K_RETURN):
            toggle_fullscreen()

        if isKeyJustPressed(pygame.K_ESCAPE):
            globals.pygame.quit()
            loop = False

        # Flip the buffer
        pygame.display.flip()
def main():

	pygame.init()
	globals.pygame = pygame # assign global pygame for other modules to reference
	globals.inputs = Inputs(pygame) # assign global inputs for other modules to reference
	update_display_mode() # now that the global display properties have been set up, update the display
	clock = pygame.time.Clock() # clock to tick / manage delta

	entities = [] # contains every object that will be drawn in the game

	entities.append(Entity()) # our testing entity will be the default entity

	loop = True # for controlling the game loop

	while(loop):
		clock.tick(60) # tick the clock with a target 60 fps
		globals.window.fill((255, 255, 255))

		globals.inputs.update() # refresh inputs

		update(entities) # update all entities
		render(entities) # draw all entities

		if(globals.inputs.isKeyDown("space")): toggle_fullscreen() # space bar toggles fullscreen
		if(globals.inputs.isKeyDown("escape")): loop = False # escape key exits game
		if(globals.inputs.isQuitPressed()): loop = False # red 'x' button exits game

		pygame.display.flip() # flip the display, which finally shows our render

	pygame.quit() # unload pygame modules
Exemple #3
0
def main():

    pygame.init()
    globals.pygame = pygame
    update_display_mode()
    clock = pygame.time.Clock()

    entities = []

    entities.append(Tank(100, 100))

    loop = True

    while (loop):
        clock.tick(60)  # 60 FPS
        globals.window.fill((255, 255, 255))  # Fill window white

        globals.events = pygame.event.get()

        for entitiy in entities:
            entitiy.update()

        for entitiy in entities:
            entitiy.draw()

        if isKeyJustPressed(pygame.K_RETURN):
            toggle_fullscreen()

        if isKeyJustPressed(pygame.K_ESCAPE):
            globals.pygame.quit()
            loop = False

        # Flip the buffer
        pygame.display.flip()
Exemple #4
0
def main():

    # Initialize pygame
    pygame.init()
    pygame.mixer.init()
    clock = pygame.time.Clock()
    globals.window = pygame.display.set_mode((globals.WIDTH, globals.HEIGHT), False)

    sound_correct = pygame.mixer.Sound("res/correct.wav")
    sound_incorrect = pygame.mixer.Sound("res/incorrect.wav")

    load_cards()
    loop = True
    timer = 1
    space_pressed = False
    score = 0

    while(loop):

        clock.tick(60)

        timer += 1
        if timer >= 50:
            timer = 0
            new_card()
            space_pressed = False

        # Check if the escape key has been pressed
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:

                if event.key == pygame.K_SPACE:
                    if(is_double_or_sandwich(cards) and not space_pressed):
                        score += 1
                        print("Correct: Score is " + str(score))
                        space_pressed = True
                        sound_correct.play()
                    elif(not space_pressed):
                        score -= 1
                        print("Incorrect: Score is " + str(score))
                        space_pressed = True
                        sound_incorrect.play()

                if event.key == pygame.K_RETURN:
                    toggle_fullscreen()

                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    quit()

        pygame.display.flip()
Exemple #5
0
def main():

    pygame.init()
    update_display_mode()
    clock = pygame.time.Clock()

    entities = []
    for i in range(1000):
        entities.append(
            Ball(globals.width / 2, globals.height / 2,
                 numpy.random.normal(-10, 10), numpy.random.normal(-10, 10),
                 (random.randint(0, 255), random.randint(
                     0, 255), random.randint(0, 255))))

    running = True

    globals.window.fill((255, 255, 255))

    while (running):

        # Set FPS limit
        clock.tick(globals.fps)

        # Fill window white
        globals.window.fill((255, 255, 255))

        globals.events = pygame.event.get()

        for entitiy in entities:
            entitiy.update()

        for entitiy in entities:
            entitiy.draw()

        if isKeyJustPressed(pygame.K_RETURN):
            toggle_fullscreen()

        if isKeyJustPressed(pygame.K_ESCAPE):
            globals.pygame.quit()
            loop = False

        # Flip the buffer
        pygame.display.flip()
def main():

    pygame.init()
    globals.pygame = pygame  # assign global pygame for other modules to reference
    globals.inputs = Inputs(
        pygame)  # assign global inputs for other modules to reference
    update_display_mode(
    )  # now that the global display properties have been set up, update the display
    clock = pygame.time.Clock()  # clock to tick / manage delta

    entities = []  # contains every object that will be drawn in the game

    entities.append(Entity())  # our testing entity will be the default entity

    loop = True  # for controlling the game loop

    while (loop):
        clock.tick(60)  # tick the clock with a target 60 fps
        globals.window.fill((255, 255, 255))

        globals.inputs.update()  # refresh inputs

        update(entities)  # update all entities
        render(entities)  # draw all entities

        if (globals.inputs.isKeyDown("space")):
            toggle_fullscreen()  # space bar toggles fullscreen
        if (globals.inputs.isKeyDown("escape")):
            loop = False  # escape key exits game
        if (globals.inputs.isQuitPressed()):
            loop = False  # red 'x' button exits game

        pygame.display.flip(
        )  # flip the display, which finally shows our render

    pygame.quit()  # unload pygame modules
Exemple #7
0
    def __init__(self):
        super().__init__()
        self.back_btn = gui.Button(_("Go Back"), f.MAIN, callback=lambda *_: setattr(self, 'done', True), layout_gravity=gui.Gravity.BOTTOMRIGHT)
        self.fullscreen_btn = gui.CheckBox(_("Toggle Fullscreen"), f.MAIN, callback=lambda *_: display.toggle_fullscreen(), padding=25)

        def res_setter(res):
            return lambda *_: display.set_resolution(res)
        resolutions = [("{0[0]}x{0[1]}".format(res), res_setter(res)) for res in pygame.display.list_modes()]
        self.resolutions_menu = gui.Menu(resolutions, f.MAIN, die_when_done=False)
        self.add_children(self.back_btn, self.fullscreen_btn, self.resolutions_menu)