File size: 6,431 Bytes
e5ddb64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pygame
import json
import time
import math

# --- Configuration ---
WIDTH, HEIGHT = 800, 600
FPS = 60
WHITE = (255, 255, 255)
CYAN = (0, 255, 204)
PINK = (255, 0, 85)
GOLD = (255, 215, 0)
BLACK = (5, 5, 5)

pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()
font = pygame.font.SysFont("Courier New", 18, bold=True)

# --- Game State ---
class GameState:
    def __init__(self):
        self.current_level = 0
        self.jumps = 0
        self.pb = self.load_pb()
        self.editing = False
        self.loading = False
        self.levels = self.load_levels()
        self.reset_player()

    def reset_player(self):
        self.px, self.py = 50, 500
        self.vx, self.vy = 0, 0
        self.grounded = False

    def load_pb(self):
        try:
            with open("pb.txt", "r") as f: return int(f.read())
        except: return float('inf')

    def save_pb(self):
        if self.jumps < self.pb:
            with open("pb.txt", "w") as f: f.write(str(self.jumps))
            self.pb = self.jumps

    def load_levels(self):
        try:
            with open("levels.json", "r") as f: return json.load(f)
        except:
            # Default Level 1
            return [[{"rect": [0, 550, 200, 20], "type": "normal"}, 
                     {"rect": [720, 100, 50, 50], "type": "goal"}]]

    def save_levels(self):
        with open("levels.json", "w") as f: json.dump(self.levels, f)

state = GameState()

# --- 4D Tesseract Loading Screen ---
def draw_tesseract_loader():
    start_time = time.time()
    angle = 0
    while time.time() - start_time < 3:
        screen.fill(BLACK)
        angle += 0.05
        center = (WIDTH // 2, HEIGHT // 2)
        
        # Draw projection
        s1 = 40 + math.sin(angle) * 10
        s2 = 80
        
        for s in [s1, s2]:
            pts = [
                (center[0]-s, center[1]-s), (center[0]+s, center[1]-s),
                (center[0]+s, center[1]+s), (center[0]-s, center[1]+s)
            ]
            pygame.draw.lines(screen, CYAN, True, pts, 2)
            
        # Connecting lines
        for i in [-1, 1]:
            for j in [-1, 1]:
                pygame.draw.line(screen, CYAN, (center[0]+i*s1, center[1]+j*s1), (center[0]+i*s2, center[1]+j*s2), 1)

        txt = font.render("STABILIZING DIMENSIONS...", True, CYAN)
        screen.blit(txt, (WIDTH//2 - 120, HEIGHT//2 + 120))
        pygame.display.flip()
        clock.tick(FPS)

# --- Main Loop ---
running = True
new_plat_start = None
current_type = "normal"

while running:
    screen.fill(BLACK)
    dt = clock.tick(FPS)
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        
        # Editor Controls
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_e: state.editing = not state.editing
            if event.key == pygame.K_s and state.editing: state.save_levels()
            if event.key == pygame.K_n and state.editing: # New Level
                state.levels.append([{"rect": [0, 550, 200, 20], "type": "normal"}])
                state.current_level = len(state.levels) - 1
        
        if state.editing:
            if event.type == pygame.MOUSEBUTTONDOWN:
                if event.button == 1: new_plat_start = event.pos
                if event.button == 3: # Right click cycle type
                    types = ["normal", "bouncy", "goal"]
                    current_type = types[(types.index(current_type) + 1) % 3]
            if event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                end_x, end_y = event.pos
                x, y = min(new_plat_start[0], end_x), min(new_plat_start[1], end_y)
                w, h = abs(new_plat_start[0] - end_x), abs(new_plat_start[1] - end_y)
                state.levels[state.current_level].append({"rect": [x, y, w, h], "type": current_type})
                new_plat_start = None

    if not state.editing:
        # Physics
        keys = pygame.key.get_pressed()
        if keys[pygame.K_a] or keys[pygame.K_LEFT]: state.vx -= 0.8
        if keys[pygame.K_d] or keys[pygame.K_RIGHT]: state.vx += 0.8
        if (keys[pygame.K_SPACE] or keys[pygame.K_UP] or keys[pygame.K_w]) and state.grounded:
            state.vy = -11
            state.jumps += 1
            state.grounded = False

        state.vy += 0.5 # Gravity
        state.vx *= 0.85 # Friction
        state.px += state.vx
        state.py += state.vy

        # Screen Wrap
        if state.px < 0: state.px = WIDTH
        if state.px > WIDTH: state.px = 0
        if state.py > HEIGHT: state.reset_player()

        # Collisions
        state.grounded = False
        for p in state.levels[state.current_level]:
            r = pygame.Rect(p["rect"])
            player_rect = pygame.Rect(state.px - 10, state.py - 10, 20, 20)
            if player_rect.colliderect(r):
                if p["type"] == "goal":
                    state.save_pb()
                    if state.current_level < len(state.levels) - 1:
                        state.current_level += 1
                        draw_tesseract_loader()
                        state.reset_player()
                    else:
                        print("All Levels Clear!")
                        running = False
                elif state.vy > 0 and state.py < r.top + 10:
                    state.py = r.top - 10
                    state.vy *= -1.4 if p["type"] == "bouncy" else -0.5
                    if abs(state.vy) < 1:
                        state.vy = 0
                        state.grounded = True

    # --- Drawing ---
    # Draw Platforms
    for p in state.levels[state.current_level]:
        color = CYAN if p["type"] == "normal" else (PINK if p["type"] == "bouncy" else GOLD)
        pygame.draw.rect(screen, color, p["rect"])
    
    # Draw Player
    pygame.draw.circle(screen, WHITE, (int(state.px), int(state.py)), 10)

    # UI
    mode_txt = "EDITOR MODE (S: Save, R-Click: Change Type)" if state.editing else f"LEVEL: {state.current_level+1} | JUMPS: {state.jumps}"
    pb_txt = f"PB: {state.pb if state.pb != float('inf') else '--'}"
    screen.blit(font.render(mode_txt, True, WHITE), (10, 10))
    screen.blit(font.render(pb_txt, True, WHITE), (10, 35))
    if state.editing:
        screen.blit(font.render(f"TYPE: {current_type.upper()}", True, GOLD), (10, 60))

    pygame.display.flip()

pygame.quit()