Last active
May 8, 2017 17:03
-
-
Save Mekire/36831ce1ca36a6d814126fe43fb56115 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 os | |
import sys | |
import random | |
import pygame as pg | |
class _BaseSprite(pg.sprite.Sprite): | |
def __init__(self, color, pos, size, *groups): | |
super(_BaseSprite, self).__init__(*groups) | |
self.image = pg.Surface(size).convert() | |
self.image.fill(color) | |
self.rect = self.image.get_rect(topleft=pos) | |
class Zombie(_BaseSprite): | |
""" | |
This class represents the zombie | |
""" | |
SIZE = (20, 15) | |
COLOR = pg.Color("green") | |
def __init__(self, pos, *groups): | |
super(Zombie, self).__init__(self.COLOR, pos, self.SIZE, *groups) | |
class Player(_BaseSprite): | |
SIZE = (20, 15) | |
COLOR = pg.Color("red") | |
def __init__(self, pos, *groups): | |
super(Player, self).__init__(self.COLOR, pos, self.SIZE, *groups) | |
self.speed = 5 | |
self.damage = 5 | |
self.health = 10 | |
self.inv_space = 2 | |
pg.init() | |
screenWidth = 600 | |
screenHeight = 600 | |
screen = pg.display.set_mode([screenWidth, screenHeight]) | |
screen_rect = screen.get_rect() | |
block_list = pg.sprite.Group() | |
all_sprites_list = pg.sprite.Group() | |
for i in range(10): | |
pos = random.randrange(screenWidth), random.randrange(screenHeight) | |
Zombie(pos, block_list, all_sprites_list) | |
player = Player(screen_rect.center, all_sprites_list) | |
done = False | |
clock = pg.time.Clock() | |
while not done: | |
for event in pg.event.get(): | |
if event.type == pg.QUIT: | |
done = True | |
screen.fill(pg.Color("white")) | |
pos = pg.mouse.get_pos() | |
all_sprites_list.draw(screen) | |
pg.display.flip() | |
clock.tick(60) | |
pg.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment