How to use the pygame.time function in pygame

To help you get started, we’ve selected a few pygame examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github horstjens / feuerwerk / frictiongame.py View on Github external
def __init__(self, width=640, height=400, fps=30, friction=0.995, gametime=120.0):
        """Initialize pygame, window, background, font,...
           default arguments """
        pygame.init()
        PygView.width = width    # make global readable
        PygView.height = height
        self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
        self.background = pygame.Surface(self.screen.get_size()).convert()  
        self.background.fill((255,255,255)) # fill background white
        self.clock = pygame.time.Clock()
        self.fps = fps
        PygView.friction = friction
        self.playtime = 0.0
        self.gametime = gametime
        self.paint()
github lucasmedeiros / pygame-minicurso / game_example.py View on Github external
def __init__(self):
        pygame.init()
        pygame.mixer.init()

        self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
        pygame.display.set_caption(GAME_NAME)

        self.running = True
        self.win = False

        self.all_sprites = pygame.sprite.Group()

        self.clock = pygame.time.Clock()
github Revolutionary-Games / thrive-prototypes / tectonics / tectonics_DEC_2015.py View on Github external
import math
import random
from pygame.locals import *

#pygame setup
background_colour = (255,255,255)
(width, height) = (700, 700)

screen = pygame.display.set_mode((width, height))#,pygame.FULLSCREEN)
screen.fill(background_colour)
pygame.display.set_caption('Collisions on a Sphere')
pygame.font.init()

myfont = pygame.font.SysFont("monospace", 20)

clock = pygame.time.Clock()

#distance in space between two points, not distance on a sphere
def euclidean_distance(quat1, quat2):
	return math.sqrt((quat1[0] - quat2[0])**2 +
					(quat1[1] - quat2[1])**2 + 
					(quat1[2] - quat2[2])**2 + 
					(quat1[3] - quat2[3])**2)

#the size of a quaternion
def norm(quat):
	return euclidean_distance([0,0,0,0], quat)

#make a quaternion unit size
def normalise(quat):
	this_norm = norm(quat)
	if this_norm == 0:
github alejolp / grounded / grounded-py / grounded.py View on Github external
elif e.type == (USEREVENT + 0):
                MAP.on_timer()

        MAP.update()
        jugador.update()

        # Move

        jugador.move(teclas)

        # Draw

        MAP.draw(screen)
        jugador.draw(screen)

        if pygame.time.get_ticks() - start_t < 10000:
            for tt, ttp in zip(ftext, ftextpos):
                screen.blit(tt, ttp)

        pygame.display.flip()
        clock.tick(GAME_FPS)

    pygame.quit()
github kidscancode / gamedev / tutorials / shmup / shmup-5.py View on Github external
FPS = 60

# define colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)

# initialize pygame and create window
pygame.init()
pygame.mixer.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Shmup!")
clock = pygame.time.Clock()

class Player(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.transform.scale(player_img, (50, 38))
        self.image.set_colorkey(BLACK)
        self.rect = self.image.get_rect()
        self.radius = 20
        # pygame.draw.circle(self.image, RED, self.rect.center, self.radius)
        self.rect.centerx = WIDTH / 2
        self.rect.bottom = HEIGHT - 10
        self.speedx = 0

    def update(self):
        self.speedx = 0
        keystate = pygame.key.get_pressed()
github Teifion / RuneTD / engine / engine.py View on Github external
def update_window(self):
        self.sprites.update(pygame.time.get_ticks())
        rectlist = self.sprites.draw(self.screen)
        pygame.display.update(rectlist)
        pygame.time.delay(10)
        pygame.display.flip()
        self.sprites.clear(self.screen, self.background)
github krother / maze_run / leftovers / replay.py View on Github external
repeat_key = None
                pygame.time.set_timer(KEY_REPEATED, 0)
        elif event.type == KEY_REPEATED:
            handle_key(repeat_key)
        elif event.type == DRAW:
            draw()
        elif event.type == UPDATE:
            update()
        elif event.type == MOVE_GHOST:
            move_ghost()
        elif event.type == EXIT:
            running = False
            eventlog.critical('exit event received: ' + str(event))
        else:
            eventlog.info('unhandled event: ' + str(event))
        pygame.time.delay(delay)
github Mekire / pygame-samples / platforming / fall_mask.py View on Github external
def physics_update(self):
        """If the player is falling, calculate current y velocity."""
        if self.fall:
            time_now = pg.time.get_ticks()
            if not self.time:
                self.time = time_now
            self.y_vel = self.grav*((time_now-self.time)/1000.0)+self.y_vel_i
        else:
            self.time = None
            self.y_vel = self.y_vel_i = 0
github aalex / toonloop / toonloop.py View on Github external
def __init__(self, **argd):
        """
        Startup poutine.
        """
        self.config = Configuration(**argd)
        self.api = Api(self)
        # size of the rendering window
        self._display_size = (self.config.display_width, self.config.display_height)
        self.running = True
        self.paused = False
        self.image_size = (self.config.image_width, self.config.image_height)
        self.clock = pygame.time.Clock()
        self.fps = 0 # for statistics
        #self.images_list = [] # only editing one shot for now
        #self.shot.playhead = 0 
        self.shot_id = 0 # Currently selected shot
        self.shot = None # current ToonShot instance
        self.shots = [] # ToonShot instances
        self._init_shots()
        self.renderer = None # Renderer instance that owns it.
        self._intervalometer_delayed_id = None
        # the pygame window
        self.display = pygame.display.set_mode(self._display_size, OPENGL | DOUBLEBUF | HWSURFACE)
        pygame.display.set_caption("ToonLoop")
        pygame.mouse.set_visible(False)
        # the images
        self.most_recent_image = pygame.surface.Surface(self.image_size) # , 0, self.display)
github ActiveState / neuroblast / gameover.py View on Github external
def enter_text(eq, screen, max_length, lower = False, upper = False, title = False):
    global pressed
    BLUE = (0,0,255)
    allowed_values = [i for i in range(97, 123)] +\
                     [i for i in range(48,58)]

    BLINK_EVENT = pygame.USEREVENT + 0
    pygame.time.set_timer(BLINK_EVENT, 800)
    blinky = cycle(["_", " "])
    next_blink = next(blinky)
    displaytext('GAME OVER', 16, 320,60, WHITE, screen)        

    displaytext('Enter your name:', 16, 320,125, WHITE, screen)        

    for event in eq:
        if event.type == BLINK_EVENT:
            next_blink = next(blinky)
        # if input is in list of allowed characters, add to variable
        elif event.type == KEYUP and event.key in allowed_values \
            and len(pressed) < max_length:
            # caps entry?
            if pygame.key.get_mods() & KMOD_SHIFT or pygame.key.get_mods()\
                & KMOD_CAPS:
                pressed += chr(event.key).upper()