44import threading
55import queue
66from simple_framework import SimpleSettingsWindow , SimpleWindowScaler , SimplePygameField , SimplePygameButton , SimpleImageButton
7-
87from os import getcwd
98print (getcwd ())
109
@@ -491,12 +490,12 @@ def __init__(self, game, background, banned_plants):
491490 self .banned_plants = banned_plants
492491 self .seed_bank_bg = pygame .image .load ('images/SeedBank.png' )
493492 # Scale by 1.8 like seedbank
494- self .seed_bank_bg = pygame .transform .scale (self .seed_bank_bg , (self .seed_bank_bg .get_width () * 1.8 , self .seed_bank_bg .get_height () * 1.8 ))
493+ self .seed_bank_bg = pygame .transform .smoothscale (self .seed_bank_bg , (self .seed_bank_bg .get_width () * 1.8 , self .seed_bank_bg .get_height () * 1.8 ))
495494
496495 # Load seed chooser background
497496 self .seed_chooser_bg = pygame .image .load ('images/SeedChooser_Background.png' )
498497 # Scale by 1.8 like seedbank
499- self .seed_chooser_bg = pygame .transform .scale (self .seed_chooser_bg , (self .seed_chooser_bg .get_width () * 1.8 , self .seed_chooser_bg .get_height () * 1.8 ))
498+ self .seed_chooser_bg = pygame .transform .smoothscale (self .seed_chooser_bg , (self .seed_chooser_bg .get_width () * 1.8 , self .seed_chooser_bg .get_height () * 1.8 ))
500499
501500 # Seed selection data
502501 self .all_plants = [p for p in PLANT_SUN_COST .keys () if p in self .game .user ['unlocked_plants' ] and p not in self .banned_plants ]
@@ -529,7 +528,7 @@ def __init__(self, game, background, banned_plants):
529528 def toggle_plant_selection (self , plant ):
530529 if plant in self .selected_plants :
531530 self .selected_plants .remove (plant )
532- elif len (self .selected_plants ) < 6 :
531+ elif len (self .selected_plants ) < self . game . user [ 'max_seeds' ] :
533532 self .selected_plants .append (plant )
534533 self .update_start_button ()
535534
@@ -569,12 +568,12 @@ def draw_seed_bank(self, screen):
569568 offset = self .game .scaler .scale_x (5 * 2 )
570569 for i , seed_name in enumerate (self .selected_plants ):
571570 rect = pygame .Rect (seed_x_start + i * (seed_w + offset ), seed_y , seed_w , seed_h )
572- scaled_seed = pygame .transform .scale (self .game .seed_image , (seed_w , seed_h ))
571+ scaled_seed = pygame .transform .smoothscale (self .game .seed_image , (seed_w , seed_h ))
573572 screen .blit (scaled_seed , rect )
574573 # Draw plant icon on top
575574 if seed_name in self .game .plant_icons :
576575 icon = self .game .plant_icons [seed_name ]
577- scaled_icon = pygame .transform .scale (icon , (int (seed_w * 0.8 ), int (seed_h * 0.6 )))
576+ scaled_icon = pygame .transform .smoothscale (icon , (int (seed_w * 0.8 ), int (seed_h * 0.6 )))
578577 icon_rect = scaled_icon .get_rect (center = rect .center )
579578 screen .blit (scaled_icon , icon_rect )
580579 # Draw white border to indicate selected
@@ -617,13 +616,13 @@ def draw(self, screen):
617616 # Draw seed packets and plant icons on buttons
618617 for i , button in enumerate (self .plant_buttons ):
619618 # Draw seed packet background
620- scaled_seed = pygame .transform .scale (self .game .seed_image , (button .size [0 ], button .size [1 ]))
619+ scaled_seed = pygame .transform .smoothscale (self .game .seed_image , (button .size [0 ], button .size [1 ]))
621620 screen .blit (scaled_seed , button .position )
622621 # Draw plant icon on top
623622 plant_name = self .all_plants [i ]
624623 if plant_name in self .game .plant_icons :
625624 icon = self .game .plant_icons [plant_name ]
626- scaled_icon = pygame .transform .scale (icon , (int (button .size [0 ] * 0.8 ), int (button .size [1 ] * 0.6 )))
625+ scaled_icon = pygame .transform .smoothscale (icon , (int (button .size [0 ] * 0.8 ), int (button .size [1 ] * 0.6 )))
627626 icon_rect = scaled_icon .get_rect (center = (button .position [0 ] + button .size [0 ] // 2 , button .position [1 ] + button .size [1 ] // 2 ))
628627 screen .blit (scaled_icon , icon_rect )
629628 # Draw border if selected
@@ -803,7 +802,7 @@ def __init__(self, game, level_name):
803802
804803 def draw_hotbar (self , screen ):
805804 # Draw hotbar background image
806- scaled_seedbank = pygame .transform .scale (self .game .seedbank_image , (self .game .scaler .scale_x (self .game .seedbank_image .get_width ()), self .game .scaler .scale_y (self .game .seedbank_image .get_height ())))
805+ scaled_seedbank = pygame .transform .smoothscale (self .game .seedbank_image , (self .game .scaler .scale_x (self .game .seedbank_image .get_width ()), self .game .scaler .scale_y (self .game .seedbank_image .get_height ())))
807806 screen .blit (scaled_seedbank , (0 , 0 ))
808807 # Draw sun count
809808 sun_text = self .game .small_font .render (f"{ self .sun_count } " , True , "#000000" )
@@ -825,11 +824,11 @@ def draw_hotbar(self, screen):
825824 for i , seed in enumerate (self .game .seed_packets ):
826825 rect = pygame .Rect (seed_x_start + i * (seed_w + offset ), seed_y , seed_w , seed_h )
827826 # Draw seed packet background
828- scaled_seed = pygame .transform .scale (self .game .seed_image , (seed_w , seed_h ))
827+ scaled_seed = pygame .transform .smoothscale (self .game .seed_image , (seed_w , seed_h ))
829828 screen .blit (scaled_seed , rect )
830829 # Draw plant icon on top
831830 icon = seed ['icon' ]
832- scaled_icon = pygame .transform .scale (icon , (int (seed_w * 1 ), int (seed_h * 0.7 )))
831+ scaled_icon = pygame .transform .smoothscale (icon , (int (seed_w * 1 ), int (seed_h * 0.7 )))
833832 icon_rect = scaled_icon .get_rect (center = rect .center )
834833 screen .blit (scaled_icon , icon_rect )
835834 # Highlight selected seed
@@ -863,9 +862,9 @@ def draw_hotbar(self, screen):
863862 # Draw shovel
864863 shovel_x = seed_x_start + len (self .game .seed_packets ) * (seed_w + offset ) + 50
865864 shovel_rect = pygame .Rect (shovel_x , seed_y , 140 , 144 )
866- scaled_shovel_bank = pygame .transform .scale (self .game .shovel_bank_image , (140 , 144 ))
865+ scaled_shovel_bank = pygame .transform .smoothscale (self .game .shovel_bank_image , (140 , 144 ))
867866 screen .blit (scaled_shovel_bank , shovel_rect )
868- scaled_shovel_icon = pygame .transform .scale (self .game .shovel_image , (120 , 120 ))
867+ scaled_shovel_icon = pygame .transform .smoothscale (self .game .shovel_image , (120 , 120 ))
869868 icon_rect = scaled_shovel_icon .get_rect (center = shovel_rect .center )
870869 screen .blit (scaled_shovel_icon , icon_rect )
871870 if self .selected_shovel :
@@ -1115,11 +1114,11 @@ def draw_flag_meter(self, screen):
11151114 frame_height = self .game .flag_meter_image .get_height () // 2
11161115 empty_frame = self .game .flag_meter_image .subsurface ((0 , 0 , frame_width , frame_height ))
11171116 filled_frame = self .game .flag_meter_image .subsurface ((0 , frame_height , frame_width , frame_height ))
1118- scale = 0.6
1119- empty_scaled = pygame .transform .scale (empty_frame , (int (frame_width * scale ), int (frame_height * scale )))
1120- filled_scaled = pygame .transform .scale (filled_frame , (int (frame_width * scale ), int (frame_height * scale )))
1121- bar_width = int (frame_width * scale )
1122- bar_height = int (frame_height * scale )
1117+ smoothscale = 0.6
1118+ empty_scaled = pygame .transform .smoothscale (empty_frame , (int (frame_width * smoothscale ), int (frame_height * smoothscale )))
1119+ filled_scaled = pygame .transform .smoothscale (filled_frame , (int (frame_width * smoothscale ), int (frame_height * smoothscale )))
1120+ bar_width = int (frame_width * smoothscale )
1121+ bar_height = int (frame_height * smoothscale )
11231122 x = self .game .width - bar_width - 20 # 20 px padding from right
11241123 y = self .game .height - bar_height - 20 # 20 px padding from bottom
11251124
@@ -1158,7 +1157,7 @@ def draw(self, screen):
11581157 if icon :
11591158 preview = icon .copy ()
11601159 preview .set_alpha (128 )
1161- scaled_preview = pygame .transform .scale (preview , (int (self .game_field .cell_width * 0.8 ), int (self .game_field .cell_height * 0.8 )))
1160+ scaled_preview = pygame .transform .smoothscale (preview , (int (self .game_field .cell_width * 0.8 ), int (self .game_field .cell_height * 0.8 )))
11621161 cell_x = self .game_field .field_x + col * self .game_field .cell_width
11631162 cell_y = self .game_field .field_y + row * self .game_field .cell_height
11641163 center_x = cell_x + (self .game_field .cell_width - scaled_preview .get_width ()) // 2
@@ -1174,7 +1173,7 @@ def draw(self, screen):
11741173 zombie .draw (screen )
11751174 if self .selected_shovel :
11761175 mouse_pos = pygame .mouse .get_pos ()
1177- cursor_shovel = pygame .transform .scale (self .game .shovel_image , (40 , 40 ))
1176+ cursor_shovel = pygame .transform .smoothscale (self .game .shovel_image , (40 , 40 ))
11781177 screen .blit (cursor_shovel , (mouse_pos [0 ] - cursor_shovel .get_width () // 2 , mouse_pos [1 ] - cursor_shovel .get_height () // 2 ))
11791178 if self .debug_mode :
11801179 # draw wave and points
@@ -1398,6 +1397,7 @@ def parse_lawnstrings(filepath):
13981397 # Initialize pygame
13991398 pygame .init ()
14001399 self .screen = pygame .display .set_mode ((self .width , self .height ))
1400+
14011401 pygame .display .set_caption ("Plants vs Zombies Python Edition" )
14021402
14031403 # Load levels
@@ -1411,13 +1411,17 @@ def parse_lawnstrings(filepath):
14111411 self .user ['completed_levels' ] = set (self .user ['completed_levels' ])
14121412 if 'coins' not in self .user :
14131413 self .user ['coins' ] = 0
1414+ if 'max_seeds' not in self .user :
1415+ self .user ['max_seeds' ] = 6
1416+ if 'seed_upgrade_count' not in self .user :
1417+ self .user ['seed_upgrade_count' ] = 0
14141418 except FileNotFoundError :
1415- self .user = {'completed_levels' : set (), 'unlocked_plants' : ['Peashooter' ], 'coins' : 0 }
1419+ self .user = {'completed_levels' : set (), 'unlocked_plants' : ['Peashooter' ], 'coins' : 0 , 'max_seeds' : 6 , 'seed_upgrade_count' : 0 }
14161420
14171421 # Load images
14181422 self .seedbank_image = pygame .image .load ('images/seedbank.png' )
14191423 # Scale seedbank by 2
1420- self .seedbank_image = pygame .transform .scale (self .seedbank_image , (self .seedbank_image .get_width () * 1.8 , self .seedbank_image .get_height () * 1.8 ))
1424+ self .seedbank_image = pygame .transform .smoothscale (self .seedbank_image , (self .seedbank_image .get_width () * 1.8 , self .seedbank_image .get_height () * 1.8 ))
14211425 self .flag_meter_image = pygame .image .load ('images/FlagMeter.png' )
14221426 seeds_image = pygame .image .load ('images/seeds.png' )
14231427 # Extract the third seed image (0-indexed as 2)
@@ -1427,9 +1431,9 @@ def parse_lawnstrings(filepath):
14271431 self .shovel_bank_image = pygame .image .load ('images/ShovelBank.png' )
14281432 self .shovel_image = pygame .image .load ('images/Shovel.png' )
14291433 # Scale shovel bank to match seed packet size (will be scaled per draw)
1430- self .shovel_bank_image = pygame .transform .scale (self .shovel_bank_image , (50 * 1.8 , 70 * 1.8 ))
1434+ self .shovel_bank_image = pygame .transform .smoothscale (self .shovel_bank_image , (50 * 1.8 , 70 * 1.8 ))
14311435 # Scale shovel icon appropriately
1432- self .shovel_image = pygame .transform .scale (self .shovel_image , (40 * 1.8 , 40 * 1.8 ))
1436+ self .shovel_image = pygame .transform .smoothscale (self .shovel_image , (40 * 1.8 , 40 * 1.8 ))
14331437
14341438 # Load plant icons
14351439 self .plant_icons = {
@@ -1517,7 +1521,7 @@ def load_background(self):
15171521 total_width = scaled_bg_width * tile_count
15181522 self .scaled_background = pygame .Surface ((total_width , scaled_bg_height ))
15191523 for i in range (tile_count ):
1520- self .scaled_background .blit (pygame .transform .scale (background_image , (scaled_bg_width , scaled_bg_height )), (i * scaled_bg_width , 0 ))
1524+ self .scaled_background .blit (pygame .transform .smoothscale (background_image , (scaled_bg_width , scaled_bg_height )), (i * scaled_bg_width , 0 ))
15211525
15221526 def draw_background (self , screen , offset_x ):
15231527 width_to_blit = min (self .width , self .scaled_background .get_width ())
0 commit comments