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 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() 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 update(self): # manage forward and backward acceleration if isKeyPressed(pygame.K_w): self.speed = self.FORWARD_SPEED if isKeyPressed(pygame.K_s): self.speed = -self.BACKWARD_SPEED if (not isKeyPressed(pygame.K_w) and not isKeyPressed(pygame.K_s)): self.speed = 0 # if tank is turning right, # the way the tracks function # will move it forward a bit, # not just spin it on a dime if isKeyPressed(pygame.K_d): self.angle -= self.TURNSPEED if self.speed < 0: self.angle += self.TURNSPEED * 2 if self.speed == 0: self.speed = self.FORWARD_SPEED if isKeyPressed(pygame.K_a): self.angle += self.TURNSPEED if self.speed < 0: self.angle -= self.TURNSPEED * 2 if self.speed == 0: self.speed = self.FORWARD_SPEED # trig gives us the correct position to draw the turret self.y += self.speed * math.sin(math.radians(self.angle + 270)) self.x -= self.speed * math.cos(math.radians(self.angle + 270)) # turret moves left and right with arrow keys if isKeyPressed(pygame.K_RIGHT): self.turret_angle -= self.TURRET_TURNSPEED if isKeyPressed(pygame.K_LEFT): self.turret_angle += self.TURRET_TURNSPEED # GUN COOLDOWN if self.gun_cooldown_timer > 0: self.gun_cooldown_timer -= 1 if self.gun_cooldown_timer == 0: self.sound_finish_reload.play() # play a reloading sound self.gun_cooldown_timer = -1 # GUN BARREL BLOWBACK if self.gun_length_modifier < 0: self.gun_length_modifier += 0.5 # FIRE GUN if self.gun_shoot_delay > 0: self.gun_shoot_delay -= 1 if self.gun_shoot_delay == 0: self.gun_length_modifier = -12 self.gun_shoot_delay = -1 # TRIGGER GUN TO FIRE if isKeyJustPressed(pygame.K_SPACE): if self.gun_cooldown_timer < 1: self.gun_cooldown_timer = self.GUN_COOLDOWN self.gun_shoot_delay = 10 self.sound_shoot.play() # CLAMP TO WINDOW self.clamp()
def update(self): # manage forward and backward acceleration if isKeyPressed(pygame.K_w): self.speed = self.FORWARD_SPEED if isKeyPressed(pygame.K_s): self.speed = -self.BACKWARD_SPEED if(not isKeyPressed(pygame.K_w) and not isKeyPressed(pygame.K_s)): self.speed = 0 # if tank is turning right, # the way the tracks function # will move it forward a bit, # not just spin it on a dime if isKeyPressed(pygame.K_d): self.angle -= self.TURNSPEED if self.speed < 0: self.angle += self.TURNSPEED * 2 if self.speed == 0: self.speed = self.FORWARD_SPEED if isKeyPressed(pygame.K_a): self.angle += self.TURNSPEED if self.speed < 0: self.angle -= self.TURNSPEED * 2 if self.speed == 0: self.speed = self.FORWARD_SPEED # trig gives us the correct position to draw the turret self.y += self.speed * math.sin(math.radians(self.angle + 270)) self.x -= self.speed * math.cos(math.radians(self.angle + 270)) # turret moves left and right with arrow keys if isKeyPressed(pygame.K_RIGHT): self.turret_angle -= self.TURRET_TURNSPEED if isKeyPressed(pygame.K_LEFT): self.turret_angle += self.TURRET_TURNSPEED # GUN COOLDOWN if self.gun_cooldown_timer > 0: self.gun_cooldown_timer -= 1 if self.gun_cooldown_timer == 0: self.sound_finish_reload.play() # play a reloading sound self.gun_cooldown_timer = -1 # GUN BARREL BLOWBACK if self.gun_length_modifier < 0: self.gun_length_modifier += 0.5 # FIRE GUN if self.gun_shoot_delay > 0: self.gun_shoot_delay -= 1 if self.gun_shoot_delay == 0: self.gun_length_modifier = -12 self.gun_shoot_delay = -1 # TRIGGER GUN TO FIRE if isKeyJustPressed(pygame.K_SPACE): if self.gun_cooldown_timer < 1: self.gun_cooldown_timer = self.GUN_COOLDOWN self.gun_shoot_delay = 10 self.sound_shoot.play() # CLAMP TO WINDOW self.clamp()