Exemple #1
0
            if event.key == pg.K_ESCAPE:
                running = False
            elif event.key == pg.K_LEFT:
                sprite.rect.x -= 5
            elif event.key == pg.K_RIGHT:
                sprite.rect.x += 5
            elif event.key == pg.K_DOWN:
                sprite.rect.y += 5
            elif event.key == pg.K_UP:
                sprite.rect.y -= 5

    renderer.clear()
    t += 1

    img = sprite.image
    img.angle += 1
    img.flip_x = t % 50 < 25
    img.flip_y = t % 100 < 50
    img.color[0] = int(255.0 * (0.5 + math.sin(0.5 * t + 10.0) / 2.0))
    img.alpha = int(255.0 * (0.5 + math.sin(0.1 * t) / 2.0))
    # img.draw(dstrect=(x, y, 5 * img.srcrect['w'], 5 * img.srcrect['h']))

    group.draw(renderer)

    renderer.present()

    clock.tick(60)
    win.title = str("FPS: {}".format(clock.get_fps()))

pg.quit()
Exemple #2
0
               event.type == pygame.WINDOWEVENT and event.event == pygame.WINDOWEVENT_CLOSE:
                win2.destroy()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                running = False
            elif event.key == pygame.K_LEFT:
                x -= 5
            elif event.key == pygame.K_RIGHT:
                x += 5
            elif event.key == pygame.K_DOWN:
                y += 5
            elif event.key == pygame.K_UP:
                y -= 5
            elif event.key == pygame.K_f:
                if full == 0:
                    win.set_fullscreen(True)
                    full = 1
                else:
                    win.set_windowed()
                    full = 0
            elif event.key == pygame.K_SPACE:
                bg_index = (bg_index + 1) % len(backgrounds)
                renderer.draw_color = backgrounds[bg_index]

    renderer.clear()
    renderer.copy_pos(tex, x, y)
    renderer.present()

    clock.tick(60)
    win.title = str('FPS: {}'.format(clock.get_fps()))
Exemple #3
0
            if event.key == pg.K_ESCAPE:
                running = False
            elif event.key == pg.K_LEFT:
                sprite.rect.x -= 5
            elif event.key == pg.K_RIGHT:
                sprite.rect.x += 5
            elif event.key == pg.K_DOWN:
                sprite.rect.y += 5
            elif event.key == pg.K_UP:
                sprite.rect.y -= 5

    renderer.clear()
    t += 1

    img = sprite.image
    img.angle += 1
    img.flip_x = t % 50 < 25
    img.flip_y = t % 100 < 50
    img.color[0] = int(255.0 * (0.5 + math.sin(0.5 * t + 10.0) / 2.0))
    img.alpha = int(255.0 * (0.5 + math.sin(0.1 * t) / 2.0))
    # img.draw(dstrect=(x, y, 5 * img.srcrect['w'], 5 * img.srcrect['h']))

    group.draw(renderer)

    renderer.present()

    clock.tick(60)
    win.title = str(f"FPS: {clock.get_fps()}")

pg.quit()