-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprites_and_images.py
103 lines (71 loc) · 2.57 KB
/
sprites_and_images.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pygame
from abc import ABC, abstractmethod
sprite_sheet_image = pygame.image.load("smg_spritesheet.png")
sprite_bg_color = (51, 0, 51)
class Actor(ABC):
def __init__(self, width, height, pos_x, pos_y, scale=1, color=sprite_bg_color):
self.sprite = pygame.Surface((width, height)).convert_alpha()
self.sprite.blit(sprite_sheet_image, (0, 0), (pos_x, pos_y, width, height))
self.sprite = pygame.transform.scale(
self.sprite, (width * scale, height * scale)
)
self.sprite.set_colorkey(color)
def get_resting_state(self) -> pygame.Surface:
return self.sprite
class Squid(Actor):
width = 16
height = 16
def __init__(self):
self.sprite_states: list[pygame.Surface] = []
calc_width = lambda sprite_num: (2 * (sprite_num + 1)) + (
Squid.width * sprite_num
)
for s in range(7):
sprite = pygame.Surface((Squid.width, Squid.height)).convert_alpha()
sprite.blit(sprite_sheet_image, (0, 0), (2, 2, calc_width(s), Squid.height))
self.sprite_states.append(sprite)
def get_resting_state(self):
return self.sprite_states[0]
class Zapfish(Actor):
width = 16
height = 16
def __init__(self):
super().__init__(Zapfish.width, Zapfish.height, 20, 22)
class Crab(Actor):
width = 16
height = 16
def __init__(self):
super().__init__(Crab.width, Crab.height, 38, 22)
class Starfish(Actor):
width = 16
height = 16
def __init__(self):
super().__init__(Starfish.width, Starfish.height, 56, 22)
class Jellyfish(Actor):
width = 16
height = 16
def __init__(self):
super().__init__(Jellyfish.width, Jellyfish.height, 74, 22)
class GreenFish(Actor):
width = 16
height = 16
def __init__(self):
super().__init__(GreenFish.width, GreenFish.height, 92, 22)
class RedFish(Actor):
width = 16
height = 16
def __init__(self):
super().__init__(RedFish.width, RedFish.height, 128, 22)
class Background:
sprite_width = 240
sprite_height = 240
def __init__(self, screen_width: int, screen_height: int):
self.background = pygame.Surface((Background.sprite_width, Background.sprite_height))
self.background.blit(
sprite_sheet_image,
(0, 0),
(2, 126, Background.sprite_width, Background.sprite_height),
)
self.background = pygame.transform.scale(self.background, (screen_width, screen_height))
def get_background(self) -> pygame.Surface:
return self.background