-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
66 lines (56 loc) · 2.17 KB
/
settings.py
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
class Settings:
"""Auxiliary class for all settings of Alien Warfare"""
def __init__(self):
"""Setup game settings"""
# Main Surface
self.main_width = 1200
self.main_height = 800
self.background_color = (0, 0, 128)
# Ship
self.ship_limit = 3
# Bullet
self.bullet_width = 10
self.bullet_height = 20
self.bullet_color = (255, 0, 0)
self.bullets_limit = 3
# Buttons
self.play_button_color = (0, 200, 0)
self.easy_button_color = (0, 255, 0)
self.normal_button_color = (255, 165, 0)
self.hard_button_color = (255, 0, 0)
# Adjustable difficulty
self.difficulty = 1.05
# Rate of change
self.speedup_scale = 1.1
# Alien points rate of change
self.alien_points_speedup_scale = 2 * self.speedup_scale
# Dynamic settings
self.initialize_dynamic_settings()
def _set_difficulty(self, button_color):
"""Sets difficulty based on button click"""
# Reset difficulty
self.difficulty = 1.05
# Set difficulty based on button click
match button_color:
case self.easy_button_color:
self.difficulty -= 0.05
case self.hard_button_color:
self.difficulty += 0.05
case _:
pass
def initialize_dynamic_settings(self):
"""Initialize settings that change throughout the game."""
self.spaceship_speed = 2 * self.difficulty
self.bullet_speed = 2 * self.difficulty
self.alien_speed = 0.5 * self.difficulty
self.fleet_direction = 1 # 1 -> Right, -1 -> Left
self.fleet_drop_speed = 10 * self.difficulty
self.speedup_scale = 1.1 * self.difficulty
self.alien_points = 50 * self.difficulty
def increase_speed(self):
"""Increase dynamic settings."""
self.spaceship_speed *= self.speedup_scale
self.bullet_speed *= self.speedup_scale
self.alien_speed *= self.speedup_scale
self.fleet_drop_speed += int(self.speedup_scale)
self.alien_points = int(self.alien_points * self.alien_points_speedup_scale)