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
|
import os
import pygame
from random import randrange
from display import Scaling
from text import Fonts
DEBUG = os.getenv("DEBUG")
class PlayerSprite(pygame.sprite.Sprite):
def __init__(self, image):
super().__init__()
self.image = image
self.rect = self.image.get_rect()
def update(self, pos = None, **kwargs):
if pos:
w, h = self.image.get_size()
self.rect = self.image.get_rect().move(pos[0]-w//2,pos[1]-h//2)
class Player(pygame.sprite.LayeredUpdates):
def __init__(self):
super().__init__()
self.position = (0,0)
self.direction = False
self.lazer = False
image = pygame.Surface((8,26), pygame.SRCALPHA)
for color, y, ch in (
("red",0,0x18),
("red",13,0x19),
("blue",6,0x09)):
ch = Fonts.fonts['standard'].get(ch)
ch.fill( color, special_flags = pygame.BLEND_RGBA_MULT)
image.blit(ch,(0,y))
image = pygame.transform.scale_by(image, 1_200 * Scaling.factor)
self.add(PlayerSprite(image), layer = 0)
image = pygame.transform.rotate(image, 90)
self.add(PlayerSprite(image), layer = 1)
def update(self, pos = None, direction = False, **kwargs):
if self.lazer:
direction = False
pos = None
super().update(pos = pos, **kwargs)
if direction:
self.direction = not self.direction
self.switch_layer(0,1)
if pos:
self.position = Scaling.scale_to_internal(pos)
|