-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathac!red4k.py
More file actions
139 lines (115 loc) · 4.85 KB
/
ac!red4k.py
File metadata and controls
139 lines (115 loc) · 4.85 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
import pygame
import sys
# --- CONFIGURATION ---
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 576 # 4x GameBoy Resolution (160x144)
TILE_SIZE = 64 # 4x 16px tiles
FPS = 60
MOVE_SPEED = 4 # Speed of movement (pixels per frame)
# Colors (GameBoy Palette)
COLOR_DARKEST = (15, 56, 15)
COLOR_DARK = (48, 98, 48)
COLOR_LIGHT = (139, 172, 15)
COLOR_LIGHTEST = (155, 188, 15)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
# --- MAP DATA ---
# 0: Grass, 1: Wall/Bush, 2: Water, 3: Path, 4: Warp/Door
PALLET_TOWN = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 3, 3, 3, 3, 3, 3, 3, 3, 1],
[1, 3, 0, 0, 0, 0, 0, 0, 3, 1],
[1, 3, 0, 1, 1, 1, 1, 0, 3, 1],
[1, 3, 0, 1, 4, 1, 1, 0, 3, 1], # House
[1, 3, 0, 0, 0, 0, 0, 0, 3, 1],
[1, 3, 3, 3, 4, 3, 3, 3, 3, 1], # Lab
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
]
# --- CLASSES ---
class Player:
def __init__(self, x, y):
self.rect = pygame.Rect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE, TILE_SIZE)
self.color = COLOR_DARKEST
self.target_x = self.rect.x
self.target_y = self.rect.y
self.moving = False
def move(self, dx, dy, current_map):
if self.moving:
return
new_x = (self.rect.x // TILE_SIZE) + dx
new_y = (self.rect.y // TILE_SIZE) + dy
# Collision Check
if 0 <= new_y < len(current_map) and 0 <= new_x < len(current_map[0]):
if current_map[new_y][new_x] != 1: # Not a wall
self.target_x = new_x * TILE_SIZE
self.target_y = new_y * TILE_SIZE
self.moving = True
def update(self):
if self.moving:
if self.rect.x < self.target_x: self.rect.x += MOVE_SPEED
elif self.rect.x > self.target_x: self.rect.x -= MOVE_SPEED
if self.rect.y < self.target_y: self.rect.y += MOVE_SPEED
elif self.rect.y > self.target_y: self.rect.y -= MOVE_SPEED
if self.rect.x == self.target_x and self.rect.y == self.target_y:
self.moving = False
def draw(self, surface):
# Draw a simple "Red" character sprite
pygame.draw.rect(surface, self.color, self.rect)
pygame.draw.rect(surface, WHITE, (self.rect.x + 10, self.rect.y + 10, 10, 10)) # Left Eye
pygame.draw.rect(surface, WHITE, (self.rect.x + 40, self.rect.y + 10, 10, 10)) # Right Eye
class Game:
def __init__(self):
pygame.init()
self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Cat's ! Pokemon Red [MR.AC]")
self.clock = pygame.time.Clock()
self.font = pygame.font.SysFont("monospace", 20, bold=True)
self.player = Player(4, 5)
self.current_map = PALLET_TOWN
self.dialogue = "Welcome to Pallet Town!"
self.running = True
def draw_map(self):
for row_index, row in enumerate(self.current_map):
for col_index, tile in enumerate(row):
rect = pygame.Rect(col_index * TILE_SIZE, row_index * TILE_SIZE, TILE_SIZE, TILE_SIZE)
if tile == 0: color = COLOR_LIGHT # Grass
elif tile == 1: color = COLOR_DARK # Bush/Wall
elif tile == 3: color = COLOR_LIGHTEST # Path
elif tile == 4: color = (100, 100, 255) # Door
pygame.draw.rect(self.screen, color, rect)
pygame.draw.rect(self.screen, BLACK, rect, 1) # Tile borders
def draw_ui(self):
# Dialogue Box
ui_rect = pygame.Rect(10, SCREEN_HEIGHT - 100, SCREEN_WIDTH - 20, 90)
pygame.draw.rect(self.screen, WHITE, ui_rect)
pygame.draw.rect(self.screen, BLACK, ui_rect, 4)
text_surf = self.font.render(self.dialogue, True, BLACK)
self.screen.blit(text_surf, (25, SCREEN_HEIGHT - 80))
# Header Info
header_text = self.font.render("CAT'S ! RED [MR.AC] - 60 FPS", True, WHITE)
self.screen.blit(header_text, (10, 10))
def handle_input(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]: self.player.move(0, -1, self.current_map)
if keys[pygame.K_DOWN]: self.player.move(0, 1, self.current_map)
if keys[pygame.K_LEFT]: self.player.move(-1, 0, self.current_map)
if keys[pygame.K_RIGHT]: self.player.move(1, 0, self.current_map)
def run(self):
while self.running:
self.handle_input()
self.player.update()
# Rendering
self.screen.fill(COLOR_DARK)
self.draw_map()
self.player.draw(self.screen)
self.draw_ui()
pygame.display.flip()
self.clock.tick(FPS)
pygame.quit()
sys.exit()
if __name__ == "__main__":
game = Game()
game.run()