Created
December 2, 2015 14:06
-
-
Save AndyNovo/83a621d45aff84702920 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import random | |
from math import sin, cos, tan, asin, acos, atan, degrees | |
from math import radians as rad | |
pygame.init() | |
resolution = (800, 600) | |
screen = pygame.display.set_mode(resolution) | |
mousepos = [0, 0] | |
swarmer = pygame.image.load("swarmer.png") | |
bwiz = pygame.image.load("bwclear1.gif") | |
class Animal: | |
def __init__(self, mousepos): | |
self.x = mousepos[0] | |
self.y = mousepos[1] | |
self.x_speed = random.randint(-3,3) | |
self.y_speed = random.randint(-3,3) | |
self.image = random.choice([swarmer, bwiz]) | |
def update(self): | |
self.x += self.x_speed | |
self.y += self.y_speed | |
def draw(self): | |
screen.blit(self.image, (self.x, self.y)) | |
clock = pygame.time.Clock() | |
s = [] | |
quit = 0 | |
font = pygame.font.Font(None, 20) | |
numbers = [] | |
for i in range(5000): | |
numbers.append(font.render(str(i), True, (0, 0, 0))) | |
while not quit: | |
for e in pygame.event.get(): | |
if e.type == pygame.KEYDOWN or e.type == pygame.QUIT: | |
quit = True | |
mousepos = pygame.mouse.get_pos() | |
screen.fill((0, 128, 255)) | |
p = pygame.mouse.get_pressed()[0] | |
if pygame.mouse.get_pressed()[2]: | |
s.append(Animal(mousepos)) | |
elif pygame.mouse.get_pressed()[1]: | |
try: | |
s.pop() | |
except: | |
pass | |
for i in s: | |
i.update() | |
i.draw() | |
screen.blit(numbers[len(s)], (10, 10)) | |
pygame.display.flip() | |
clock.tick(30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment