from Button_tactics import Score
import pygame
from plyer import Player
from Client import Network
class Game:
def __init__(self):
self.width = 1280
self.height = 800
self.window = pygame.display.set_mode((1280, 800))
pygame.display.set_caption("Football Simulator")
def RedrawWindow(self, p, p2):
score = Score()
# Builds the GUI
self.window.fill((50, 50, 50))
self.BuildFootballPitch()
#score.Draw()
p.DrawPlayerShape(self.window)
p2.DrawPlayerShape(self.window)
def BuildFootballPitch(self, dark_green=(76, 153, 0), white=(255, 255, 255)):
# This draws the football pitch on the screen
# rectangle = x, y, width, height
# circle = x, y
# line = start x end y, start x end y, width
# MAIN FIELD
rect1 = (260, 0, 750, 775)
pygame.draw.rect(self.window, dark_green, rect1)
rect2 = (315, 40, 640, 675)
pygame.draw.rect(self.window, white, rect2, 2)
pygame.draw.line(self.window, white, (315, 375), (953, 375), 2)
circle1 = (630, 375)
pygame.draw.circle(self.window, white, circle1, 50, 2)
# THE GOALPOST AND BOX
rect3 = (532.5, 40, 200, 100)
pygame.draw.rect(self.window, white, rect3, 2)
rect4 = (582.5, 40, 100, 53.25)
pygame.draw.rect(self.window, white, rect4, 2)
rect5 = (532.5, 615, 200, 100)
pygame.draw.rect(self.window, white, rect5, 2)
rect6 = (582.5, 662.5, 100, 53.25)
pygame.draw.rect(self.window, white, rect6, 2)
# CORNER MARKS
circle2 = (315, 715)
pygame.draw.circle(self.window, white, circle2, 40, 2, True, False, False, False)
circle3 = (955, 715)
pygame.draw.circle(self.window, white, circle3, 40, 2, False, True, False, False)
circle4 = (955, 40)
pygame.draw.circle(self.window, white, circle4, 40, 2, False, False, True, False)
circle5 = (315, 40)
pygame.draw.circle(self.window, white, circle5, 40, 2, False, False, False, True)
def main():
game = Game()
clock = pygame.time.Clock()
# Allows the window to stay open
running = True
n = Network()
p = n.ReturnP()
while running:
clock.tick(60)
p2 = n.Send(p)
for events in pygame.event.get():
if events.type == pygame.QUIT:
running = False
pygame.quit()
pass
p.Move()
game.RedrawWindow(p, p2)
pygame.display.update()
if __name__ == '__main__':
main()
When I run this code the whole window starts flickering. I can still control the plays on the window though. I have looked around and some people have claimed that it is to do with having 'pygame.display.update' duplicates in their code, however I have checked this. I am not sure why it is doing this because surely I should not be able to move my players if the display is updating too quickly?