Added config to increase or decrease game speed when score rising

This commit is contained in:
Anry Das 2025-11-16 09:12:29 +02:00
parent 836f635a6b
commit a04e422547
3 changed files with 20 additions and 8 deletions

View File

@ -65,6 +65,7 @@
} }
}, },
"store_width": 10, "store_width": 10,
"block_size": 30 "block_size": 30,
"high_score_inc_speed": true
} }
} }

View File

@ -220,12 +220,20 @@ class TetrisGame:
elapsed = (current_ticks - self.last_time) / 1000.0 # Convert to seconds elapsed = (current_ticks - self.last_time) / 1000.0 # Convert to seconds
self.last_time = current_ticks self.last_time = current_ticks
if self.score > 5000: if cfg.HIGH_SCORE_INC_SPEED:
self.fall_speed = 0.55 if self.score > 5000:
elif self.score > 10000: self.fall_speed = 0.55
self.fall_speed = 0.6 elif self.score > 10000:
elif self.score > 15000: self.fall_speed = 0.6
self.fall_speed = 0.65 elif self.score > 15000:
self.fall_speed = 0.65
else:
if self.score > 5000:
self.fall_speed = 0.45
elif self.score > 10000:
self.fall_speed = 0.4
elif self.score > 15000:
self.fall_speed = 0.35
if not self.game_over and not self.paused: if not self.game_over and not self.paused:
self.fall_time += elapsed self.fall_time += elapsed

View File

@ -133,6 +133,8 @@ COLORS = {
'game_over': (255, 0, 0) 'game_over': (255, 0, 0)
} }
HIGH_SCORE_INC_SPEED = False
def store_config(): def store_config():
blocks_to_save = {'ALL_BLOCKS': BlockType} blocks_to_save = {'ALL_BLOCKS': BlockType}
@ -151,7 +153,7 @@ def store_config():
def load_config(): def load_config():
global KEY_CONFIG, COLORS, CONTROLS_TEXT, STORE_WIDTH, BLOCK_SIZE, BLOCK_TYPE global KEY_CONFIG, COLORS, CONTROLS_TEXT, STORE_WIDTH, BLOCK_SIZE, BLOCK_TYPE, HIGH_SCORE_INC_SPEED
es = EnumSerializer es = EnumSerializer
if not os.path.isfile(CONFIG_JSON) or not os.path.isfile(CONFIG_JSON) : if not os.path.isfile(CONFIG_JSON) or not os.path.isfile(CONFIG_JSON) :
@ -164,6 +166,7 @@ def load_config():
COLORS = config_data['CONFIG']['colors'] COLORS = config_data['CONFIG']['colors']
STORE_WIDTH = config_data['CONFIG']['store_width'] STORE_WIDTH = config_data['CONFIG']['store_width']
BLOCK_SIZE = config_data['CONFIG']['block_size'] BLOCK_SIZE = config_data['CONFIG']['block_size']
HIGH_SCORE_INC_SPEED = True if str(config_data['CONFIG']['high_score_inc_speed']).lower() == 'true' else False
with open(CONFIG_BLOCKS_JSON) as block_fd: with open(CONFIG_BLOCKS_JSON) as block_fd:
blocks_data = json.load(block_fd) blocks_data = json.load(block_fd)