make this code have an extra powerup called supersheild… · The Chat Archive
make this code have an extra powerup called supersheild that lasts for 30 seconds and survives 3hits: import pygame
import random
import sys
import time
pygame.init()
Constants
WIDTH, HEIGHT = 600, 400
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Cube Runnin'")
Fonts
font_small = pygame.font.SysFont(None, 24)
font_med = pygame.font.SysFont(None, 36)
font_large = pygame.font.SysFont(None, 48)
font_xlarge = pygame.font.SysFont(None, 72)
Colors
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
RED = (255, 0, 0)
DARK_RED = (180, 0, 0)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0) # Shield color
BLACK = (0, 0, 0)
GRAY = (200, 200, 200)
TRANSPARENT_BLACK_180 = (0, 0, 0, 180)
SPEED_GLOW_COLOR = (50, 255, 50)
Game settings
clock = pygame.time.Clock()
FPS = 60
floor_height = 40
player_size = 20
gravity = 1
jump_speed = 15
base_move_speed = 5
States
STATE_MENU = 0
STATE_PLAYING = 1
STATE_PAUSED = 2
STATE_GAMEOVER = 3
STATE_SETTINGS = 4 # added settings state
Power-up durations in frames
POWERUP_DURATION_FRAMES = FPS * 30 # 30 seconds (double jump, speed boost)
SHIELD_DURATION_FRAMES = FPS * 10 # 10 seconds (shield)
def draw_text_with_outline(surface, text, font, color, outline_color, x, y, center=True):
text_surface = font.render(text, True, color)
outline_surf = font.render(text, True, outline_color)
code Copy code
if center:
rect = text_surface.get_rect(center=(x, y))
else:
rect = text_surface.get_rect(topleft=(x, y))
# Draw outline
outline_positions = [(rect.x - 1, rect.y), (rect.x + 1, rect.y), (rect.x, rect.y - 1), (rect.x, rect.y + 1)]
for pos in outline_positions:
surface.blit(outline_surf, pos)
surface.blit(text_surface, rect)
class Player:
def init (self):
self.rect = pygame.Rect(WIDTH // 2, HEIGHT - floor_height - player_size, player_size, player_size)
self.dy = 0
self.on_floor = True
self.can_double_jump = False
self.double_jump_available = False
self.speed_boost = False
self.shield_active = False
self.speed_boost_time_left = 0
self.shield_time_left = 0
code Copy code
def jump(self):
if self.on_floor:
self.dy = -jump_speed
self.on_floor = False
self.double_jump_available = self.can_double_jump
elif self.double_jump_available:
self.dy = -jump_speed
self.double_jump_available = False
def move(self, dx):
self.rect.x += dx
if self.rect.x < 0:
self.rect.x = 0
if self.rect.x > WIDTH - player_size:
self.rect.x = WIDTH - player_size
def update(self, floors):
self.dy += gravity
self.rect.y += self.dy
collided_floor = None
for floor in floors:
if self.rect.colliderect(floor.rect):
if self.dy >= 0 and self.rect.bottom - self.dy <= floor.rect.top:
self.rect.bottom = floor.rect.top
self.dy = 0
self.on_floor = True
collided_floor = floor
break
else:
self.on_floor = False
if collided_floor and self.dy == 0: # landed, damage floor
if collided_floor.damage():
floors.remove(collided_floor)
if self.rect.y > HEIGHT - floor_height - player_size:
self.rect.y = HEIGHT - floor_height - player_size
self.dy = 0
self.on_floor = True
if self.rect.x < 0:
self.rect.x = 0
elif self.rect.x > WIDTH - player_size:
self.rect.x = WIDTH - player_size
def draw(self, surface):
if self.speed_boost:
glow_radius = player_size * 2
glow_surf = pygame.Surface((glow_radius * 2, glow_radius * 2), pygame.SRCALPHA)
pygame.draw.circle(glow_surf, (*SPEED_GLOW_COLOR, 100), (glow_radius, glow_radius), glow_radius)
surface.blit(glow_surf, (self.rect.centerx - glow_radius, self.rect.centery - glow_radius))
pygame.draw.rect(surface, BLUE, self.rect)
if self.shield_active:
pygame.draw.ellipse(surface, YELLOW, self.rect.inflate(10, 10), 3)
class Floor:
def init (self, y):
self.rect = pygame.Rect(0, y, WIDTH, floor_height)
self.max_health = 5
self.health = self.max_health
code Copy code
def draw(self, surface):
health_ratio = self.health / self.max_health
floor_color = (
int(RED[0] * health_ratio + DARK_RED[0] * (1 - health_ratio)),
int(RED[1] * health_ratio + DARK_RED[1] * (1 - health_ratio)),
int(RED[2] * health_ratio + DARK_RED[2] * (1 - health_ratio))
)
pygame.draw.rect(surface, floor_color, self.rect)
bar_width = self.rect.width * 0.3
bar_height = 6
bar_x = (WIDTH - bar_width) / 2
bar_y = self.rect.top - bar_height - 4
pygame.draw.rect(surface, BLACK, (bar_x, bar_y, bar_width, bar_height), 1)
inner_width = bar_width * (self.health / self.max_health)
pygame.draw.rect(surface, GREEN, (bar_x + 1, bar_y + 1, inner_width - 2, bar_height - 2))
def damage(self):
self.health -= 1
return self.health <= 0
class PowerUp:
def init (self, x, y, power_type):
self.rect = pygame.Rect(x, y, player_size, player_size)
self.power_type = power_type
self.fall_speed = random.randint(3, 6)
code Copy code
def apply(self, player, timers):
if self.power_type == "double_jump":
player.can_double_jump = True
timers['double_jump'] = POWERUP_DURATION_FRAMES
elif self.power_type == "speed_boost":
player.speed_boost = True
timers['speed_boost'] = POWERUP_DURATION_FRAMES
elif self.power_type == "shield":
player.shield_active = True
timers['shield'] = SHIELD_DURATION_FRAMES
def update(self):
self.rect.y += self.fall_speed
def draw(self, surface):
if self.power_type == "double_jump":
color = BLUE
elif self.power_type == "speed_boost":
color = GREEN
elif self.power_type == "shield":
color = YELLOW
else:
color = WHITE
pygame.draw.rect(surface, color, self.rect)
class KillBlock:
def init (self, x, y):
self.size = 60
self.rect = pygame.Rect(x, y, self.size, self.size)
self.fall_speed = random.randint(4, 7)
code Copy code
def update(self):
self.rect.y += self.fall_speed
if self.rect.top > HEIGHT:
self.rect.x = random.randint(0, WIDTH - self.size)
self.rect.y = -self.size
self.fall_speed = random.randint(4, 7)
def draw(self, surface):
pygame.draw.rect(surface, DARK_RED, self.rect)
def draw_paused_overlay(surface):
overlay = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
overlay.fill(TRANSPARENT_BLACK_180)
surface.blit(overlay, (0, 0))
draw_text_with_outline(surface, "PAUSED", font_xlarge, WHITE, BLACK, WIDTH//2, HEIGHT//3)
draw_text_with_outline(surface, "Press ESC to Resume", font_med, WHITE, BLACK, WIDTH//2, HEIGHT//2)
def draw_powerup_timers(surface, timers):
x = 10
y = HEIGHT - 90
bar_width = 140
bar_height = 20
gap = 10
for p_type in timers:
pygame.draw.rect(surface, BLACK, (x, y, bar_width, bar_height))
max_frames = POWERUP_DURATION_FRAMES if p_type != 'shield' else SHIELD_DURATION_FRAMES
progress = timers[p_type] / max_frames
color = GREEN if p_type == 'speed_boost' else BLUE if p_type == 'double_jump' else YELLOW
pygame.draw.rect(surface, color, (x + 2, y + 2, int((bar_width - 4) * progress), bar_height - 4))
label = f"{p_type.replace('_', ' ').title()}: {timers[p_type] // FPS}s"
draw_text_with_outline(surface, label, font_small, WHITE, BLACK, x + bar_width//2, y + 2 + bar_height//2)
y += bar_height + gap
def draw_settings_menu(surface, show_fps):
draw_text_with_outline(surface, "Settings", font_large, BLACK, WHITE, WIDTH // 2, HEIGHT // 6)
status_fps = "ON" if show_fps else "OFF"
draw_text_with_outline(surface, f"Show FPS: {status_fps} (Press F to toggle)", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 3)
draw_text_with_outline(surface, "Press ESC to return to Menu", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2)
def main():
state = STATE_MENU
paused = False
show_fps = True # Settings option
if name == "main ":
main()
Show full message · 444 lines Assistant2025-07-13 11:38 UTC Copy response
To add a new supershield power-up that lasts 30 seconds and survives 3 hits, you'll need to:
Add a new powerup type "supershield".
Track the supershield's remaining hits and duration.
Update logic when the player collides with kill blocks: if supershield is active, decrement hits instead of ending the game.
Draw the supershield indicator distinctively.
Modify timers and powerup durations accordingly.
Here is the modified and added code . I’ll mark changes with comments # NEW or # MODIFIED where appropriate.
make the supersheild very rare and make its cube color super shiny yellow
Assistant2025-07-13 11:39 UTC Copy response
To make the supershield power-up very rare and have its cube color super shiny yellow , we'll:
Reduce the spawn chance of the supershield powerup.
Change its color to a bright yellow with a shiny/glowing effect when drawn.
Changes to make:
1. Rarity change
Currently:
python Copy code
pu_type = random.choice(["double_jump", "speed_boost", "shield", "supershield"])
Instead, we can implement weighted rarity by defining a list with many common powerups and very few supershields:
python Copy code
pu_type = random.choices(
["double_jump", "speed_boost", "shield", "supershield"],
weights=[30, 30, 30, 1], # supershield very rare
k=1
)[0]
This means supershield is approx 1/91 chance (about 1%) to spawn.
2. Super shiny yellow color
Define a bright yellow and add a glow effect for supershield powerup's rect when drawn:
Add a new color:
python Copy code
SUPER_SHINY_YELLOW = (255, 255, 100) # bright yellowish
Modify the PowerUp.draw method, when power_type == "supershield":
python Copy code
elif self.power_type == "supershield":
# draw glow effect behind the cube
glow_radius = player_size # around powerup size
glow_surf = pygame.Surface((glow_radius*4, glow_radius*4), pygame.SRCALPHA)
for i in range(3, 0, -1):
alpha = 30 * i
pygame.draw.rect(
glow_surf,
(*SUPER_SHINY_YELLOW[:3], alpha),
pygame.Rect(glow_radius - i*6, glow_radius - i*6, self.rect.width + i*12, self.rect.height + i*12),
border_radius=4
)
surface.blit(glow_surf, (self.rect.x - glow_radius*1.5, self.rect.y - glow_radius*1.5))
pygame.draw.rect(surface, SUPER_SHINY_YELLOW, self.rect, border_radius=4)
make its color pink instead of yellow and also show me the full updated code after
Assistant2025-07-13 11:40 UTC Copy response
Got it! I'll update the supershield powerup color to pink with a shiny glow, instead of yellow.
Here are the changes, then the full updated code below:
Define pink color for supershield cube & glow, e.g.:
python Copy code
SUPER_SHINY_PINK = (255, 100, 180)
Full updated code with supershield as a rare pink shiny cube
Show full message · 543 lines make shield have a 30% chance of dropping and make the speed boost 30% aswell as the double jump make it 30%
Assistant2025-07-13 11:42 UTC Copy response
Sure! To make the shield, speed boost, and double jump drops each have roughly a 30% chance and supershield very rare (roughly 10%), you can adjust the spawn weights accordingly.
Modify the powerup spawn line from:
python Copy code
pu_type = random.choices(
["double_jump", "speed_boost", "shield", "supershield"],
weights=[30, 30, 30, 1], # supershield is very rare
k=1
)[0]
to something like:
python Copy code
pu_type = random.choices(
["double_jump", "speed_boost", "shield", "supershield"],
weights=[30, 30, 30, 10], # shield, speed boost, double jump each 30%; supershield 10%
k=1
)[0]
This means:
double_jump = 30 / 100 = 30%
speed_boost = 30 / 100 = 30%
shield = 30 / 100 = 30%
supershield = 10 / 100 = 10%
Replace this snippet inside your main game loop where powerups spawn:
python Copy code
if random.randint(1, 100) == 1:
pu_type = random.choices(
["double_jump", "speed_boost", "shield", "supershield"],
weights=[30, 30, 30, 10], # 30% each for first 3, 10% supershield
k=1
)[0]
powerups.append(PowerUp(random.randint(0, WIDTH - player_size), -player_size, pu_type))
That's the only change needed for your requested drop rates!
If you want I can also output the full updated code with this change included!
show me the full code aswell make the supersheild ~1%
Assistant2025-07-13 11:44 UTC Copy response
Certainly! I'll provide you the full updated code where:
double_jump , speed_boost , and shield each have ~30% drop chance,
supershield has about 1% drop chance (very rare),
and supershield is shown as a shiny pink powerup as before.
That means weights roughly like: [30, 30, 30, 1] for a total of 91 (approx 1% for supershield).
Here is the complete updated code with all requested changes:
Show full message · 535 lines make it if i collect 6 shields in a row it makes a opsheild, an opsheild's color is dark pink and its drop chance is ~0.1%
Assistant2025-07-13 11:48 UTC Copy response
Got it! We'll implement the following:
Track how many shields the player collects in a row (consecutively without picking other powerups).
When the player collects 6 shields in a row , grant them an "opsheild" power-up.
The opsheild power-up:
Drops very rarely (about 0.1% chance).
Has a dark pink color.
Works as a super power shield (I will make it survive 5 hits and lasts 45 seconds as an idea).
After collecting an opshield, the consecutive shield count resets.
Reset consecutive shield count if another powerup type is collected (other than shield or opshield).
Implementation plan:
Add 'opsheild' powerup type.
Add a counter consecutive_shields_collected that increments on collecting shield, resets on other pickups.
When consecutive_shields_collected hits 6, apply opshield effect immediately, reset counter.
Make opshield drop very rarely (0.1%) in the spawning weights.
Add opshield color and draw it (dark pink).
Implement opshield behavior: lasts 45 seconds, survives 5 hits.
Show opshield timer and remaining hits in UI.
When opshield active, on collision with killblock reduce hits, and deactivate if zero.
Colors & durations
python Copy code
OPSHEILD_COLOR = (180, 30, 90) # dark pink
OPSHEILD_DURATION_FRAMES = FPS * 45 # 45 seconds
OPSHEILD_HITS = 5
Code additions and changes
In Player
Add:
python Copy code
self.opsheild_active = False
self.opsheild_time_left = 0
self.opsheild_hits_left = 0
Modify PowerUp.apply()
Add:
python Copy code
elif self.power_type == "opsheild":
player.opsheild_active = True
player.opsheild_time_left = OPSHEILD_DURATION_FRAMES
player.opsheild_hits_left = OPSHEILD_HITS
timers['opsheild'] = OPSHEILD_DURATION_FRAMES
Show full message · 770 lines Copy first response
Not yet included in a published release.
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {
'double_jump': 0,
'speed_boost': 0,
'shield': 0,
}
button_rect = pygame.Rect(WIDTH // 2 - 100, HEIGHT // 2 - 25, 200, 50)
while True:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if state == STATE_MENU:
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse_pos = pygame.mouse.get_pos()
if button_rect.collidepoint(mouse_pos):
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {k: 0 for k in powerup_timers}
state = STATE_PLAYING
paused = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {k: 0 for k in powerup_timers}
state = STATE_PLAYING
paused = False
elif event.key == pygame.K_s:
state = STATE_SETTINGS
elif state == STATE_SETTINGS:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
state = STATE_MENU
elif event.key == pygame.K_f:
show_fps = not show_fps
elif state == STATE_PLAYING:
if event.type == pygame.KEYDOWN and not paused:
if event.key in (pygame.K_SPACE, pygame.K_w, pygame.K_UP):
player.jump()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
paused = not paused
elif state == STATE_GAMEOVER:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
state = STATE_MENU
keys = pygame.key.get_pressed()
if state == STATE_PLAYING and not paused:
dx = 0
if keys[pygame.K_a] or keys[pygame.K_LEFT]:
dx -= move_speed_current
if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
dx += move_speed_current
if powerup_timers['speed_boost'] > 0:
dx *= 2
player.move(dx)
player.update(floors)
if random.randint(1, 100) == 1:
pu_type = random.choice(["double_jump", "speed_boost", "shield"])
powerups.append(PowerUp(random.randint(0, WIDTH - player_size), -player_size, pu_type))
for pu in powerups[:]:
pu.update()
if pu.rect.top > HEIGHT:
pu.rect.x = random.randint(0, WIDTH - player_size)
pu.rect.y = -player_size
pu.fall_speed = random.randint(3, 6)
elif player.rect.colliderect(pu.rect):
pu.apply(player, powerup_timers)
score += 1
powerups.remove(pu)
for kb in kill_blocks:
kb.update()
if player.rect.colliderect(kb.rect):
if player.shield_active:
player.shield_active = False
powerup_timers['shield'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
else:
state = STATE_GAMEOVER
for key in powerup_timers:
if powerup_timers[key] > 0:
powerup_timers[key] -= 1
if powerup_timers[key] == 0:
if key == 'double_jump':
player.can_double_jump = False
player.double_jump_available = False
elif key == 'speed_boost':
player.speed_boost = False
elif key == 'shield':
player.shield_active = False
score_timer += 1
if score_timer >= 10:
score += 1
score_timer = 0
screen.fill(WHITE)
if state == STATE_MENU:
draw_text_with_outline(screen, "Cube Runnin'", font_large, BLACK, WHITE, WIDTH // 2, HEIGHT // 4)
pygame.draw.rect(screen, GRAY, button_rect)
draw_text_with_outline(screen, "PLAY GAME", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 - 12)
draw_text_with_outline(screen, "Move: A/D or Arrows, Jump: W/Up/Space", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 50)
draw_text_with_outline(screen, "Avoid falling red blocks! Collect powerups!", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 80)
draw_text_with_outline(screen, "Press S for Settings", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 110)
elif state == STATE_SETTINGS:
draw_settings_menu(screen, show_fps)
elif state == STATE_PLAYING:
for floor in floors:
floor.draw(screen)
for kb in kill_blocks:
kb.draw(screen)
for pu in powerups:
pu.draw(screen)
player.draw(screen)
draw_text_with_outline(screen, f"Score: {score}", font_med, BLACK, WHITE, 60, 20, center=False)
active_timers = {k: v for k, v in powerup_timers.items() if v > 0}
if active_timers:
draw_powerup_timers(screen, active_timers)
y_ui = 50
if player.can_double_jump:
draw_text_with_outline(screen, "Double Jump Active", font_small, BLUE, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.speed_boost:
draw_text_with_outline(screen, "Speed Boost Active", font_small, GREEN, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.shield_active:
draw_text_with_outline(screen, "Shield Active", font_small, YELLOW, WHITE, WIDTH - 150, y_ui)
if paused:
draw_paused_overlay(screen)
if show_fps:
fps = int(clock.get_fps())
draw_text_with_outline(screen, f"FPS: {fps}", font_small, BLACK, WHITE, 10, HEIGHT - 25, center=False)
elif state == STATE_GAMEOVER:
draw_text_with_outline(screen, "GAME OVER", font_xlarge, RED, BLACK, WIDTH // 2, HEIGHT // 3)
draw_text_with_outline(screen, f"Final Score: {score}", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2)
draw_text_with_outline(screen, "Press R to Restart", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 50)
pygame.display.flip()
# Add new color (e.g., Cyan) for supershield visualization
CYAN = (0, 255, 255)
# Add supershield duration (30 seconds in frames)
SUPERSHIELD_DURATION_FRAMES = FPS * 30 # 30 seconds
class Player:
def __init__(self):
# ... existing init code ...
self.supershield_active = False # NEW
self.supershield_time_left = 0 # NEW
self.supershield_hits_left = 0 # NEW
def draw(self, surface):
# ... existing speed_boost glow ...
if self.supershield_active:
# Draw supershield ellipse thicker and cyan colored to distinguish
pygame.draw.ellipse(surface, CYAN, self.rect.inflate(14, 14), 4)
if self.shield_active:
pygame.draw.ellipse(surface, YELLOW, self.rect.inflate(10, 10), 3)
pygame.draw.rect(surface, BLUE, self.rect)
class PowerUp:
def apply(self, player, timers):
if self.power_type == "double_jump":
# existing code ...
player.can_double_jump = True
timers['double_jump'] = POWERUP_DURATION_FRAMES
elif self.power_type == "speed_boost":
player.speed_boost = True
timers['speed_boost'] = POWERUP_DURATION_FRAMES
elif self.power_type == "shield":
player.shield_active = True
timers['shield'] = SHIELD_DURATION_FRAMES
elif self.power_type == "supershield": # NEW
player.supershield_active = True
player.supershield_time_left = SUPERSHIELD_DURATION_FRAMES
player.supershield_hits_left = 3 # survive 3 hits
timers['supershield'] = SUPERSHIELD_DURATION_FRAMES
def draw(self, surface):
if self.power_type == "double_jump":
color = BLUE
elif self.power_type == "speed_boost":
color = GREEN
elif self.power_type == "shield":
color = YELLOW
elif self.power_type == "supershield": # NEW
color = CYAN
else:
color = WHITE
pygame.draw.rect(surface, color, self.rect)
def draw_powerup_timers(surface, timers):
x = 10
y = HEIGHT - 90
bar_width = 140
bar_height = 20
gap = 10
for p_type in timers:
pygame.draw.rect(surface, BLACK, (x, y, bar_width, bar_height))
if p_type == 'shield':
max_frames = SHIELD_DURATION_FRAMES
elif p_type == 'supershield': # NEW
max_frames = SUPERSHIELD_DURATION_FRAMES
else:
max_frames = POWERUP_DURATION_FRAMES
progress = timers[p_type] / max_frames
color = GREEN if p_type == 'speed_boost' else BLUE if p_type == 'double_jump' else YELLOW if p_type == 'shield' else CYAN if p_type == 'supershield' else WHITE
pygame.draw.rect(surface, color, (x + 2, y + 2, int((bar_width - 4) * progress), bar_height - 4))
label = f"{p_type.replace('_', ' ').title()}: {timers[p_type] // FPS}s"
draw_text_with_outline(surface, label, font_small, WHITE, BLACK, x + bar_width//2, y + 2 + bar_height//2)
y += bar_height + gap
def main():
# Add supershield to powerup_timers dict
powerup_timers = {
'double_jump': 0,
'speed_boost': 0,
'shield': 0,
'supershield': 0, # NEW
}
# In the main loop, spawn supershield as possible powerup
# Modify this line:
# pu_type = random.choice(["double_jump", "speed_boost", "shield"])
# to:
pu_type = random.choice(["double_jump", "speed_boost", "shield", "supershield"]) # NEW
# When player collides with kill block, update collision logic:
for kb in kill_blocks:
kb.update()
if player.rect.colliderect(kb.rect):
if player.supershield_active:
player.supershield_hits_left -= 1
if player.supershield_hits_left <= 0:
player.supershield_active = False
powerup_timers['supershield'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
elif player.shield_active:
player.shield_active = False
powerup_timers['shield'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
else:
state = STATE_GAMEOVER
# Update powerup timers decrement with supershield:
for key in powerup_timers:
if powerup_timers[key] > 0:
powerup_timers[key] -= 1
if powerup_timers[key] == 0:
if key == 'double_jump':
player.can_double_jump = False
player.double_jump_available = False
elif key == 'speed_boost':
player.speed_boost = False
elif key == 'shield':
player.shield_active = False
elif key == 'supershield': # NEW
player.supershield_active = False
player.supershield_hits_left = 0
# Add display text for supershield active:
y_ui = 50
if player.can_double_jump:
draw_text_with_outline(screen, "Double Jump Active", font_small, BLUE, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.speed_boost:
draw_text_with_outline(screen, "Speed Boost Active", font_small, GREEN, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.shield_active:
draw_text_with_outline(screen, "Shield Active", font_small, YELLOW, WHITE, WIDTH - 150, y_ui)
y_ui += 24 # add spacing for next text
if player.supershield_active:
draw_text_with_outline(screen, f"Super Shield Active ({player.supershield_hits_left} hits left)", font_small, CYAN, WHITE, WIDTH - 200, y_ui)
y_ui += 24
Summary of key changes:
Added supershield_active, supershield_time_left, supershield_hits_left to Player.
New power-up "supershield" with duration 30 seconds and 3 hit capacity.
When a kill block hits player:
supershield loses one hit, deactivates if no hits left.
shield consumes completely on any hit.
no shield/supershield causes game over.
Display supershield status in UI and draw a cyan outline around player.
Add supershield to powerup spawning and timers.
You can simply add these snippets in place or merge them with your existing code.
If you want, I can provide the complete modified code as one block. Just let me know!
This creates a glowing yellow effect around the powerup block.
Full code snippet modifications: python Copy code
SUPER_SHINY_YELLOW = (255, 255, 100) # bright yellowish to use for supershield cube color
# Replace the powerup spawn line inside main game loop:
# Original (near "if random.randint(1, 100) == 1:")
pu_type = random.choices(
["double_jump", "speed_boost", "shield", "supershield"],
weights=[30, 30, 30, 1], # supershield rare!
k=1
)[0]
# Modify PowerUp.draw method (replace corresponding elif)
class PowerUp:
def draw(self, surface):
if self.power_type == "double_jump":
color = BLUE
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "speed_boost":
color = GREEN
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "shield":
color = YELLOW
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "supershield":
# SHINY YELLOW WITH GLOW
glow_radius = player_size
glow_surf = pygame.Surface((glow_radius * 4, glow_radius * 4), pygame.SRCALPHA)
for i in range(3, 0, -1):
alpha = 30 * i
rect = pygame.Rect(
glow_radius - i * 6,
glow_radius - i * 6,
self.rect.width + i * 12,
self.rect.height + i * 12,
)
pygame.draw.rect(glow_surf, (*SUPER_SHINY_YELLOW[:3], alpha), rect, border_radius=4)
surface.blit(glow_surf, (self.rect.x - glow_radius * 1.5, self.rect.y - glow_radius * 1.5))
pygame.draw.rect(surface, SUPER_SHINY_YELLOW, self.rect, border_radius=4)
else:
color = WHITE
pygame.draw.rect(surface, color, self.rect)
Summary:
Supershield now spawns only ~1% of the time to keep it very rare.
The supershield cube glows with a super shiny yellow color and rounded bright rectangles behind it.
Add these snippets into your code replacing the corresponding areas.
If you'd rather want me to integrate these into your entire code block, just ask!
import pygame
import random
import sys
import time
pygame.init()
# Constants
WIDTH, HEIGHT = 600, 400
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Cube Runnin'")
# Fonts
font_small = pygame.font.SysFont(None, 24)
font_med = pygame.font.SysFont(None, 36)
font_large = pygame.font.SysFont(None, 48)
font_xlarge = pygame.font.SysFont(None, 72)
# Colors
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
RED = (255, 0, 0)
DARK_RED = (180, 0, 0)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0) # Shield color
BLACK = (0, 0, 0)
GRAY = (200, 200, 200)
TRANSPARENT_BLACK_180 = (0, 0, 0, 180)
SPEED_GLOW_COLOR = (50, 255, 50)
SUPER_SHINY_PINK = (255, 100, 180) # supershield pink glow color
# Game settings
clock = pygame.time.Clock()
FPS = 60
floor_height = 40
player_size = 20
gravity = 1
jump_speed = 15
base_move_speed = 5
# States
STATE_MENU = 0
STATE_PLAYING = 1
STATE_PAUSED = 2
STATE_GAMEOVER = 3
STATE_SETTINGS = 4 # added settings state
# Power-up durations in frames
POWERUP_DURATION_FRAMES = FPS * 30 # 30 seconds (double jump, speed boost)
SHIELD_DURATION_FRAMES = FPS * 10 # 10 seconds (shield)
SUPERSHIELD_DURATION_FRAMES = FPS * 30 # 30 seconds supershield
def draw_text_with_outline(surface, text, font, color, outline_color, x, y, center=True):
text_surface = font.render(text, True, color)
outline_surf = font.render(text, True, outline_color)
if center:
rect = text_surface.get_rect(center=(x, y))
else:
rect = text_surface.get_rect(topleft=(x, y))
# Draw outline
outline_positions = [(rect.x - 1, rect.y), (rect.x + 1, rect.y), (rect.x, rect.y - 1), (rect.x, rect.y + 1)]
for pos in outline_positions:
surface.blit(outline_surf, pos)
surface.blit(text_surface, rect)
class Player:
def __init__(self):
self.rect = pygame.Rect(WIDTH // 2, HEIGHT - floor_height - player_size, player_size, player_size)
self.dy = 0
self.on_floor = True
self.can_double_jump = False
self.double_jump_available = False
self.speed_boost = False
self.shield_active = False
self.supershield_active = False
self.speed_boost_time_left = 0
self.shield_time_left = 0
self.supershield_time_left = 0
self.supershield_hits_left = 0
def jump(self):
if self.on_floor:
self.dy = -jump_speed
self.on_floor = False
self.double_jump_available = self.can_double_jump
elif self.double_jump_available:
self.dy = -jump_speed
self.double_jump_available = False
def move(self, dx):
self.rect.x += dx
if self.rect.x < 0:
self.rect.x = 0
if self.rect.x > WIDTH - player_size:
self.rect.x = WIDTH - player_size
def update(self, floors):
self.dy += gravity
self.rect.y += self.dy
collided_floor = None
for floor in floors:
if self.rect.colliderect(floor.rect):
if self.dy >= 0 and self.rect.bottom - self.dy <= floor.rect.top:
self.rect.bottom = floor.rect.top
self.dy = 0
self.on_floor = True
collided_floor = floor
break
else:
self.on_floor = False
if collided_floor and self.dy == 0: # landed, damage floor
if collided_floor.damage():
floors.remove(collided_floor)
if self.rect.y > HEIGHT - floor_height - player_size:
self.rect.y = HEIGHT - floor_height - player_size
self.dy = 0
self.on_floor = True
if self.rect.x < 0:
self.rect.x = 0
elif self.rect.x > WIDTH - player_size:
self.rect.x = WIDTH - player_size
def draw(self, surface):
if self.speed_boost:
glow_radius = player_size * 2
glow_surf = pygame.Surface((glow_radius * 2, glow_radius * 2), pygame.SRCALPHA)
pygame.draw.circle(glow_surf, (*SPEED_GLOW_COLOR, 100), (glow_radius, glow_radius), glow_radius)
surface.blit(glow_surf, (self.rect.centerx - glow_radius, self.rect.centery - glow_radius))
if self.supershield_active:
pygame.draw.ellipse(surface, SUPER_SHINY_PINK, self.rect.inflate(14, 14), 4)
if self.shield_active:
pygame.draw.ellipse(surface, YELLOW, self.rect.inflate(10, 10), 3)
pygame.draw.rect(surface, BLUE, self.rect)
class Floor:
def __init__(self, y):
self.rect = pygame.Rect(0, y, WIDTH, floor_height)
self.max_health = 5
self.health = self.max_health
def draw(self, surface):
health_ratio = self.health / self.max_health
floor_color = (
int(RED[0] * health_ratio + DARK_RED[0] * (1 - health_ratio)),
int(RED[1] * health_ratio + DARK_RED[1] * (1 - health_ratio)),
int(RED[2] * health_ratio + DARK_RED[2] * (1 - health_ratio))
)
pygame.draw.rect(surface, floor_color, self.rect)
bar_width = self.rect.width * 0.3
bar_height = 6
bar_x = (WIDTH - bar_width) / 2
bar_y = self.rect.top - bar_height - 4
pygame.draw.rect(surface, BLACK, (bar_x, bar_y, bar_width, bar_height), 1)
inner_width = bar_width * (self.health / self.max_health)
pygame.draw.rect(surface, GREEN, (bar_x + 1, bar_y + 1, inner_width - 2, bar_height - 2))
def damage(self):
self.health -= 1
return self.health <= 0
class PowerUp:
def __init__(self, x, y, power_type):
self.rect = pygame.Rect(x, y, player_size, player_size)
self.power_type = power_type
self.fall_speed = random.randint(3, 6)
def apply(self, player, timers):
if self.power_type == "double_jump":
player.can_double_jump = True
timers['double_jump'] = POWERUP_DURATION_FRAMES
elif self.power_type == "speed_boost":
player.speed_boost = True
timers['speed_boost'] = POWERUP_DURATION_FRAMES
elif self.power_type == "shield":
player.shield_active = True
timers['shield'] = SHIELD_DURATION_FRAMES
elif self.power_type == "supershield":
player.supershield_active = True
player.supershield_time_left = SUPERSHIELD_DURATION_FRAMES
player.supershield_hits_left = 3
timers['supershield'] = SUPERSHIELD_DURATION_FRAMES
def update(self):
self.rect.y += self.fall_speed
def draw(self, surface):
if self.power_type == "double_jump":
color = BLUE
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "speed_boost":
color = GREEN
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "shield":
color = YELLOW
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "supershield":
# SHINY PINK WITH GLOW
glow_radius = player_size
glow_surf = pygame.Surface((glow_radius * 4, glow_radius * 4), pygame.SRCALPHA)
for i in range(3, 0, -1):
alpha = 30 * i
rect = pygame.Rect(
glow_radius - i * 6,
glow_radius - i * 6,
self.rect.width + i * 12,
self.rect.height + i * 12,
)
pygame.draw.rect(glow_surf, (*SUPER_SHINY_PINK[:3], alpha), rect, border_radius=4)
surface.blit(glow_surf, (self.rect.x - glow_radius * 1.5, self.rect.y - glow_radius * 1.5))
pygame.draw.rect(surface, SUPER_SHINY_PINK, self.rect, border_radius=4)
else:
color = WHITE
pygame.draw.rect(surface, color, self.rect)
class KillBlock:
def __init__(self, x, y):
self.size = 60
self.rect = pygame.Rect(x, y, self.size, self.size)
self.fall_speed = random.randint(4, 7)
def update(self):
self.rect.y += self.fall_speed
if self.rect.top > HEIGHT:
self.rect.x = random.randint(0, WIDTH - self.size)
self.rect.y = -self.size
self.fall_speed = random.randint(4, 7)
def draw(self, surface):
pygame.draw.rect(surface, DARK_RED, self.rect)
def draw_paused_overlay(surface):
overlay = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
overlay.fill(TRANSPARENT_BLACK_180)
surface.blit(overlay, (0, 0))
draw_text_with_outline(surface, "PAUSED", font_xlarge, WHITE, BLACK, WIDTH//2, HEIGHT//3)
draw_text_with_outline(surface, "Press ESC to Resume", font_med, WHITE, BLACK, WIDTH//2, HEIGHT//2)
def draw_powerup_timers(surface, timers):
x = 10
y = HEIGHT - 90
bar_width = 140
bar_height = 20
gap = 10
for p_type in timers:
pygame.draw.rect(surface, BLACK, (x, y, bar_width, bar_height))
if p_type == 'shield':
max_frames = SHIELD_DURATION_FRAMES
elif p_type == 'supershield':
max_frames = SUPERSHIELD_DURATION_FRAMES
else:
max_frames = POWERUP_DURATION_FRAMES
progress = timers[p_type] / max_frames
color = (
GREEN if p_type == 'speed_boost' else
BLUE if p_type == 'double_jump' else
YELLOW if p_type == 'shield' else
SUPER_SHINY_PINK if p_type == 'supershield' else
WHITE
)
pygame.draw.rect(surface, color, (x + 2, y + 2, int((bar_width - 4) * progress), bar_height - 4))
label = f"{p_type.replace('_', ' ').title()}: {timers[p_type] // FPS}s"
draw_text_with_outline(surface, label, font_small, WHITE, BLACK, x + bar_width//2, y + 2 + bar_height//2)
y += bar_height + gap
def draw_settings_menu(surface, show_fps):
draw_text_with_outline(surface, "Settings", font_large, BLACK, WHITE, WIDTH // 2, HEIGHT // 6)
status_fps = "ON" if show_fps else "OFF"
draw_text_with_outline(surface, f"Show FPS: {status_fps} (Press F to toggle)", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 3)
draw_text_with_outline(surface, "Press ESC to return to Menu", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2)
def main():
state = STATE_MENU
paused = False
show_fps = True # Settings option
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {
'double_jump': 0,
'speed_boost': 0,
'shield': 0,
'supershield': 0,
}
button_rect = pygame.Rect(WIDTH // 2 - 100, HEIGHT // 2 - 25, 200, 50)
while True:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if state == STATE_MENU:
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse_pos = pygame.mouse.get_pos()
if button_rect.collidepoint(mouse_pos):
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {k: 0 for k in powerup_timers}
state = STATE_PLAYING
paused = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {k: 0 for k in powerup_timers}
state = STATE_PLAYING
paused = False
elif event.key == pygame.K_s:
state = STATE_SETTINGS
elif state == STATE_SETTINGS:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
state = STATE_MENU
elif event.key == pygame.K_f:
show_fps = not show_fps
elif state == STATE_PLAYING:
if event.type == pygame.KEYDOWN and not paused:
if event.key in (pygame.K_SPACE, pygame.K_w, pygame.K_UP):
player.jump()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
paused = not paused
elif state == STATE_GAMEOVER:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
state = STATE_MENU
keys = pygame.key.get_pressed()
if state == STATE_PLAYING and not paused:
dx = 0
if keys[pygame.K_a] or keys[pygame.K_LEFT]:
dx -= move_speed_current
if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
dx += move_speed_current
if powerup_timers['speed_boost'] > 0:
dx *= 2
player.move(dx)
player.update(floors)
if random.randint(1, 100) == 1:
pu_type = random.choices(
["double_jump", "speed_boost", "shield", "supershield"],
weights=[30, 30, 30, 1], # supershield is very rare
k=1
)[0]
powerups.append(PowerUp(random.randint(0, WIDTH - player_size), -player_size, pu_type))
for pu in powerups[:]:
pu.update()
if pu.rect.top > HEIGHT:
pu.rect.x = random.randint(0, WIDTH - player_size)
pu.rect.y = -player_size
pu.fall_speed = random.randint(3, 6)
elif player.rect.colliderect(pu.rect):
pu.apply(player, powerup_timers)
score += 1
powerups.remove(pu)
for kb in kill_blocks:
kb.update()
if player.rect.colliderect(kb.rect):
if player.supershield_active:
player.supershield_hits_left -= 1
if player.supershield_hits_left <= 0:
player.supershield_active = False
powerup_timers['supershield'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
elif player.shield_active:
player.shield_active = False
powerup_timers['shield'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
else:
state = STATE_GAMEOVER
for key in powerup_timers:
if powerup_timers[key] > 0:
powerup_timers[key] -= 1
if powerup_timers[key] == 0:
if key == 'double_jump':
player.can_double_jump = False
player.double_jump_available = False
elif key == 'speed_boost':
player.speed_boost = False
elif key == 'shield':
player.shield_active = False
elif key == 'supershield':
player.supershield_active = False
player.supershield_hits_left = 0
score_timer += 1
if score_timer >= 10:
score += 1
score_timer = 0
screen.fill(WHITE)
if state == STATE_MENU:
draw_text_with_outline(screen, "Cube Runnin'", font_large, BLACK, WHITE, WIDTH // 2, HEIGHT // 4)
pygame.draw.rect(screen, GRAY, button_rect)
draw_text_with_outline(screen, "PLAY GAME", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 - 12)
draw_text_with_outline(screen, "Move: A/D or Arrows, Jump: W/Up/Space", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 50)
draw_text_with_outline(screen, "Avoid falling red blocks! Collect powerups!", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 80)
draw_text_with_outline(screen, "Press S for Settings", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 110)
elif state == STATE_SETTINGS:
draw_settings_menu(screen, show_fps)
elif state == STATE_PLAYING:
for floor in floors:
floor.draw(screen)
for kb in kill_blocks:
kb.draw(screen)
for pu in powerups:
pu.draw(screen)
player.draw(screen)
draw_text_with_outline(screen, f"Score: {score}", font_med, BLACK, WHITE, 60, 20, center=False)
active_timers = {k: v for k, v in powerup_timers.items() if v > 0}
if active_timers:
draw_powerup_timers(screen, active_timers)
y_ui = 50
if player.can_double_jump:
draw_text_with_outline(screen, "Double Jump Active", font_small, BLUE, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.speed_boost:
draw_text_with_outline(screen, "Speed Boost Active", font_small, GREEN, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.shield_active:
draw_text_with_outline(screen, "Shield Active", font_small, YELLOW, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.supershield_active:
draw_text_with_outline(screen, f"Super Shield Active ({player.supershield_hits_left} hits left)", font_small, SUPER_SHINY_PINK, WHITE, WIDTH - 200, y_ui)
y_ui += 24
if paused:
draw_paused_overlay(screen)
if show_fps:
fps = int(clock.get_fps())
draw_text_with_outline(screen, f"FPS: {fps}", font_small, BLACK, WHITE, 10, HEIGHT - 25, center=False)
elif state == STATE_GAMEOVER:
draw_text_with_outline(screen, "GAME OVER", font_xlarge, RED, BLACK, WIDTH // 2, HEIGHT // 3)
draw_text_with_outline(screen, f"Final Score: {score}", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2)
draw_text_with_outline(screen, "Press R to Restart", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 50)
pygame.display.flip()
if __name__ == "__main__":
main()
Summary of the additions:
Supershield rarity set with random.choices weights — very rare (1 in ~91 chance).
Supershield powerup cube draws with a glowing pink rectangle, using multiple translucent rings behind it.
Player displays supershield active status with pink text.
Player outline glow for supershield is pink ellipse around the player cube.
All supershield durations are 30 seconds, hit count is 3 hits to survive.
Let me know if you'd like me to help with anything else!
import pygame
import random
import sys
import time
pygame.init()
# Constants
WIDTH, HEIGHT = 600, 400
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Cube Runnin'")
# Fonts
font_small = pygame.font.SysFont(None, 24)
font_med = pygame.font.SysFont(None, 36)
font_large = pygame.font.SysFont(None, 48)
font_xlarge = pygame.font.SysFont(None, 72)
# Colors
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
RED = (255, 0, 0)
DARK_RED = (180, 0, 0)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0) # Shield color
BLACK = (0, 0, 0)
GRAY = (200, 200, 200)
TRANSPARENT_BLACK_180 = (0, 0, 0, 180)
SPEED_GLOW_COLOR = (50, 255, 50)
SUPER_SHINY_PINK = (255, 100, 180) # supershield pink glow color
# Game settings
clock = pygame.time.Clock()
FPS = 60
floor_height = 40
player_size = 20
gravity = 1
jump_speed = 15
base_move_speed = 5
# States
STATE_MENU = 0
STATE_PLAYING = 1
STATE_PAUSED = 2
STATE_GAMEOVER = 3
STATE_SETTINGS = 4 # added settings state
# Power-up durations in frames
POWERUP_DURATION_FRAMES = FPS * 30 # 30 seconds (double jump, speed boost)
SHIELD_DURATION_FRAMES = FPS * 10 # 10 seconds (shield)
SUPERSHIELD_DURATION_FRAMES = FPS * 30 # 30 seconds supershield
def draw_text_with_outline(surface, text, font, color, outline_color, x, y, center=True):
text_surface = font.render(text, True, color)
outline_surf = font.render(text, True, outline_color)
if center:
rect = text_surface.get_rect(center=(x, y))
else:
rect = text_surface.get_rect(topleft=(x, y))
# Draw outline
outline_positions = [(rect.x - 1, rect.y), (rect.x + 1, rect.y), (rect.x, rect.y - 1), (rect.x, rect.y + 1)]
for pos in outline_positions:
surface.blit(outline_surf, pos)
surface.blit(text_surface, rect)
class Player:
def __init__(self):
self.rect = pygame.Rect(WIDTH // 2, HEIGHT - floor_height - player_size, player_size, player_size)
self.dy = 0
self.on_floor = True
self.can_double_jump = False
self.double_jump_available = False
self.speed_boost = False
self.shield_active = False
self.supershield_active = False
self.speed_boost_time_left = 0
self.shield_time_left = 0
self.supershield_time_left = 0
self.supershield_hits_left = 0
def jump(self):
if self.on_floor:
self.dy = -jump_speed
self.on_floor = False
self.double_jump_available = self.can_double_jump
elif self.double_jump_available:
self.dy = -jump_speed
self.double_jump_available = False
def move(self, dx):
self.rect.x += dx
if self.rect.x < 0:
self.rect.x = 0
if self.rect.x > WIDTH - player_size:
self.rect.x = WIDTH - player_size
def update(self, floors):
self.dy += gravity
self.rect.y += self.dy
collided_floor = None
for floor in floors:
if self.rect.colliderect(floor.rect):
if self.dy >= 0 and self.rect.bottom - self.dy <= floor.rect.top:
self.rect.bottom = floor.rect.top
self.dy = 0
self.on_floor = True
collided_floor = floor
break
else:
self.on_floor = False
if collided_floor and self.dy == 0: # landed, damage floor
if collided_floor.damage():
floors.remove(collided_floor)
if self.rect.y > HEIGHT - floor_height - player_size:
self.rect.y = HEIGHT - floor_height - player_size
self.dy = 0
self.on_floor = True
if self.rect.x < 0:
self.rect.x = 0
elif self.rect.x > WIDTH - player_size:
self.rect.x = WIDTH - player_size
def draw(self, surface):
if self.speed_boost:
glow_radius = player_size * 2
glow_surf = pygame.Surface((glow_radius * 2, glow_radius * 2), pygame.SRCALPHA)
pygame.draw.circle(glow_surf, (*SPEED_GLOW_COLOR, 100), (glow_radius, glow_radius), glow_radius)
surface.blit(glow_surf, (self.rect.centerx - glow_radius, self.rect.centery - glow_radius))
if self.supershield_active:
pygame.draw.ellipse(surface, SUPER_SHINY_PINK, self.rect.inflate(14, 14), 4)
if self.shield_active:
pygame.draw.ellipse(surface, YELLOW, self.rect.inflate(10, 10), 3)
pygame.draw.rect(surface, BLUE, self.rect)
class Floor:
def __init__(self, y):
self.rect = pygame.Rect(0, y, WIDTH, floor_height)
self.max_health = 5
self.health = self.max_health
def draw(self, surface):
health_ratio = self.health / self.max_health
floor_color = (
int(RED[0] * health_ratio + DARK_RED[0] * (1 - health_ratio)),
int(RED[1] * health_ratio + DARK_RED[1] * (1 - health_ratio)),
int(RED[2] * health_ratio + DARK_RED[2] * (1 - health_ratio))
)
pygame.draw.rect(surface, floor_color, self.rect)
bar_width = self.rect.width * 0.3
bar_height = 6
bar_x = (WIDTH - bar_width) / 2
bar_y = self.rect.top - bar_height - 4
pygame.draw.rect(surface, BLACK, (bar_x, bar_y, bar_width, bar_height), 1)
inner_width = bar_width * (self.health / self.max_health)
pygame.draw.rect(surface, GREEN, (bar_x + 1, bar_y + 1, inner_width - 2, bar_height - 2))
def damage(self):
self.health -= 1
return self.health <= 0
class PowerUp:
def __init__(self, x, y, power_type):
self.rect = pygame.Rect(x, y, player_size, player_size)
self.power_type = power_type
self.fall_speed = random.randint(3, 6)
def apply(self, player, timers):
if self.power_type == "double_jump":
player.can_double_jump = True
timers['double_jump'] = POWERUP_DURATION_FRAMES
elif self.power_type == "speed_boost":
player.speed_boost = True
timers['speed_boost'] = POWERUP_DURATION_FRAMES
elif self.power_type == "shield":
player.shield_active = True
timers['shield'] = SHIELD_DURATION_FRAMES
elif self.power_type == "supershield":
player.supershield_active = True
player.supershield_time_left = SUPERSHIELD_DURATION_FRAMES
player.supershield_hits_left = 3
timers['supershield'] = SUPERSHIELD_DURATION_FRAMES
def update(self):
self.rect.y += self.fall_speed
def draw(self, surface):
if self.power_type == "double_jump":
color = BLUE
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "speed_boost":
color = GREEN
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "shield":
color = YELLOW
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "supershield":
# SHINY PINK WITH GLOW
glow_radius = player_size
glow_surf = pygame.Surface((glow_radius * 4, glow_radius * 4), pygame.SRCALPHA)
for i in range(3, 0, -1):
alpha = 30 * i
rect = pygame.Rect(
glow_radius - i * 6,
glow_radius - i * 6,
self.rect.width + i * 12,
self.rect.height + i * 12,
)
pygame.draw.rect(glow_surf, (*SUPER_SHINY_PINK[:3], alpha), rect, border_radius=4)
surface.blit(glow_surf, (self.rect.x - glow_radius * 1.5, self.rect.y - glow_radius * 1.5))
pygame.draw.rect(surface, SUPER_SHINY_PINK, self.rect, border_radius=4)
else:
color = WHITE
pygame.draw.rect(surface, color, self.rect)
class KillBlock:
def __init__(self, x, y):
self.size = 60
self.rect = pygame.Rect(x, y, self.size, self.size)
self.fall_speed = random.randint(4, 7)
def update(self):
self.rect.y += self.fall_speed
if self.rect.top > HEIGHT:
self.rect.x = random.randint(0, WIDTH - self.size)
self.rect.y = -self.size
self.fall_speed = random.randint(4, 7)
def draw(self, surface):
pygame.draw.rect(surface, DARK_RED, self.rect)
def draw_paused_overlay(surface):
overlay = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
overlay.fill(TRANSPARENT_BLACK_180)
surface.blit(overlay, (0, 0))
draw_text_with_outline(surface, "PAUSED", font_xlarge, WHITE, BLACK, WIDTH//2, HEIGHT//3)
draw_text_with_outline(surface, "Press ESC to Resume", font_med, WHITE, BLACK, WIDTH//2, HEIGHT//2)
def draw_powerup_timers(surface, timers):
x = 10
y = HEIGHT - 90
bar_width = 140
bar_height = 20
gap = 10
for p_type in timers:
pygame.draw.rect(surface, BLACK, (x, y, bar_width, bar_height))
if p_type == 'shield':
max_frames = SHIELD_DURATION_FRAMES
elif p_type == 'supershield':
max_frames = SUPERSHIELD_DURATION_FRAMES
else:
max_frames = POWERUP_DURATION_FRAMES
progress = timers[p_type] / max_frames
color = (
GREEN if p_type == 'speed_boost' else
BLUE if p_type == 'double_jump' else
YELLOW if p_type == 'shield' else
SUPER_SHINY_PINK if p_type == 'supershield' else
WHITE
)
pygame.draw.rect(surface, color, (x + 2, y + 2, int((bar_width - 4) * progress), bar_height - 4))
label = f"{p_type.replace('_', ' ').title()}: {timers[p_type] // FPS}s"
draw_text_with_outline(surface, label, font_small, WHITE, BLACK, x + bar_width//2, y + 2 + bar_height//2)
y += bar_height + gap
def draw_settings_menu(surface, show_fps):
draw_text_with_outline(surface, "Settings", font_large, BLACK, WHITE, WIDTH // 2, HEIGHT // 6)
status_fps = "ON" if show_fps else "OFF"
draw_text_with_outline(surface, f"Show FPS: {status_fps} (Press F to toggle)", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 3)
draw_text_with_outline(surface, "Press ESC to return to Menu", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2)
def main():
state = STATE_MENU
paused = False
show_fps = True # Settings option
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {
'double_jump': 0,
'speed_boost': 0,
'shield': 0,
'supershield': 0,
}
button_rect = pygame.Rect(WIDTH // 2 - 100, HEIGHT // 2 - 25, 200, 50)
while True:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if state == STATE_MENU:
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse_pos = pygame.mouse.get_pos()
if button_rect.collidepoint(mouse_pos):
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {k: 0 for k in powerup_timers}
state = STATE_PLAYING
paused = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {k: 0 for k in powerup_timers}
state = STATE_PLAYING
paused = False
elif event.key == pygame.K_s:
state = STATE_SETTINGS
elif state == STATE_SETTINGS:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
state = STATE_MENU
elif event.key == pygame.K_f:
show_fps = not show_fps
elif state == STATE_PLAYING:
if event.type == pygame.KEYDOWN and not paused:
if event.key in (pygame.K_SPACE, pygame.K_w, pygame.K_UP):
player.jump()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
paused = not paused
elif state == STATE_GAMEOVER:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
state = STATE_MENU
keys = pygame.key.get_pressed()
if state == STATE_PLAYING and not paused:
dx = 0
if keys[pygame.K_a] or keys[pygame.K_LEFT]:
dx -= move_speed_current
if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
dx += move_speed_current
if powerup_timers['speed_boost'] > 0:
dx *= 2
player.move(dx)
player.update(floors)
if random.randint(1, 100) == 1:
pu_type = random.choices(
["double_jump", "speed_boost", "shield", "supershield"],
weights=[30, 30, 30, 1], # ~30% each + supershield ~1%
k=1
)[0]
powerups.append(PowerUp(random.randint(0, WIDTH - player_size), -player_size, pu_type))
for pu in powerups[:]:
pu.update()
if pu.rect.top > HEIGHT:
pu.rect.x = random.randint(0, WIDTH - player_size)
pu.rect.y = -player_size
pu.fall_speed = random.randint(3, 6)
elif player.rect.colliderect(pu.rect):
pu.apply(player, powerup_timers)
score += 1
powerups.remove(pu)
for kb in kill_blocks:
kb.update()
if player.rect.colliderect(kb.rect):
if player.supershield_active:
player.supershield_hits_left -= 1
if player.supershield_hits_left <= 0:
player.supershield_active = False
powerup_timers['supershield'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
elif player.shield_active:
player.shield_active = False
powerup_timers['shield'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
else:
state = STATE_GAMEOVER
for key in powerup_timers:
if powerup_timers[key] > 0:
powerup_timers[key] -= 1
if powerup_timers[key] == 0:
if key == 'double_jump':
player.can_double_jump = False
player.double_jump_available = False
elif key == 'speed_boost':
player.speed_boost = False
elif key == 'shield':
player.shield_active = False
elif key == 'supershield':
player.supershield_active = False
player.supershield_hits_left = 0
score_timer += 1
if score_timer >= 10:
score += 1
score_timer = 0
screen.fill(WHITE)
if state == STATE_MENU:
draw_text_with_outline(screen, "Cube Runnin'", font_large, BLACK, WHITE, WIDTH // 2, HEIGHT // 4)
pygame.draw.rect(screen, GRAY, button_rect)
draw_text_with_outline(screen, "PLAY GAME", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 - 12)
draw_text_with_outline(screen, "Move: A/D or Arrows, Jump: W/Up/Space", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 50)
draw_text_with_outline(screen, "Avoid falling red blocks! Collect powerups!", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 80)
draw_text_with_outline(screen, "Press S for Settings", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 110)
elif state == STATE_SETTINGS:
draw_settings_menu(screen, show_fps)
elif state == STATE_PLAYING:
for floor in floors:
floor.draw(screen)
for kb in kill_blocks:
kb.draw(screen)
for pu in powerups:
pu.draw(screen)
player.draw(screen)
draw_text_with_outline(screen, f"Score: {score}", font_med, BLACK, WHITE, 60, 20, center=False)
active_timers = {k: v for k, v in powerup_timers.items() if v > 0}
if active_timers:
draw_powerup_timers(screen, active_timers)
y_ui = 50
if player.can_double_jump:
draw_text_with_outline(screen, "Double Jump Active", font_small, BLUE, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.speed_boost:
draw_text_with_outline(screen, "Speed Boost Active", font_small, GREEN, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.shield_active:
draw_text_with_outline(screen, "Shield Active", font_small, YELLOW, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.supershield_active:
draw_text_with_outline(screen, f"Super Shield Active ({player.supershield_hits_left} hits left)", font_small, SUPER_SHINY_PINK, WHITE, WIDTH - 200, y_ui)
y_ui += 24
if paused:
draw_paused_overlay(screen)
if show_fps:
fps = int(clock.get_fps())
draw_text_with_outline(screen, f"FPS: {fps}", font_small, BLACK, WHITE, 10, HEIGHT - 25, center=False)
elif state == STATE_GAMEOVER:
draw_text_with_outline(screen, "GAME OVER", font_xlarge, RED, BLACK, WIDTH // 2, HEIGHT // 3)
draw_text_with_outline(screen, f"Final Score: {score}", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2)
draw_text_with_outline(screen, "Press R to Restart", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 50)
pygame.display.flip()
if __name__ == "__main__":
main()
What changed:
Powerup spawn weights: [30, 30, 30, 1] → double_jump, speed_boost, shield ≈30% each; supershield ~1%.
Supershield remains the shiny pink cube with glowing effect.
Other logic stays the same as your original game.
Feel free to run this, and supershield should be very rare and shiny pink!
If you want it even rarer or different spawn logic just ask.
Modify PowerUp.draw() to include opsheild: python Copy code
elif self.power_type == "opsheild":
glow_radius = player_size
glow_surf = pygame.Surface((glow_radius * 4, glow_radius * 4), pygame.SRCALPHA)
for i in range(3, 0, -1):
alpha = 40 * i
rect = pygame.Rect(
glow_radius - i * 6,
glow_radius - i * 6,
self.rect.width + i * 12,
self.rect.height + i * 12,
)
pygame.draw.rect(glow_surf, (*OPSHEILD_COLOR[:3], alpha), rect, border_radius=4)
surface.blit(glow_surf, (self.rect.x - glow_radius * 1.5, self.rect.y - glow_radius * 1.5))
pygame.draw.rect(surface, OPSHEILD_COLOR, self.rect, border_radius=4)
Show opsheild glow around player in Player.draw(): python Copy code
if self.opsheild_active:
pygame.draw.ellipse(surface, OPSHEILD_COLOR, self.rect.inflate(18, 18), 5)
Track shield streak in main() python Copy code
consecutive_shields_collected = 0
Inside the powerup collection area, when player picks up a powerup:
python Copy code
if pu.power_type == "shield":
consecutive_shields_collected += 1
if consecutive_shields_collected == 6:
# Grant opsheild immediately
player.opsheild_active = True
player.opsheild_time_left = OPSHEILD_DURATION_FRAMES
player.opsheild_hits_left = OPSHEILD_HITS
powerup_timers['opsheild'] = OPSHEILD_DURATION_FRAMES
consecutive_shields_collected = 0 # reset
# Optional: play sound or show message for opsheild gain here
elif pu.power_type == "opsheild":
# If player picks opsheild powerup (very rare), also reset counter
consecutive_shields_collected = 0
else:
# Any other powerup picked resets consecutive shield count.
consecutive_shields_collected = 0
Modify powerup spawn (very rare opsheild) python Copy code
pu_type = random.choices(
["double_jump", "speed_boost", "shield", "supershield", "opsheild"],
weights=[30, 30, 30, 1, 0.1], # opsheild ~0.1%
k=1
)[0]
Handle opsheild effects on killblock collision In killblock collision check (in main loop):
python Copy code
if player.opsheild_active:
player.opsheild_hits_left -= 1
if player.opsheild_hits_left <= 0:
player.opsheild_active = False
powerup_timers['opsheild'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
elif player.supershield_active:
# existing supershield code ...
Decrease opsheild timer like others: python Copy code
elif key == 'opsheild':
player.opsheild_active = False
player.opsheild_hits_left = 0
Show opsheild active status in UI (in playing state drawing): python Copy code
if player.opsheild_active:
draw_text_with_outline(
screen,
f"OPSheild Active ({player.opsheild_hits_left} hits left)",
font_small,
OPSHEILD_COLOR,
WHITE,
WIDTH - 220,
y_ui
)
y_ui += 24
Full updated code below python Copy code
import pygame
import random
import sys
import time
pygame.init()
# Constants
WIDTH, HEIGHT = 600, 400
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Cube Runnin'")
# Fonts
font_small = pygame.font.SysFont(None, 24)
font_med = pygame.font.SysFont(None, 36)
font_large = pygame.font.SysFont(None, 48)
font_xlarge = pygame.font.SysFont(None, 72)
# Colors
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
RED = (255, 0, 0)
DARK_RED = (180, 0, 0)
GREEN = (0, 255, 0)
YELLOW = (255, 255, 0) # Shield color
BLACK = (0, 0, 0)
GRAY = (200, 200, 200)
TRANSPARENT_BLACK_180 = (0, 0, 0, 180)
SPEED_GLOW_COLOR = (50, 255, 50)
SUPER_SHINY_PINK = (255, 100, 180) # supershield pink glow color
OPSHEILD_COLOR = (180, 30, 90) # opshield dark pink
# Game settings
clock = pygame.time.Clock()
FPS = 60
floor_height = 40
player_size = 20
gravity = 1
jump_speed = 15
base_move_speed = 5
# States
STATE_MENU = 0
STATE_PLAYING = 1
STATE_PAUSED = 2
STATE_GAMEOVER = 3
STATE_SETTINGS = 4 # added settings state
# Power-up durations in frames
POWERUP_DURATION_FRAMES = FPS * 30 # 30 seconds (double jump, speed boost)
SHIELD_DURATION_FRAMES = FPS * 10 # 10 seconds (shield)
SUPERSHIELD_DURATION_FRAMES = FPS * 30 # 30 seconds supershield
OPSHEILD_DURATION_FRAMES = FPS * 45 # 45 seconds opshield
OPSHEILD_HITS = 5
def draw_text_with_outline(surface, text, font, color, outline_color, x, y, center=True):
text_surface = font.render(text, True, color)
outline_surf = font.render(text, True, outline_color)
if center:
rect = text_surface.get_rect(center=(x, y))
else:
rect = text_surface.get_rect(topleft=(x, y))
# Draw outline
outline_positions = [(rect.x - 1, rect.y), (rect.x + 1, rect.y), (rect.x, rect.y - 1), (rect.x, rect.y + 1)]
for pos in outline_positions:
surface.blit(outline_surf, pos)
surface.blit(text_surface, rect)
class Player:
def __init__(self):
self.rect = pygame.Rect(WIDTH // 2, HEIGHT - floor_height - player_size, player_size, player_size)
self.dy = 0
self.on_floor = True
self.can_double_jump = False
self.double_jump_available = False
self.speed_boost = False
self.shield_active = False
self.supershield_active = False
self.opsheild_active = False
self.speed_boost_time_left = 0
self.shield_time_left = 0
self.supershield_time_left = 0
self.supershield_hits_left = 0
self.opsheild_time_left = 0
self.opsheild_hits_left = 0
def jump(self):
if self.on_floor:
self.dy = -jump_speed
self.on_floor = False
self.double_jump_available = self.can_double_jump
elif self.double_jump_available:
self.dy = -jump_speed
self.double_jump_available = False
def move(self, dx):
self.rect.x += dx
if self.rect.x < 0:
self.rect.x = 0
if self.rect.x > WIDTH - player_size:
self.rect.x = WIDTH - player_size
def update(self, floors):
self.dy += gravity
self.rect.y += self.dy
collided_floor = None
for floor in floors:
if self.rect.colliderect(floor.rect):
if self.dy >= 0 and self.rect.bottom - self.dy <= floor.rect.top:
self.rect.bottom = floor.rect.top
self.dy = 0
self.on_floor = True
collided_floor = floor
break
else:
self.on_floor = False
if collided_floor and self.dy == 0: # landed, damage floor
if collided_floor.damage():
floors.remove(collided_floor)
if self.rect.y > HEIGHT - floor_height - player_size:
self.rect.y = HEIGHT - floor_height - player_size
self.dy = 0
self.on_floor = True
if self.rect.x < 0:
self.rect.x = 0
elif self.rect.x > WIDTH - player_size:
self.rect.x = WIDTH - player_size
def draw(self, surface):
if self.speed_boost:
glow_radius = player_size * 2
glow_surf = pygame.Surface((glow_radius * 2, glow_radius * 2), pygame.SRCALPHA)
pygame.draw.circle(glow_surf, (*SPEED_GLOW_COLOR, 100), (glow_radius, glow_radius), glow_radius)
surface.blit(glow_surf, (self.rect.centerx - glow_radius, self.rect.centery - glow_radius))
if self.opsheild_active:
pygame.draw.ellipse(surface, OPSHEILD_COLOR, self.rect.inflate(18, 18), 5)
if self.supershield_active:
pygame.draw.ellipse(surface, SUPER_SHINY_PINK, self.rect.inflate(14, 14), 4)
if self.shield_active:
pygame.draw.ellipse(surface, YELLOW, self.rect.inflate(10, 10), 3)
pygame.draw.rect(surface, BLUE, self.rect)
class Floor:
def __init__(self, y):
self.rect = pygame.Rect(0, y, WIDTH, floor_height)
self.max_health = 5
self.health = self.max_health
def draw(self, surface):
health_ratio = self.health / self.max_health
floor_color = (
int(RED[0] * health_ratio + DARK_RED[0] * (1 - health_ratio)),
int(RED[1] * health_ratio + DARK_RED[1] * (1 - health_ratio)),
int(RED[2] * health_ratio + DARK_RED[2] * (1 - health_ratio))
)
pygame.draw.rect(surface, floor_color, self.rect)
bar_width = self.rect.width * 0.3
bar_height = 6
bar_x = (WIDTH - bar_width) / 2
bar_y = self.rect.top - bar_height - 4
pygame.draw.rect(surface, BLACK, (bar_x, bar_y, bar_width, bar_height), 1)
inner_width = bar_width * (self.health / self.max_health)
pygame.draw.rect(surface, GREEN, (bar_x + 1, bar_y + 1, inner_width - 2, bar_height - 2))
def damage(self):
self.health -= 1
return self.health <= 0
class PowerUp:
def __init__(self, x, y, power_type):
self.rect = pygame.Rect(x, y, player_size, player_size)
self.power_type = power_type
self.fall_speed = random.randint(3, 6)
def apply(self, player, timers):
if self.power_type == "double_jump":
player.can_double_jump = True
timers['double_jump'] = POWERUP_DURATION_FRAMES
elif self.power_type == "speed_boost":
player.speed_boost = True
timers['speed_boost'] = POWERUP_DURATION_FRAMES
elif self.power_type == "shield":
player.shield_active = True
timers['shield'] = SHIELD_DURATION_FRAMES
elif self.power_type == "supershield":
player.supershield_active = True
player.supershield_time_left = SUPERSHIELD_DURATION_FRAMES
player.supershield_hits_left = 3
timers['supershield'] = SUPERSHIELD_DURATION_FRAMES
elif self.power_type == "opsheild":
player.opsheild_active = True
player.opsheild_time_left = OPSHEILD_DURATION_FRAMES
player.opsheild_hits_left = OPSHEILD_HITS
timers['opsheild'] = OPSHEILD_DURATION_FRAMES
def update(self):
self.rect.y += self.fall_speed
def draw(self, surface):
if self.power_type == "double_jump":
color = BLUE
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "speed_boost":
color = GREEN
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "shield":
color = YELLOW
pygame.draw.rect(surface, color, self.rect)
elif self.power_type == "supershield":
glow_radius = player_size
glow_surf = pygame.Surface((glow_radius * 4, glow_radius * 4), pygame.SRCALPHA)
for i in range(3, 0, -1):
alpha = 30 * i
rect = pygame.Rect(
glow_radius - i * 6,
glow_radius - i * 6,
self.rect.width + i * 12,
self.rect.height + i * 12,
)
pygame.draw.rect(glow_surf, (*SUPER_SHINY_PINK[:3], alpha), rect, border_radius=4)
surface.blit(glow_surf, (self.rect.x - glow_radius * 1.5, self.rect.y - glow_radius * 1.5))
pygame.draw.rect(surface, SUPER_SHINY_PINK, self.rect, border_radius=4)
elif self.power_type == "opsheild":
glow_radius = player_size
glow_surf = pygame.Surface((glow_radius * 4, glow_radius * 4), pygame.SRCALPHA)
for i in range(3, 0, -1):
alpha = 40 * i
rect = pygame.Rect(
glow_radius - i * 6,
glow_radius - i * 6,
self.rect.width + i * 12,
self.rect.height + i * 12,
)
pygame.draw.rect(glow_surf, (*OPSHEILD_COLOR[:3], alpha), rect, border_radius=4)
surface.blit(glow_surf, (self.rect.x - glow_radius * 1.5, self.rect.y - glow_radius * 1.5))
pygame.draw.rect(surface, OPSHEILD_COLOR, self.rect, border_radius=4)
else:
color = WHITE
pygame.draw.rect(surface, color, self.rect)
class KillBlock:
def __init__(self, x, y):
self.size = 60
self.rect = pygame.Rect(x, y, self.size, self.size)
self.fall_speed = random.randint(4, 7)
def update(self):
self.rect.y += self.fall_speed
if self.rect.top > HEIGHT:
self.rect.x = random.randint(0, WIDTH - self.size)
self.rect.y = -self.size
self.fall_speed = random.randint(4, 7)
def draw(self, surface):
pygame.draw.rect(surface, DARK_RED, self.rect)
def draw_paused_overlay(surface):
overlay = pygame.Surface((WIDTH, HEIGHT), pygame.SRCALPHA)
overlay.fill(TRANSPARENT_BLACK_180)
surface.blit(overlay, (0, 0))
draw_text_with_outline(surface, "PAUSED", font_xlarge, WHITE, BLACK, WIDTH//2, HEIGHT//3)
draw_text_with_outline(surface, "Press ESC to Resume", font_med, WHITE, BLACK, WIDTH//2, HEIGHT//2)
def draw_powerup_timers(surface, timers):
x = 10
y = HEIGHT - 90
bar_width = 140
bar_height = 20
gap = 10
for p_type in timers:
pygame.draw.rect(surface, BLACK, (x, y, bar_width, bar_height))
if p_type == 'shield':
max_frames = SHIELD_DURATION_FRAMES
elif p_type == 'supershield':
max_frames = SUPERSHIELD_DURATION_FRAMES
elif p_type == 'opsheild':
max_frames = OPSHEILD_DURATION_FRAMES
else:
max_frames = POWERUP_DURATION_FRAMES
progress = timers[p_type] / max_frames
color = (
GREEN if p_type == 'speed_boost' else
BLUE if p_type == 'double_jump' else
YELLOW if p_type == 'shield' else
SUPER_SHINY_PINK if p_type == 'supershield' else
OPSHEILD_COLOR if p_type == 'opsheild' else
WHITE
)
pygame.draw.rect(surface, color, (x + 2, y + 2, int((bar_width - 4) * progress), bar_height - 4))
label = f"{p_type.replace('_', ' ').title()}: {timers[p_type] // FPS}s"
draw_text_with_outline(surface, label, font_small, WHITE, BLACK, x + bar_width//2, y + 2 + bar_height//2)
y += bar_height + gap
def draw_settings_menu(surface, show_fps):
draw_text_with_outline(surface, "Settings", font_large, BLACK, WHITE, WIDTH // 2, HEIGHT // 6)
status_fps = "ON" if show_fps else "OFF"
draw_text_with_outline(surface, f"Show FPS: {status_fps} (Press F to toggle)", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 3)
draw_text_with_outline(surface, "Press ESC to return to Menu", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2)
def main():
state = STATE_MENU
paused = False
show_fps = True # Settings option
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {
'double_jump': 0,
'speed_boost': 0,
'shield': 0,
'supershield': 0,
'opsheild': 0,
}
# Track consecutive shields collected in a row
consecutive_shields_collected = 0
button_rect = pygame.Rect(WIDTH // 2 - 100, HEIGHT // 2 - 25, 200, 50)
while True:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if state == STATE_MENU:
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse_pos = pygame.mouse.get_pos()
if button_rect.collidepoint(mouse_pos):
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {k: 0 for k in powerup_timers}
consecutive_shields_collected = 0
state = STATE_PLAYING
paused = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
player = Player()
floors = [Floor(HEIGHT - (i + 1) * floor_height) for i in range(10)]
powerups = []
kill_blocks = []
for i in range(3):
kb_x = random.randint(0, WIDTH - 60)
kb_y = random.randint(-600, -60)
kill_blocks.append(KillBlock(kb_x, kb_y))
score = 0
score_timer = 0
move_speed_current = base_move_speed
powerup_timers = {k: 0 for k in powerup_timers}
consecutive_shields_collected = 0
state = STATE_PLAYING
paused = False
elif event.key == pygame.K_s:
state = STATE_SETTINGS
elif state == STATE_SETTINGS:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
state = STATE_MENU
elif event.key == pygame.K_f:
show_fps = not show_fps
elif state == STATE_PLAYING:
if event.type == pygame.KEYDOWN and not paused:
if event.key in (pygame.K_SPACE, pygame.K_w, pygame.K_UP):
player.jump()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
paused = not paused
elif state == STATE_GAMEOVER:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
state = STATE_MENU
keys = pygame.key.get_pressed()
if state == STATE_PLAYING and not paused:
dx = 0
if keys[pygame.K_a] or keys[pygame.K_LEFT]:
dx -= move_speed_current
if keys[pygame.K_d] or keys[pygame.K_RIGHT]:
dx += move_speed_current
if powerup_timers['speed_boost'] > 0:
dx *= 2
player.move(dx)
player.update(floors)
if random.randint(1, 100) == 1:
pu_type = random.choices(
["double_jump", "speed_boost", "shield", "supershield", "opsheild"],
weights=[30, 30, 30, 1, 0.1], # opsheild very rare ~0.1%
k=1
)[0]
powerups.append(PowerUp(random.randint(0, WIDTH - player_size), -player_size, pu_type))
for pu in powerups[:]:
pu.update()
if pu.rect.top > HEIGHT:
pu.rect.x = random.randint(0, WIDTH - player_size)
pu.rect.y = -player_size
pu.fall_speed = random.randint(3, 6)
elif player.rect.colliderect(pu.rect):
pu.apply(player, powerup_timers)
score += 1
# Track consecutive shields
if pu.power_type == "shield":
consecutive_shields_collected += 1
if consecutive_shields_collected == 6:
# Grant opsheild immediately
player.opsheild_active = True
player.opsheild_time_left = OPSHEILD_DURATION_FRAMES
player.opsheild_hits_left = OPSHEILD_HITS
powerup_timers['opsheild'] = OPSHEILD_DURATION_FRAMES
consecutive_shields_collected = 0
elif pu.power_type == "opsheild":
consecutive_shields_collected = 0
else:
consecutive_shields_collected = 0
powerups.remove(pu)
for kb in kill_blocks:
kb.update()
if player.rect.colliderect(kb.rect):
if player.opsheild_active:
player.opsheild_hits_left -= 1
if player.opsheild_hits_left <= 0:
player.opsheild_active = False
powerup_timers['opsheild'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
elif player.supershield_active:
player.supershield_hits_left -= 1
if player.supershield_hits_left <= 0:
player.supershield_active = False
powerup_timers['supershield'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
elif player.shield_active:
player.shield_active = False
powerup_timers['shield'] = 0
kb.rect.x = random.randint(0, WIDTH - kb.size)
kb.rect.y = -kb.size
kb.fall_speed = random.randint(4, 7)
else:
state = STATE_GAMEOVER
for key in powerup_timers:
if powerup_timers[key] > 0:
powerup_timers[key] -= 1
if powerup_timers[key] == 0:
if key == 'double_jump':
player.can_double_jump = False
player.double_jump_available = False
elif key == 'speed_boost':
player.speed_boost = False
elif key == 'shield':
player.shield_active = False
elif key == 'supershield':
player.supershield_active = False
player.supershield_hits_left = 0
elif key == 'opsheild':
player.opsheild_active = False
player.opsheild_hits_left = 0
score_timer += 1
if score_timer >= 10:
score += 1
score_timer = 0
screen.fill(WHITE)
if state == STATE_MENU:
draw_text_with_outline(screen, "Cube Runnin'", font_large, BLACK, WHITE, WIDTH // 2, HEIGHT // 4)
pygame.draw.rect(screen, GRAY, button_rect)
draw_text_with_outline(screen, "PLAY GAME", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 - 12)
draw_text_with_outline(screen, "Move: A/D or Arrows, Jump: W/Up/Space", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 50)
draw_text_with_outline(screen, "Avoid falling red blocks! Collect powerups!", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 80)
draw_text_with_outline(screen, "Press S for Settings", font_small, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 110)
elif state == STATE_SETTINGS:
draw_settings_menu(screen, show_fps)
elif state == STATE_PLAYING:
for floor in floors:
floor.draw(screen)
for kb in kill_blocks:
kb.draw(screen)
for pu in powerups:
pu.draw(screen)
player.draw(screen)
draw_text_with_outline(screen, f"Score: {score}", font_med, BLACK, WHITE, 60, 20, center=False)
active_timers = {k: v for k, v in powerup_timers.items() if v > 0}
if active_timers:
draw_powerup_timers(screen, active_timers)
y_ui = 50
if player.can_double_jump:
draw_text_with_outline(screen, "Double Jump Active", font_small, BLUE, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.speed_boost:
draw_text_with_outline(screen, "Speed Boost Active", font_small, GREEN, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.shield_active:
draw_text_with_outline(screen, "Shield Active", font_small, YELLOW, WHITE, WIDTH - 150, y_ui)
y_ui += 24
if player.supershield_active:
draw_text_with_outline(screen, f"Super Shield Active ({player.supershield_hits_left} hits left)", font_small, SUPER_SHINY_PINK, WHITE, WIDTH - 200, y_ui)
y_ui += 24
if player.opsheild_active:
draw_text_with_outline(screen, f"OPSheild Active ({player.opsheild_hits_left} hits left)", font_small, OPSHEILD_COLOR, WHITE, WIDTH - 220, y_ui)
y_ui += 24
if paused:
draw_paused_overlay(screen)
if show_fps:
fps = int(clock.get_fps())
draw_text_with_outline(screen, f"FPS: {fps}", font_small, BLACK, WHITE, 10, HEIGHT - 25, center=False)
elif state == STATE_GAMEOVER:
draw_text_with_outline(screen, "GAME OVER", font_xlarge, RED, BLACK, WIDTH // 2, HEIGHT // 3)
draw_text_with_outline(screen, f"Final Score: {score}", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2)
draw_text_with_outline(screen, "Press R to Restart", font_med, BLACK, WHITE, WIDTH // 2, HEIGHT // 2 + 50)
pygame.display.flip()
if __name__ == "__main__":
main()
Summary
Track and count shield pickups in a row.
On 6 shields collected consecutively: grant an opshield instantly.
Opshield powerup drops insanely rare (~0.1%).
Opshield lasts 45 seconds and survives 5 hits.
Different colors for supershield (pink) and opshield (dark pink).
Proper UI and drawing for opshield and updating hit counts.
If you want me to add any special message on getting opshield or tweak balance, just ask!