-
Notifications
You must be signed in to change notification settings - Fork 2
/
stage.py
61 lines (45 loc) · 1.81 KB
/
stage.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
52
53
54
55
56
57
58
59
60
61
import pygame
import sys
import os
from pygame.locals import *
class Stage:
# Set up the PyGame surface
def __init__(self, caption, dimensions=None):
pygame.init()
# If no screen size is provided pick the first available mode
if dimensions == None:
dimensions = pygame.display.list_modes()[0]
pygame.display.set_mode(dimensions, FULLSCREEN)
pygame.mouse.set_visible(False)
# pygame.display.set_mode(dimensions)
pygame.display.set_caption(caption)
self.screen = pygame.display.get_surface()
self.spriteList = []
self.width = dimensions[0]
self.height = dimensions[1]
self.showBoundingBoxes = False
# Add sprite to list then draw it as a easy way to get the bounding rect
def addSprite(self, sprite):
self.spriteList.append(sprite)
sprite.boundingRect = pygame.draw.aalines(
self.screen, sprite.color, True, sprite.draw())
def removeSprite(self, sprite):
self.spriteList.remove(sprite)
def drawSprites(self):
for sprite in self.spriteList:
sprite.boundingRect = pygame.draw.aalines(
self.screen, sprite.color, True, sprite.draw())
if self.showBoundingBoxes == True:
pygame.draw.rect(self.screen, (255, 255, 255),
sprite.boundingRect, 1)
def moveSprites(self):
for sprite in self.spriteList:
sprite.move()
if sprite.position.x < 0:
sprite.position.x = self.width
if sprite.position.x > self.width:
sprite.position.x = 0
if sprite.position.y < 0:
sprite.position.y = self.height
if sprite.position.y > self.height:
sprite.position.y = 0