-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.py
51 lines (36 loc) · 1.47 KB
/
graphics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pygame
import random
import imageutils
class Graphics:
def __init__(self, scoreboard, timer):
self.scoreboard = scoreboard
self.timer = timer
# Create empty background
x = random.choice([1,2,3,4,6,7,9])
self.background = imageutils.load_image("BG_%s.png" % x)[0].convert()
# Create Layers
self.player_layer = pygame.sprite.RenderPlain()
self.enemy_layer = pygame.sprite.RenderPlain()
def update(self, screen, delta):
self.player_layer.update(delta)
self.enemy_layer.update(delta)
def draw(self, screen, delta):
# Background base
screen.blit(self.background, (0,0))
# Draw the Player
self.player_layer.draw(screen)
# Draw the enemies
self.enemy_layer.draw(screen)
# Draw UI
screen.blit(self.scoreboard.image, (0, 0))
screen.blit(self.timer.image, (920, 0))
def add_player_shape(self, shape):
self.player_layer.add(shape)
def remove_player_shape(self, shape):
if self.player_layer.has(shape):
self.player_layer.remove(shape)
def add_enemy_shape(self, shape):
self.enemy_layer.add(shape)
def remove_enemy_shape(self, shape):
if self.enemy_layer.has(shape):
self.enemy_layer.remove(shape)