Skip to content

Commit 8956965

Browse files
committed
radically changed the way the code works
1 parent 7fce797 commit 8956965

23 files changed

+1264
-1292
lines changed

bodies_functions.py

-101
This file was deleted.

config.py

+30-116
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,58 @@
11
TEST_MODE = False
2-
STRAIGHTFORWARD_FIX = True
32

4-
from math import sqrt
5-
6-
# Common settings for windows
3+
# Constants to make the code cleaner
74
TITLE = 'Smiling Zombies'
8-
9-
# Window settings
10-
FPS = 200
11-
12-
# Scale
13-
SPEED_LABEL = 'Speed'
14-
VISION_DISTANCE_LABEL = 'Vision\ndistance'
15-
5+
PAUSE_RESUME = 'Use your right mouse button in order to pause/resume the evolution.'
166
WHAT_A_WONDERFUL_GAME = 'What a wonderful game!'
7+
SMILIES = 'smilies'
8+
PLANTS = 'plants'
179

1810
SPEED = 0
1911
VISION_DISTANCE = 1
2012

2113
RUN = 0
2214
PAUSE = 1
2315

24-
# Help maintenance
25-
GEOMETRY_RATIO = 0.7
26-
POPULATED_ROOM = 80 # Room populated by the bottom items of the help window (defined experimentally)
27-
HELP_SCROLLED_TEXT_FONT_SIZE = 10 # The initial height of the letters in points
28-
SCROLLED_TEXT_FONT_SIZE_IN_PIXELS = HELP_SCROLLED_TEXT_FONT_SIZE*1.3333 # Retrieving the text with its size being transformed from points into pixels (1.333 must not be changed)
29-
SCROLLED_FONT_SIZE_GAP_HEIGHT = SCROLLED_TEXT_FONT_SIZE_IN_PIXELS*1.13 # Retrieving the height of lines (the factor must not be changed)
30-
LETTER_WIDTH = SCROLLED_TEXT_FONT_SIZE_IN_PIXELS/2 # Retrieving the width of letters (the divisior must not be changed)
31-
TEXT_COLOR = '#ffffff'
32-
HELP_WINDOW_BG = '#303030'
33-
34-
# Bodies
35-
# Shapes
36-
BODY_SIZE = 14 if STRAIGHTFORWARD_FIX else 10
37-
OLD_VISION_DISTANCE = 75 # A satisfying value for the size of the evolution field being {'width': 950, 'height': 500}
38-
DOUBLE_BODY_SIZE = BODY_SIZE*2
39-
40-
NEWLY_BORN_PERIOD = 4 # In seconds
41-
42-
CIRCLE = 0
43-
SQUARE = 1
44-
RHOMBUS = 2
45-
46-
# Rhombus shape
47-
RHOMBUS_SIZE = BODY_SIZE*1.4
48-
HALF_RHOMBUS_SIZE = RHOMBUS_SIZE/2
49-
50-
# Food preference
51-
BODY = 'bodies'
52-
PLANT = 'plants'
53-
54-
# Status
5516
SLEEPING = 0
5617
RUNNING_AWAY = 1
5718
FOLLOWING_PLANT = 2
58-
FOLLOWING_BODY = 3
19+
FOLLOWING_SMILEY = 3
5920

6021
CONTROL_PREPARATION = 0
61-
DELETE_EVERYTHING = 1
22+
DELETE_ERASE_EVERYTHING = 1
6223
EVOLUTION_PREPARATION = 2
6324
EVOLUTION = 3
64-
USER_SELECTING_BODY = 4
65-
PAUSED = 5
25+
USER_SELECTING_ZOMBIE_BOSS = 4
26+
RESULTS = 5
27+
PAUSED = 6
6628

67-
FROM = 0
68-
TO = 1
29+
BOSS = 0
30+
SMILEY = 1
6931

70-
# Tips
71-
PAUSE_RESUME = 'Use your right mouse button in order to pause/resume the evolution.'
32+
NO_CREATURES = 0
33+
SQUARES_ONE_SPECIES_WON = 1
34+
ALL_ZOMBIES = 2
35+
ONLY_ZOMBIE_BOSS = 3
7236

73-
# Related to plants
74-
PLANT_ENERGY = 100
75-
PLANT_PREFERENCE_CHANCE = 0.5 # The chance that the body will prefer eating plant
76-
PROCREATION_THRESHOLD = 5*PLANT_ENERGY
77-
USER_BODY_PLANT_GAP = BODY_SIZE*0.9
37+
SMILIES_AMOUNT = 20 if TEST_MODE is False else 2 # The initial number of smilies on the evolution field
7838

79-
# Zombie boss
80-
ZOMBIE_PLANT_HEALTH_LOSS = 30
81-
BOSS_PLANT_HEALTH_LOSS = 60
39+
# Plants
40+
PLANT_PREFERENCE_CHANCE = 0.5 # The chance that the smiley will prefer eating plant
41+
PLANT_ENERGY = 100 # Energy to a smiley for eating a plant
42+
INITIALLY_PLANTED = SMILIES_AMOUNT*3 if TEST_MODE is False else 100 # Amount of plants that have to be planted initially
8243

83-
VISION_DISTANCE_LOSS_1680_1050 = PLANT_ENERGY*0.000012
84-
SPEED_LOSS_1680_1050 = PLANT_ENERGY*0.002
44+
# Smilies
45+
SMILEY_SIZE = 14
46+
HALF_SMILEY_SIZE = SMILEY_SIZE/2
47+
PROCREATION_THRESHOLD = 5*PLANT_ENERGY
48+
INITIAL_ENERGY = 4*PLANT_ENERGY # Initial energy at the start for the smiley not to die immediately
8549

50+
# Zombie
8651
NEW_ZOMBIE_HEALTH = 120
8752

88-
# Related to other bodies
89-
USER_BODY_BODY_GAP = BODY_SIZE*0.7
90-
91-
# Appearance
92-
HALF_BODY_SIZE = BODY_SIZE/2
93-
MAXIMUM_COLOUR = 220
94-
MAX_COLOUR_DISTANCE = sqrt(3*MAXIMUM_COLOUR**2) # This is the maximum of sqrt((r1-r2)**2 + (g1-g2)**2 + (b1-b2)**2)
95-
96-
# First generation
97-
PLANT_ENERGY = 100 # Energy to a body for eating a plant
98-
INITIAL_ENERGY = 4*PLANT_ENERGY # Initial energy at the start for the body not to die immediately
99-
100-
# Procreating
101-
FOOD_PREFERENCE_CHANCE_CHILD = 0.9 # The chance that the child will inherit the food preference of the parent
102-
DEVIATION_OF_RANDOM_PROPERTIES = 0.1 # Proportionates to standard deviation
103-
DEVIATION_OF_RANDOM_PROPERTIES_ZERO_GENERATION = 0.4 # Proportionates to standard deviation for the zero generation
53+
# Smilies & Zombies
10454
PLACEMENT_GAP = 2.5
10555

106-
OLD_BODY_SPEED = 0.6 # A satisfying value for the size of the evolution field being {'width': 950, 'height': 500}
107-
BODIES_AMOUNT = 20 if TEST_MODE is False else 2 # Amount of bodies on the window
108-
OLD_ENERGY_FOR_VISION = 0.00007*PLANT_ENERGY if TEST_MODE is False else 0.01 # A satisfying value for the size of the evolution field being {'width': 950, 'height': 500}
109-
OLD_ENERGY_FOR_MOVING = 0.007*PLANT_ENERGY if TEST_MODE is False else 0.000000000001
110-
111-
# Canvas
112-
BOTTOM_CONTROLS_AREA_SIZE = 68
113-
114-
RIGHT_CONTROLS_AREA_SIZE = 105
115-
INDENTATION = 10
116-
117-
NOTHING_CLICKED = 0
118-
119-
# Plants
120-
PLANT_COLOUR = (14, 209, 69) # Not defining the colour, but saying that the RGB of the plant is this one
121-
TIMES_ATTEMPTED = 1000 # Limit of times for trying to place a plant on the window
122-
PLANT_SIZE_RATIO = 25 # Higher => smaller
123-
PLANT_CHANCE = 0.2 if TEST_MODE is False else 0 # The chance (percent = PLANT_CHANCE * 100) of Plant emerging
124-
INITIALLY_PLANTED = BODIES_AMOUNT*3 if TEST_MODE is False else 100 # Amount of plants that have to be planted initially
125-
126-
# Crosses
127-
CROSS_LIFETIME = 3 # Lifetime of a cross
128-
129-
# Cross appearance
130-
CROSS_SIZE_RATIO = 3 # Higher => smaller
131-
132-
# Display results
133-
RATIO = 100 # Making the results that are displayed more readable
134-
NO_CREATURES = 0
135-
SQUARES_ONE_SPECIES_WON = 1
136-
ALL_ZOMBIES = 2
137-
ONLY_ZOMBIE_BOSS = 3
138-
139-
# Other
140-
DELTA = 0.1 # Window update every DELTA seconds
141-
142-
if STRAIGHTFORWARD_FIX:
143-
ZOMBIE_BOSS_SIZE_RATIO = 27 # Higher => smaller
144-
ZOMBIE_SIZE_RATIO = 30 # Higher => smaller
56+
# Misc
57+
SPEED_RATIO = 100 # Multiplying the speed by SPEED_RATIO to make it more readable
58+
EXTENSION = 1.2 # Adding some void space to images to make it easier to click them

crosses.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
from tkinter import PhotoImage
22
from time import time
33

4-
from config import *
54
from images import CROSS_IMAGE
6-
75
import global_items
86

97
class Cross:
@@ -15,9 +13,13 @@ def __init__(self, x: float, y: float, birth_time: float):
1513

1614
crosses_list: list[Cross] = []
1715

16+
CROSS_SIZE_RATIO = 3 # Higher => smaller
17+
1818
def create_cross_image():
1919
global_items.cross_shape = PhotoImage(data=CROSS_IMAGE).subsample(CROSS_SIZE_RATIO, CROSS_SIZE_RATIO) # Registering a new shape with the plant_base64
2020

21+
CROSS_LIFETIME = 3 # Lifetime of a cross
22+
2123
def delete_old_cross(): # Deleting the cross
2224
if crosses_list != []:
2325
first_cross = crosses_list[0] # If it is required have to remove a cross, then this stamp is supposed to be the first one
@@ -27,6 +29,7 @@ def delete_old_cross(): # Deleting the cross
2729
def add_cross(x: float, y: float):
2830
crosses_list.append(Cross(x, y, time()))
2931

30-
def delete_all_crosses():
32+
@global_items.handle
33+
def D_delete_all_crosses():
3134
global crosses_list
3235
crosses_list.clear()

0 commit comments

Comments
 (0)