I'm working on a basic program which should simulate the life of a species over time. The user can choose settings like the chance of reproduction or the chances of dying.
Since I have used PyGame for some basic stuff before, I chose to use PyGame (and Python 2.7).
I just started, so I'm using circles instead of animals and there aren't too many settings but I ran into a problem:
The text on the screen isn't changing even tho it should be. In the function called ManageTime there is a loop which always waits a few seconds and should then update the number on the screen.
import pygame
import random
import time
from multiprocessing import Process
pygame.init()
#Variables
amountStart = input("How many circles should there be at the start? ")
timePassing = input("How many seconds should 1 year take?")
running = True
BLACK = (0,0,0)
WHITE = (255, 255, 255, 1)
circle_amount = 0
current_year = 0
#Create and set up window
(width, height) = (900, 600)
screen = pygame.display.set_mode((width, height))
pygame.display.flip()
screen.fill(WHITE)
#Functions
def drawCircles(amount):
screen.fill(WHITE)
amount = int(amount)
global circle_amount
while amount > 0:
amount -= 1
circle_amount += 1
xcord = random.randint(0,900)
ycord = random.randint(0,600)
print(xcord,ycord)
pygame.draw.circle(screen, (0,255,0), (xcord,ycord), 50)
pygame.display.update()
#Draw circles
drawCircles(amountStart)
#Font
font = pygame.font.SysFont(None, 24)
img = font.render(str(circle_amount), True, BLACK)
screen.blit(img, (20, 20))
pygame.display.update()
#Time passing
def ManageTime():
global current_year
global timePassing
global year
while True:
time.sleep(int(timePassing))
current_year += 1
print("year:", current_year, "time passing:", timePassing)
year = pygame.font.render(str(current_year), True, BLACK)
screen.blit(year, (0, 0))
#Game loop
p = Process(target=ManageTime)
p.start()
while running:
for event in pygame.event.get():
#Update circle count
img = font.render(str(circle_amount), True, BLACK)
screen.blit(img, (20, 20))
#Update
pygame.display.update()