-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
38 lines (30 loc) · 1.18 KB
/
game.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
import pygame
from typing import List
from player import Player
from settings import GAME_SCENE_WIDTH, GAME_SCENE_HEIGHT
class GameScene:
def __init__(self, players: List[Player]):
self.scene_surface = pygame.Surface((GAME_SCENE_WIDTH, GAME_SCENE_HEIGHT))
self.players = players
def update(self, dt: float):
for player in self.players:
player.update(dt)
class Scene1(GameScene):
def __init__(self, players: List[Player]):
super().__init__(players)
self.bg = pygame.Surface(self.scene_surface.get_size())
ar = pygame.PixelArray(self.bg)
maximum = self.bg.get_width() + self.bg.get_height()
for x in range(self.bg.get_width()):
for y in range(self.bg.get_height()):
c = (x + y) / maximum * 255
r, g, b = c, c, c
ar[x, y] = (r, g, b)
def update(self, dt: float):
super().update(dt)
self.scene_surface.fill("green")
self.scene_surface.blit(self.bg, (0, 0))
for player in self.players:
pygame.draw.rect(
self.scene_surface, player.color, (player.pos[0], player.pos[1], 30, 30)
)