Exemplo n.º 1
0
    def drawPista(self):
        self.sectors = []
        for s in json.load(open("pista.json")):
            self.sectors.append(Sector(**s))
        # FIXME to remove after testing
        self.scene.setPista(self.sectors)

        self.borders = []
        tmp = json.load(open("bordi.json"))

        for b in tmp:
            border = Border(*b)
            self.scene.addItem(border)
            self.borders.append(border)
Exemplo n.º 2
0
 def connect(self, node1, node2):
     #if node1 and node2 is the same,return None
     if node1 == node2:
         return None
     #if node1 connects node2,return None
     if node1 in node2.borders.keys() or node2 in node1.borders.keys():
         return None
     #if node1 or node2 is nont in self.nodes,return None
     if node1 not in self.nodes.values() or node2 not in self.nodes.values(
     ):
         return None
     border = Border(node1, node2, self)  #create new border
     #add the new border to nodes
     node1.addBorder(border)
     node2.addBorder(border)
     #add the new border to the list of figure
     self.borders.append(border)
     return border
Exemplo n.º 3
0
    def __init__(self) -> None:
        self.update_action_depending_on_state = {
            GameState.PLAY: self.update_play_screen,
            GameState.MENU: self.update_menu_screen,
            GameState.PAUSE: self.update_pause_screen,
            GameState.GAME_OVER: self.update_game_over_screen,
        }
        self.state = GameState.MENU

        self.grid = Grid()
        self.menu = Menu()
        self.start_menu = StartMenu()
        self.border = Border()

        self.clock = pygame.time.Clock()
        self.running = True
        self.to_draw = True

        self.player = type(next_indicator.next_one)()
        self.create_new_player()

        self.fps = 0
Exemplo n.º 4
0
def main():
    from border import Border
    from whiteboardView import cvHelper
    b = Border()
    b.lineInterceptForm((1, 0), 3, (1, 6.3), 2.3)
Exemplo n.º 5
0
    def borderCheck(self, img):
        #CHECKING FOR BORDER
        if self.debug:
            print('borderCheck')
        if self.border is None:
            self.border = Border(debug=self.debug)
            if self.prod:
                pass
        # preps the image recieved to find the corners
        if self.corners < 4:
            img1 = cvHelper.colorSelect2(img.copy())
            img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

            # Tells the master whiteboard to display the top left corner
            if self.corners == 0:
                #topLeft, NW
                print('nw')
                if not self.calibrating:
                    self.p.calibNW()
                    self.calibrating = True
                    self.framesToSkip = 10
                # wait a couple of frames to make sure we are detecting the calibration screen
                if self.framesToSkip == 0:
                    if self.border.findCorner(img1, 'topleft'):
                        print('found nw')
                        self.corners += 1
                        self.calibrating = False
                        self.framesToSkip = 10
                else:
                    self.framesToSkip -= 1
            # Tells the master whiteboard to display the top right corner
            elif self.corners == 1:
                #topRight, NE
                print('ne')
                if not self.calibrating:
                    self.p.calibNE()
                    self.calibrating = True
                    self.framesToSkip = 10
                if self.framesToSkip == 0:
                    if self.border.findCorner(img1, 'topright'):
                        self.calibrating = False
                        print('found ne')
                        self.corners += 1
                        self.framesToSkip = 10
                else:
                    self.framesToSkip -= 1
            # Tells the master whiteboard to display the bottom left corner
            elif self.corners == 2:
                #bottomleft, SW
                print('sw')
                if not self.calibrating:
                    self.p.calibSW()
                    self.calibrating = True
                    self.framesToSkip = 5
                # wait a couple of frames to make sure we are detecting the calibration screen
                if self.framesToSkip == 0:
                    if self.border.findCorner(img1, 'bottomleft'):
                        print('found sw')
                        self.calibrating = False
                        self.corners += 1
                else:
                    self.framesToSkip -= 1
            # Tells the master whiteboard to display the bottom right corner
            elif self.corners == 3:
                #bottomright, SE
                print('se')
                if not self.calibrating:
                    self.p.calibSE()
                    self.calibrating = True
                    self.framesToSkip = 5
                # wait a couple of frames to make sure we are detecting the calibration screen
                if self.framesToSkip == 0:
                    if self.border.findCorner(img1, 'bottomright'):
                        print('found se')
                        self.calibrating = False
                        self.corners += 1
                        self.p.doneCalib()
                else:
                    self.framesToSkip -= 1
        else:
            if self.debug:
                print('not checking for border')
            return True
Exemplo n.º 6
0
from turtle import Screen, Turtle
from snake import Snake
from food import Food
from scoreboard import Scoreboard
from border import Border
import time

screen = Screen()
screen.setup(width=610, height=610)
screen.bgcolor("OliveDrab3")
screen.title("SNAKE")
screen.tracer(0)

border = Border()
snake = Snake()
food = Food()
score = Scoreboard()

game_is_on = True

screen.listen()
screen.onkey(snake.up, "w")
screen.onkey(snake.down, "s")
screen.onkey(snake.left, "a")
screen.onkey(snake.right, "d")

score.explanation()

while game_is_on:
    score.write_score()
    # animation settings
Exemplo n.º 7
0
# -*- coding: cp1252 -*-

import pygame.sprite
import pygame
from border import Border

defaultBorder = Border(0, 0)
defaultForeground = (255, 255, 255)
defaultBackground = (0, 0, 0)
disabeledOverlay = (150, 150, 150, 150)


class Widget(pygame.sprite.DirtySprite):
    """
    Underlying class for interactive GUI-objects with PyGame;
    extends pygame.sprite.DirtySprite
    intended for use together with pygame.sprite.LayeredDirty
    """
    def __init__(self, x, y, width, height):
        """
        Initialisation of a Widget

        parameters:     int x-coordinate of the Widget (left)
                        int y-coordinate of the Widget (top)
                        int width of the Widget
                        int height of the Widget
        return values:  -
        """
        super(Widget, self).__init__()
        self.image = pygame.Surface((width, height), pygame.SRCALPHA, 32)
        self._bounds = self.image.get_rect().move(x, y)
Exemplo n.º 8
0
mixer.music.play(-1)

SCREEN_WIDTH = 900
SCREEN_HEIGHT = 700

turtle.colormode(255)

# screen setup
screen = turtle.Screen()
screen.tracer(0)
screen.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT)
screen.bgcolor('grey')
screen.title("Pong Game")

# Border setup
border = Border(s_width=SCREEN_WIDTH, s_height=SCREEN_HEIGHT)

# paddle setup
paddle = Paddle(border_half_height=border.border_half_height,
                border_half_width=border.border_half_width)
paddle.goto((-1) * (SCREEN_WIDTH / 2 - 60), 0)

# ball setup
ball = Ball(border_half_height=border.border_half_height,
            border_half_width=border.border_half_width)

# score setup
score = Score(s_width=SCREEN_WIDTH, s_height=SCREEN_HEIGHT)

# level setup
level = Level(s_width=SCREEN_WIDTH, s_height=SCREEN_HEIGHT)
Exemplo n.º 9
0
def main():
    # TODO 1: Configure screen
    screen = Screen()
    screen.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT)
    screen.bgcolor(SCREEN_BACKGROUND_COLOR)
    screen.tracer(0)

    # Add borders
    border = Border()
    border.createBorder()

    # TODO 2: Configure initial snake
    snake = Snake()
    food = Food()
    scoreboard = Scoreboard()

    # TODO 3: Move the snake
    screen.listen()
    screen.onkey(snake.up, "Up")
    screen.onkey(snake.down, "Down")
    screen.onkey(snake.left, "Left")
    screen.onkey(snake.right, "Right")

    #global paused

    #def unpause():
    #    global paused
    #    paused = not paused

    #screen.onkey(unpause, "p")

    game_is_on = True
    while game_is_on:
        #while paused:
        #    sleep(0.2)
        screen.update()
        sleep(SLEEP_TIME)
        snake.move()

        # TODO 4: Detect collision with food
        snake_food_collision_distance = (
            food.width() + snake.head.width()) / 2 - COLLISION_ERROR
        if snake.head.distance(food) < snake_food_collision_distance:
            scoreboard.score += 1
            snake.add_segment()
            food.refresh()
            for segment in snake.tail:
                while segment.position() == food.position():
                    food.clear()
                    food.refresh()
            scoreboard.refresh()

        # TODO 5: Detect collision with walls
        pass_x_wall = (
            snake.head.xcor() < -SCREEN_WIDTH / 2 + snake.head.width()
            or snake.head.xcor() > SCREEN_WIDTH / 2 - snake.head.width())
        pass_y_wall = (
            snake.head.ycor() < -SCREEN_HEIGHT / 2 + snake.head.width()
            or snake.head.ycor() > SCREEN_HEIGHT / 2 - snake.head.width())
        wall_collision = pass_x_wall or pass_y_wall
        if wall_collision:
            scoreboard.resetHighestScore()
            snake.resetSnake()

        # TODO 6: Detect collision with tail
        tail_head_collision_distance = snake.head.width() - COLLISION_ERROR
        for segment in snake.tail[1:]:
            if segment.distance(snake.head) < tail_head_collision_distance:
                scoreboard.resetHighestScore()
                snake.resetSnake()

    screen.exitonclick()