Dojo Defender Sessie 6: Cheatsheet
Boss starten
def start_boss():
global boss_active, boss, boss_hp, boss_phase
boss_active = True
boss = GameObject('boss.png', WIDTH / 2, -80)
boss_hp = 50
boss_phase = "PHASE_1"
...
def check_boss_wave():
if wave >= 5 and wave % 5 == 0 and not boss_active:
start_boss()
Boss AI — state machine
if boss.rect.centery < 80:
boss.rect.centery += 2
else:
if boss_phase == "PHASE_1":
# Langzaam drijven, af en toe een kogel
boss.rect.centerx += boss_direction * 1.5
if boss_shoot_timer >= 60:
fire_boss_bullet()
elif boss_phase == "PHASE_2":
# Sneller + minions
boss.rect.centerx += boss_direction * 3
if boss_shoot_timer >= 40:
fire_boss_bullet()
if boss_minion_spawn_timer >= 180:
spawn_boss_minion()
elif boss_phase == "PHASE_3":
# Enraged + screen shake
boss.rect.centerx += boss_direction * 4
if boss_shoot_timer >= 20:
fire_boss_bullet()
Fase-overgang
hp_ratio = boss_hp / boss_hp_max
if hp_ratio <= 0.66 and boss_phase == "PHASE_1":
boss_phase = "PHASE_2"
boss_phase_transition_timer = 20
if hp_ratio <= 0.33 and boss_phase == "PHASE_2":
boss_phase = "PHASE_3"
boss_phase_transition_timer = 20
Laatste fase check
if hp_ratio <= 0.33 and boss_phase == "PHASE_2":
boss_phase = "PHASE_3"
boss_phase_transition_timer = 20
Doelzoekende kogel
def fire_boss_bullet():
dx = ship.rect.centerx - boss.rect.centerx
dy = ship.rect.centery - boss.rect.centery
dist = math.sqrt(dx * dx + dy * dy)
if dist == 0: dist = 1
boss_bullets.append({
'x': boss.rect.centerx,
'y': boss.rect.centery + 30,
'vx': dx / dist * 3,
'vy': dy / dist * 3,
})
Screen shake
# In update:
if boss_phase == "PHASE_3":
screen_shake_x = random.randint(-3, 3)
screen_shake_y = random.randint(-3, 3)
# In draw, overal een offset toevoegen:
draw_stars(screen, screen_shake_x, screen_shake_y)
HP-balk
bar_width, bar_height = 300, 20
bar_x = (WIDTH - bar_width) // 2
bar_y = 10
pygame.draw.rect(screen, (100, 20, 20), (bar_x, bar_y, bar_width, bar_height))
hp_ratio = max(0, boss_hp / boss_hp_max)
fill_width = int(bar_width * hp_ratio)
color = (0, 255, 0) if hp_ratio > 0.5 else (255, 255, 0) if hp_ratio > 0.25 else (255, 0, 0)
pygame.draw.rect(screen, color, (bar_x, bar_y, fill_width, bar_height))
pygame.draw.rect(screen, (255, 255, 255), (bar_x, bar_y, bar_width, bar_height), 2)
Boss defeated
if boss_hp <= 0:
boss_phase = "EXPLODING"
boss_defeated_timer = 90
score += 500
if boss_phase == "EXPLODING":
if boss_phase_transition_timer % 10 == 0:
spawn_particles(...)