-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_character_sprites.py
More file actions
195 lines (156 loc) · 8.76 KB
/
create_character_sprites.py
File metadata and controls
195 lines (156 loc) · 8.76 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import os
import pygame
import sys
# Initialize pygame
pygame.init()
# Constants
TILE_SIZE = 40
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
# Create directories if they don't exist
os.makedirs("assets/images", exist_ok=True)
# Character types to create
character_types = ["default", "mario", "ninja", "robot"]
# Function to create a character sprite sheet
def create_character_sprite_sheet(character_type):
dimensions = ["normal", "inverse", "ethereal", "time", "magnetic"]
states = ["idle", "run", "jump", "fall"]
# Colors for each dimension
dimension_colors = {
"normal": (0, 0, 255), # Blue
"inverse": (255, 0, 0), # Red
"ethereal": (128, 0, 128), # Purple
"time": (255, 255, 0), # Yellow
"magnetic": (0, 255, 255) # Cyan
}
# Character-specific colors
character_colors = {
"default": (100, 100, 100),
"mario": (255, 0, 0),
"ninja": (50, 50, 50),
"robot": (192, 192, 192)
}
# Create a sprite sheet with 4 frames for each state and dimension
sheet_width = 4 * TILE_SIZE
sheet_height = len(states) * len(dimensions) * TILE_SIZE
sheet = pygame.Surface((sheet_width, sheet_height), pygame.SRCALPHA)
for state_idx, state in enumerate(states):
for dim_idx, dimension in enumerate(dimensions):
for frame in range(4):
# Create a frame surface
surf = pygame.Surface((TILE_SIZE-4, TILE_SIZE-4), pygame.SRCALPHA)
# Base color combines character and dimension
base_color = character_colors.get(character_type, (100, 100, 100))
dim_color = dimension_colors.get(dimension, (255, 255, 255))
# Mix the colors
mixed_color = (
(base_color[0] + dim_color[0]) // 2,
(base_color[1] + dim_color[1]) // 2,
(base_color[2] + dim_color[2]) // 2
)
# Draw the character
if character_type == "default":
# Simple rectangle character
pygame.draw.rect(surf, mixed_color, (0, 0, TILE_SIZE-4, TILE_SIZE-4))
# Add details based on state
if state == "idle":
# Eyes
if frame == 2: # Blink on frame 2
pygame.draw.rect(surf, (255, 255, 255), ((TILE_SIZE-4)//4, (TILE_SIZE-4)//4, 2, 2))
pygame.draw.rect(surf, (255, 255, 255), (3*(TILE_SIZE-4)//4, (TILE_SIZE-4)//4, 2, 2))
else:
pygame.draw.rect(surf, (255, 255, 255), ((TILE_SIZE-4)//4, (TILE_SIZE-4)//4, 4, 4))
pygame.draw.rect(surf, (255, 255, 255), (3*(TILE_SIZE-4)//4, (TILE_SIZE-4)//4, 4, 4))
elif state == "run":
# Running legs
leg_height = (TILE_SIZE-4) // 3
leg_offset = (frame % 2) * 4 - 2
pygame.draw.rect(surf, (0, 0, 0), ((TILE_SIZE-4)//4, (TILE_SIZE-4)-leg_height+leg_offset, 4, leg_height))
pygame.draw.rect(surf, (0, 0, 0), (3*(TILE_SIZE-4)//4, (TILE_SIZE-4)-leg_height-leg_offset, 4, leg_height))
elif state == "jump":
# Jumping pose
pygame.draw.ellipse(surf, (0, 0, 0), ((TILE_SIZE-4)//4, (TILE_SIZE-4)-10, (TILE_SIZE-4)//2, 8))
elif state == "fall":
# Falling pose
pygame.draw.ellipse(surf, (0, 0, 0), ((TILE_SIZE-4)//4, (TILE_SIZE-4)-6, (TILE_SIZE-4)//2, 4))
elif character_type == "mario":
# Mario-style character
# Body
pygame.draw.rect(surf, (255, 0, 0), (0, 0, TILE_SIZE-4, TILE_SIZE-4))
# Face
pygame.draw.rect(surf, (255, 200, 150), (4, 4, TILE_SIZE-12, TILE_SIZE-12))
# Hat
pygame.draw.rect(surf, (255, 0, 0), (2, 2, TILE_SIZE-8, 8))
# Eyes
pygame.draw.rect(surf, (0, 0, 0), (8, 10, 4, 4))
# Mustache
pygame.draw.rect(surf, (0, 0, 0), (6, 16, 12, 4))
if state == "run":
# Running legs
leg_height = (TILE_SIZE-4) // 3
leg_offset = (frame % 2) * 4 - 2
pygame.draw.rect(surf, (0, 0, 255), ((TILE_SIZE-4)//4, (TILE_SIZE-4)-leg_height+leg_offset, 8, leg_height))
elif state == "jump":
# Jumping pose
pygame.draw.rect(surf, (0, 0, 255), ((TILE_SIZE-4)//4, (TILE_SIZE-4)-12, 8, 12))
elif character_type == "ninja":
# Ninja character
# Body
pygame.draw.rect(surf, (50, 50, 50), (0, 0, TILE_SIZE-4, TILE_SIZE-4))
# Mask
pygame.draw.rect(surf, (0, 0, 0), (4, 4, TILE_SIZE-12, 10))
# Eyes
pygame.draw.rect(surf, (255, 255, 255), (8, 8, 4, 4))
pygame.draw.rect(surf, (255, 255, 255), (18, 8, 4, 4))
if state == "run":
# Running animation
if frame % 2 == 0:
# Running pose 1
pygame.draw.line(surf, (100, 100, 100), (8, 20), (16, 30), 2)
pygame.draw.line(surf, (100, 100, 100), (24, 20), (16, 30), 2)
else:
# Running pose 2
pygame.draw.line(surf, (100, 100, 100), (8, 30), (16, 20), 2)
pygame.draw.line(surf, (100, 100, 100), (24, 30), (16, 20), 2)
elif state == "jump":
# Jumping pose
pygame.draw.line(surf, (100, 100, 100), (8, 25), (16, 20), 2)
pygame.draw.line(surf, (100, 100, 100), (24, 25), (16, 20), 2)
elif character_type == "robot":
# Robot character
# Body
pygame.draw.rect(surf, (192, 192, 192), (0, 0, TILE_SIZE-4, TILE_SIZE-4))
# Face plate
pygame.draw.rect(surf, (100, 100, 100), (4, 4, TILE_SIZE-12, TILE_SIZE-12))
# Eyes
if frame % 3 == 0: # Blinking effect
pygame.draw.rect(surf, (255, 0, 0), (8, 8, 4, 2))
pygame.draw.rect(surf, (255, 0, 0), (18, 8, 4, 2))
else:
pygame.draw.rect(surf, (255, 0, 0), (8, 8, 4, 4))
pygame.draw.rect(surf, (255, 0, 0), (18, 8, 4, 4))
# Mouth
pygame.draw.rect(surf, (50, 50, 50), (10, 18, 10, 2))
if state == "run":
# Robot walking
leg_height = (TILE_SIZE-4) // 3
if frame % 2 == 0:
pygame.draw.rect(surf, (100, 100, 100), (8, (TILE_SIZE-4)-leg_height, 4, leg_height))
pygame.draw.rect(surf, (100, 100, 100), (20, (TILE_SIZE-4)-leg_height+4, 4, leg_height-4))
else:
pygame.draw.rect(surf, (100, 100, 100), (8, (TILE_SIZE-4)-leg_height+4, 4, leg_height-4))
pygame.draw.rect(surf, (100, 100, 100), (20, (TILE_SIZE-4)-leg_height, 4, leg_height))
# Position in sprite sheet
x = frame * TILE_SIZE
y = (state_idx * len(dimensions) + dim_idx) * TILE_SIZE
# Draw to sprite sheet
sheet.blit(surf, (x + 2, y + 2)) # +2 for centering in tile
return sheet
# Create character sprite sheets
print("Creating character sprite sheets...")
for character in character_types:
sprite_sheet = create_character_sprite_sheet(character)
pygame.image.save(sprite_sheet, f"assets/images/{character}.png")
print(f"Created assets/images/{character}.png")
print("\nAll character sprite sheets have been created!")
print("You can now select these characters in the game.")