Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pygame.locals import *
- import sys, os, traceback
- if sys.platform in ["win32","win64"]: os.environ["SDL_VIDEO_CENTERED"]="1"
- pygame.display.init()
- pygame.font.init()
- screen_size = [800,600]
- icon = pygame.Surface((1,1)); icon.set_alpha(0); pygame.display.set_icon(icon)
- pygame.display.set_caption("Event Timer Sample - Ian Mallett - 2018")
- surface = pygame.display.set_mode(screen_size)
- cooldown = 0.0
- class Bullet(object):
- def __init__(self,x,y,t):
- self.x=x; self.y=y; self.t=t
- bullets = []
- def get_input():
- global cooldown
- keys_pressed = pygame.key.get_pressed()
- mouse_buttons = pygame.mouse.get_pressed()
- mouse_position = pygame.mouse.get_pos()
- mouse_rel = pygame.mouse.get_rel()
- for event in pygame.event.get():
- if event.type == QUIT: return False
- elif event.type == KEYDOWN:
- if event.key == K_ESCAPE: return False
- if keys_pressed[K_RETURN] and cooldown==0.0:
- cooldown = 0.2
- bullets.append(Bullet(400,300, 0))
- return True
- def update(dt):
- global cooldown, bullets
- if cooldown > 0.0:
- cooldown -= dt
- else:
- cooldown = 0.0
- for bullet in bullets:
- bullet.x += 5
- bullet.t += dt
- bullets = [
- bullet for bullet in bullets if bullet.t<1.0
- ]
- def draw():
- surface.fill((255,255,255))
- for bullet in bullets:
- pygame.draw.circle(surface,(255,0,0),(bullet.x,bullet.y),5,0)
- pygame.display.flip()
- def main():
- clock = pygame.time.Clock()
- while True:
- if not get_input(): break
- update(1.0/60.0)
- draw()
- clock.tick(60)
- pygame.quit()
- if __name__ == "__main__":
- try:
- main()
- except:
- traceback.print_exc()
- pygame.quit()
- input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement