Commit 1e1a4f7a authored by gem2578's avatar gem2578

Merge branch 'feature/clock' into 'master'

Added Clock to game

See merge request !11
parents e262145c 2b5f3ddc
......@@ -12,3 +12,5 @@ RIGHT = (10, 10, 200)
PLAYER_SPEED = 5
BALL_SPEED = 5
FPS = 30
......@@ -2,3 +2,4 @@ from .team import Team
from .team_item import TeamItem
from .team_goal import TeamGoal
from .single_ball import SingleBall
from .single_clock import SingleClock
from pygame.sprite import GroupSingle
from ..sprite import Clock
class SingleClock(GroupSingle):
def __init__(self):
super().__init__(Clock())
def set_time(self, secs):
self.sprite.set_time(int(secs))
def reset(self):
self.sprite.reset()
import pygame
from . import config
from .group import Team, TeamItem, TeamGoal, SingleBall
from .group import *
from .model import Side
from .sprite import Score
from .brain import FollowBall
......@@ -16,13 +16,16 @@ class Match(object):
def __init__(self):
super().__init__()
self.score_board = TeamItem(Score)
self.clock = SingleClock()
self.ball = SingleBall(screen.get_rect().center)
self.goals = TeamGoal()
self.goals.setup(self.ball, self.score_board)
def reset(self):
self.ticks = 0
self.ball.reset()
self.score_board.reset()
self.clock.reset()
self.done = False
screen.blit(background, (0, 0))
......@@ -37,7 +40,8 @@ class Match(object):
clock = pygame.time.Clock()
while not self.done:
clock.tick(30)
self.ticks += 1
clock.tick(config.FPS)
self.check_events()
self.clean_screen()
self.update()
......@@ -63,6 +67,7 @@ class Match(object):
self.team_left.clear(screen, background)
self.team_right.clear(screen, background)
self.score_board.clear(screen, background)
self.clock.clear(screen, background)
def update(self):
self.goals.update()
......@@ -70,6 +75,8 @@ class Match(object):
self.team_left.update()
self.team_right.update()
self.score_board.update()
self.clock.set_time(self.get_time())
self.clock.update()
def draw(self):
self.goals.draw(screen)
......@@ -77,9 +84,13 @@ class Match(object):
self.team_left.draw(screen)
self.team_right.draw(screen)
self.score_board.draw(screen)
self.clock.draw(screen)
def get_score(self):
data = {}
for score in self.score_board:
data[score.side] = score.score
return data
def get_time(self):
return self.ticks/config.FPS
......@@ -2,3 +2,4 @@ from .player import Player
from .ball import Ball
from .goal import Goal
from .score import Score
from .clock import Clock
import pygame
from .. import config
from . import round_sprite as rs
from .round_sprite import RoundSprite
class Ball(rs.Round):
class Ball(RoundSprite):
def __init__(self, pos):
super().__init__(20, config.BALL)
......
import pygame
from ..model import Side
from datetime import datetime
pygame.font.init()
FONT = pygame.font.Font(None, 40)
class Clock(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.reset()
def update(self):
time = datetime.fromtimestamp(self.secs)
text = "{:02d}:{:02d}".format(time.minute,time.second)
self.image = FONT.render(text, 0, (0,0,0))
self.rect = self.image.get_rect()
self.rect.midtop = (400,0)
def reset(self):
self.secs = 0
def set_time(self, secs):
self.secs = secs
import pygame
from .. import config
from . import round_sprite as rs
from .round_sprite import RoundSprite
from ..model import Side
class Player(rs.Round):
class Player(RoundSprite):
def __init__(self, brain, pos):
pos = pygame.math.Vector2(pos)
......
from abc import ABC, abstractmethod
import pygame
class Round(ABC, pygame.sprite.Sprite):
class RoundSprite(ABC, pygame.sprite.Sprite):
def __init__(self, diameter, colour):
super().__init__()
......
......@@ -11,13 +11,9 @@ class Score(pygame.sprite.Sprite):
super().__init__()
self.side = side
self.reset()
self.render()
def update(self):
self.render()
def render(self):
text = str(self.score).zfill(2)
text = "{:02d}".format(self.score)
self.image = FONT.render(text, 0, (0,0,0), (200,200,200))
self.rect = self.image.get_rect()
if self.side == Side.LEFT:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment