Beispiel #1
0
    def loadNextLevel(self):
        self.level += 1

        nextLevelType = random.choice([0, 1])

        bonuses.clear()
        balls.clear()

        if nextLevelType == 0:
            if self.startingBallSize * 2 <= MAXBALLSIZE:
                self.startingBallSize = self.startingBallSize * 2
                balls.append(Ball(self.startingBallSize))
            else:
                nextLevelType = 1
        if nextLevelType == 1:
            self.previousBalls = self.previousBalls + 1
            temp = self.previousBalls
            for x in range(self.previousBalls):
                balls.append(Ball(self.startingBallSize))
            for b in balls:
                if self.currentBall % 2 == 0:
                    b.x = b.x - 35 * (temp)
                    temp += 1
                    b.counter = math.floor(b.x)
                    b.forward = False
                elif self.currentBall % 2 == 1:
                    b.x = b.x + 35 * (temp)
                    temp += 1
                    b.counter = math.floor(b.x)
                self.currentBall += 1

        #self.stopOnStart = True

        queue.put(Qt.Key_Minus)
Beispiel #2
0
    def splitBall(self, size, x, y):
        if int(size / 2) <= MINBALLSIZE:
            if len(balls) == 0:
                print('prije next leve')
                self.loadNextLevel()
                #self.timer.stop()
                #time.sleep(3)
                #self.loadNextLevel()
        else:
            ball1 = Ball(int(size / 2))
            ball2 = Ball(int(size / 2))

            self.setBallProperties(ball1, x, y, True)
            self.setBallProperties(ball2, x, y, False)

            balls.append(ball1)
            balls.append(ball2)

            if random.randrange(BONUS_RANGE) == 0:
                bonus_type = random.choice(bonus_types)
                bonus = Bonus(x, y, bonus_type)
                bonus.isActive = True
                bonuses.append(bonus)

            ball1.splitedLeft = True
            ball2.splitedRight = True
            ball1.splitedCounter = 42
            ball2.splitedCounter = 42
            ball1.y = ball1.dy
            ball2.y = ball2.dy
Beispiel #3
0
def main():
    for i in range(10):
        balls.append(Ball((width / 2, height / 2)))
    while True:
        clock.tick(60)
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()

    # NEW FOLLOWS ***************************************************
            if event.type == MOUSEBUTTONDOWN:
                balls.append(Ball(event.pos))
            if event.type == KEYDOWN:
                if event.key == K_d:
                    for i in range(len(balls) // 2):
                        balls.pop(0)
                if event.key == K_f:
                    pygame.display.set_mode(screen_size, FULLSCREEN)
                if event.key == K_ESCAPE:
                    pygame.display.set_mode(size)
    # NEW ABOVE *****************************************************

        screen.fill(color)
        for ball in balls:
            ball.update()
        for ball in balls:
            ball.draw(screen)

        pygame.display.flip()
Beispiel #4
0
 def __init__(self, game):
     super(HighScoreScene, self).__init__(game)
     self.__level = Level(game)
     self.__level.load_highscores()
     self.__balls = [
         Ball((GameConstants.SCREEN_SIZE[0] * random.random(),
               GameConstants.SCREEN_SIZE[1] * random.random()),
              pygame.image.load(GameConstants.SPRITE_BALL), game),
         Ball((GameConstants.SCREEN_SIZE[0] * random.random(),
               GameConstants.SCREEN_SIZE[1] * random.random()),
              pygame.image.load(GameConstants.SPRITE_BALL), game)
     ]
Beispiel #5
0
    def checkCollision2Balls(self, b1, b2):
        distance = np.sqrt((b1.x - b2.x)**2 + (b1.y - b2.y)**2)
        if b1.x == -10 or b2.x == -10 or b1.y == -10 or b2.y == -10 or (
                b1.speed == 0 and b2.speed == 0):
            pass
        elif distance <= 2 * BALL_RADIUS and (
                b1.speed > 0.08 or b2.speed > 0.08
        ):  # Checks if collided and whether the balls are going at a huge speed that would make them overlap
            collisionAngle = math.atan2(b2.y - b1.y, b2.x - b1.x)
            vx1 = math.cos(collisionAngle) * (b2.speed * math.cos(
                b2.angle - collisionAngle)) - math.sin(collisionAngle) * (
                    b1.speed * math.sin(b1.angle - collisionAngle))
            vy1 = math.sin(collisionAngle) * (b2.speed * math.cos(
                b2.angle - collisionAngle)) + math.cos(collisionAngle) * (
                    b1.speed * math.sin(b1.angle - collisionAngle))
            vx2 = math.cos(collisionAngle) * (b1.speed * math.cos(
                b1.angle - collisionAngle)) - math.sin(collisionAngle) * (
                    b2.speed * math.sin(b2.angle - collisionAngle))
            vy2 = math.sin(collisionAngle) * (b1.speed * math.cos(
                b1.angle - collisionAngle)) + math.cos(collisionAngle) * (
                    b2.speed * math.sin(b2.angle - collisionAngle))
            # print("Collision Angle: " + str(collisionAngle * 180 / pi))
            # print(vx1, vy1, vx2, vy2)
            b1.speed = math.sqrt(vx1**2 + vy1**2)
            b1.angle = Ball.principleRadianAngle(math.atan2(vy1, vx1))
            b2.speed = math.sqrt(vx2**2 + vy2**2)
            b2.angle = Ball.principleRadianAngle(math.atan2(vy2, vx2))
            # print(b1.speed, b1.angle * 180 / pi, b2.speed, b2.angle * 180 / pi)

            if self.firstCollide is None and (type(b1) is Ball.WhiteBall
                                              or type(b2) is Ball.WhiteBall):
                if type(b1) is Ball.WhiteBall:
                    self.firstCollide = type(b2)
                else:
                    self.firstCollide = type(b1)

            while (distance <= 2 * BALL_RADIUS):  # To split up the two balls
                x1 = b1.x
                y1 = b1.y
                x2 = b2.x
                y2 = b2.y
                b1.updatePosition()
                b2.updatePosition()
                distance = np.sqrt((b1.x - b2.x)**2 + (b1.y - b2.y)**2)
                # print(b1.id, b1.x, b1.y, b2.id, b2.x, b2.y)
                if b1.distance(Ball.Ball(
                        x1, y1, -5)) / b1.timeDelta < 0.1 and b2.distance(
                            Ball.Ball(x2, y2, -5)) / b2.timeDelta < 0.1:
                    break
Beispiel #6
0
def init(data):
    # load data.xyz as appropriate
    data.testMode = True

    data.table = Table(data, data.width, data.height)
    data.cue = Cue(0, 0, 0, 0, 0)
    data.pockets = []
    data.balls = []
    data.pocketInit = pocket(0, 0)
    data.pocketInit.addPockets(data)
    data.table.addBalls(data, data.testMode)
    data.cueBall = Ball(data.width // 2 + 100, data.height // 2, "white")
    data.balls.append(data.cueBall)

    # used to keep record of the times space is pressed
    data.spaceTime = 0
    data.forceCounter = 0
    data.placeCueStick = False

    data.score = 0

    # game state control
    data.gameOver = False
    data.scratched = None
    data.hitted = False
    data.scratchReplace = False

    data.time = 0
Beispiel #7
0
    def update(self):
        self.delta_time = self.clock.tick() / 1000.0
        self.paddle.move_paddle()
        self.ball.update(self.delta_time)

        if self.ball.position.y < 100:
            self.ball.check_collision(self.paddle, self.delta_time)
            if (self.ball.check_loss()):
                self.hearts.remove_life()
                if self.hearts.lives == 0:
                    self.game_lost = True
                    self.game_on = False
                self.ball = Ball(
                    Point(-200, -200),
                    Vector(120 + (self.level * 60), 360 + (self.level * 60)))

        for tile in self.tiles:
            if (self.ball.check_collision(tile, self.delta_time)):
                self.tile_sound.play()
                self.tiles.remove(tile)

        if self.tiles == []:
            if self.level == self.max_level:
                self.game_won = True
                self.game_on = False
            else:
                self.restart()
Beispiel #8
0
 def __init__(self):
     """Constructor of the Game"""
     self._running = True
     self.size = self.width, self.height = 450, 600
     # create main display - 640x400 window
     # try to use hardware acceleration
     self.screen = pygame.display.set_mode((400,200))#, pygame.HWSURFACE
     pygame.display.set_caption('AirHockey Server')
     self.clock = pygame.time.Clock()
     # set default tool
     self.tool = 'run'
     self.player  = Player.Player(1,r = 30 )   # Синий нижний игрок
     self.player.start_pos(self)
     self.cursor1 = Cursor.Cursor(player=self.player,game=self)
     self.player0 = Player.Player(0,r = 30 )    # Красный верхний игрок
     self.player0.start_pos(self)
     self.cursor0 = Cursor.Cursor(player=self.player0,game=self)
     self.players = (self.player0, self.player)
     self.ball    = Ball.Ball(x = self.width/2, y = self.height/2)
     self.ethik   = 10                                                  # Толщина отступов
     self.ecolor = (255,179,0)
     self.gate = 40                                                     # Полудлина ворот
     self.pressed = pygame.key.get_pressed()
     self.cursor_text = 5
     self.start_server()
     self.cursors = (self.cursor0,self.cursor1)
     self.mode = 3
Beispiel #9
0
    def __init__(self, parent):
        ##=====DATA RELEVANT TO BALL===============
        ##  We are going to repeatedly draw a ball object on the canvas,
        ##  "moving" it across the canvas.  The ball object is specified
        ## by (a) its x and y center coordinates (a tuple), (b) its radius,
        ##  (c) the delta x and delta y to move the ball in each time
        ## increment, and (d)  its color.
        self.ball_x, self.ball_y = 100, 200  # initial location
        self.ball_radius = 10
        self.ball_dx, self.ball_dy = 6, -3  # the movement of the ball object
        self.ball_color = "slateblue"

        self.b = Ball(self.ball_x, self.ball_y, self.ball_dx, self.ball_dy,
                      self.ball_radius, self.ball_color)
        #========DATA NEEDED FOR ANIMATION=========
        #  Here is the time in milliseconds between consecutive instances
        #  of drawing the ball.  If this time is too small the ball will
        #  zip across the canvas in a blur.
        self.wait_time = 100

        #this will allow us to stop moving the ball when the program quits
        self.isstopped = False

        self.maxx = 400  # canvas width, in pixels
        self.maxy = 400  # canvas height, in pixels

        #=============CREATE THE NEEDED GUI ELEMENTS===========
        ##  Create a frame, attach a canvas and 4 buttons to this frame
        ##  Buttons are used to cleanly exit the program;
        ##  to speed up or slow down the animation, and to restart
        ##  the animation.
        ##  Canvas, like an image, is an object that we can draw objects on.
        ##  This canvas is called chart_1.
        ##  Parent = root window, contains a frame
        ##  The frame contains the canvas and the 4 buttons.
        ##  We only care about the canvas in our animation
        self.parent = parent
        self.frame = Frame(parent)
        self.frame.pack()
        self.top_frame = Frame(self.frame)
        self.top_frame.pack(side=TOP)
        self.canvas = Canvas(self.top_frame, background="white", \
                             width=self.maxx, height=self.maxy )
        self.canvas.pack()
        self.bottom_frame = Frame(self.frame)
        self.bottom_frame.pack(side=BOTTOM)
        self.restart = Button(self.bottom_frame,
                              text="Restart",
                              command=self.restart)
        self.restart.pack(side=LEFT)
        self.slow = Button(self.bottom_frame,
                           text="Slower",
                           command=self.slower)
        self.slow.pack(side=LEFT)
        self.fast = Button(self.bottom_frame,
                           text="Faster",
                           command=self.faster)
        self.fast.pack(side=LEFT)
        self.quit = Button(self.bottom_frame, text="Quit", command=self.quit)
        self.quit.pack(side=RIGHT)
Beispiel #10
0
    def resetLevel(self):
        balls.clear()
        bonuses.clear()

        #bonuses.clear()
        if players[0].lives == 0 and players[1].lives == 0:
            return

        for x in range(self.previousBalls):
            temp = x + 2
            balls.append(Ball(self.startingBallSize))

            if x % 2 == 0:
                balls[x].x = int(balls[x].x) - 35 * temp
                balls[x].counter = int(balls[x].x)
                balls[x].forward = False
            elif x % 2 == 1:
                balls[x].x = int(balls[x].x) + 35 * temp
                balls[x].counter = int(balls[x].x)

        self.Weapon1 = False
        self.Weapon2 = False
        self.w1Y = PLAYER_HEIGTH
        self.w2Y = PLAYER_HEIGTH
        queue.put(Qt.Key_Minus)
    def loadLevel(self, lev):
        file = open(lev, 'r')
        lines = file.readlines()
        file.close()

        ballOdds = 3
        ballMax = 10
        ballCount = 0

        newlines = []
        for line in lines:
            newline = ""
            for c in line:
                if c != '\n':
                    newline += c
            newlines += [newline]
        lines = newlines

        for line in lines:
            print line

        for y, line in enumerate(lines):
            for x, c in enumerate(line):
                if c == '#':
                    Wall("wall.png", [25 * x + 12, 25 * y + 12])
                if c == 'o':
                    if ballCount < ballMax:
                        if random.randint(1, ballOdds) == 1:
                            Ball(["ball.png"], [3, 3],
                                 [25 * x + 12, 25 * y + 12])

                if c == '@':
                    self.player = PlayerBall("pBall.png", [6, 6],
                                             [25 * x + 12, 25 * y + 12])
Beispiel #12
0
    def __init__ (self, parent):
        self.ball = Ball(80, 200, 6, -3, 10., 'red')

        self.wait_time = 100 

        self.isstopped = False 

        self.maxx = 400 # canvas width, in pixels
        self.maxy = 400 # canvas height, in pixels

        self.parent = parent
        self.frame = Frame(parent)
        self.frame.pack()
        self.top_frame = Frame(self.frame)
        self.top_frame.pack(side=TOP)
        self.canvas = Canvas(self.top_frame, background="white", \
                             width=self.maxx, height=self.maxy )
        self.canvas.pack()
        self.bottom_frame = Frame(self.frame)
        self.bottom_frame.pack(side=BOTTOM)
        self.restart = Button(self.bottom_frame, text="Restart", command=self.restart)
        self.restart.pack(side=LEFT)
        self.slow = Button(self.bottom_frame, text="Slower", command=self.slower)
        self.slow.pack(side=LEFT)
        self.fast = Button(self.bottom_frame, text="Faster", command=self.faster)
        self.fast.pack(side=LEFT)
        self.quit = Button(self.bottom_frame, text="Quit", command=self.quit)
        self.quit.pack(side=RIGHT)
Beispiel #13
0
 def __init__(self):
     pygame.init()
     (WIDTH, HEIGHT) = (640, 480)
     self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
     pygame.display.set_caption("Pong Game")
     self.ball = Ball(5, 5, 35, 35, 5, 5, Pong.CLR["RED"])
     self.paddle = Paddle(WIDTH / 2, HEIGHT - 50, 100, 10, 3,
                          Pong.CLR["RED"])
Beispiel #14
0
 def hit(self):
     game = self.get_game()
     super(BallBrick, self).hit()
     ball = Ball((GameConstants.SCREEN_SIZE[0] / 2,
                  GameConstants.SCREEN_SIZE[1] * 2 / 3),
                 pygame.image.load(GameConstants.SPRITE_BALL), game)
     game.add_a_ball(ball)
     ball.set_motion(True)
Beispiel #15
0
def init_all(score):
    right = Player.Player(True)
    left = Player.Player(False)
    parts = [right, left, Ball.Ball((right, left))]
    update_screen(score, parts)

    threads = [i.start_thread() for i in parts]
    return parts, threads
Beispiel #16
0
 def __init__(self):
     self.gameStatus = MachineOfStates(
     )  # say a game status main, gameOPT, 1pvsCp, 1pvs2p
     self.configureGameStatus()
     # Balls
     self.ballTarget = ""  # Ball to Hit (white, yellow, red)
     self.ballWhite = Ball()
     self.ballYellow = Ball()
     self.ballRed = Ball()
     self.balls = [self.ballWhite, self.ballYellow,
                   self.ballRed]  # Array with all balls
     # Table
     self.SizeOfTable = 0  # Autoconfigure when the game is run >> L
     # Players
     self.target = Target(
     )  # This is a interface usert to hit the ball and configures
     self.Players = []
 def __init__(self, parent1=None, parent2=None):
     #the neural net and ball agent of this agent
     self.net = Net.Net(parent1, parent2)
     self.ball = Ball.Ball()
     #random identifier to identify the agent for debug
     self.identifier = random.randint(0, 50)
     #true if the user won the game
     self.agentWon = False
Beispiel #18
0
    def __init__ (self, parent):
        ##=====DATA RELEVANT TO BALL===============
        ##  We are going to repeatedly draw a ball object on the canvas,
        ##  "moving" it across the canvas.  The ball object is specified
        ## by (a) its x and y center coordinates (a tuple), (b) its radius,
        ##  (c) the delta x and delta y to move the ball in each time
        ## increment, and (d)  its color.
        
        colorList = ["blue", "red", "green", "yellow", "magenta", "orange"]
        self.ballobjs = []
        for i in range(10):
            xrand = random.randint(10, 390)
            yrand = random.randint(10, 390)
            dxrand = random.randint(-8, 8)
            dyrand = random.randint(-8, 8)
            radrand = random.randint(5, 10)
            randcolor = random.choice(colorList)
            self.ballobjs.append(Ball(xrand, yrand, dxrand, dyrand, radrand, randcolor))

        #========DATA NEEDED FOR ANIMATION=========
        #  Here is the time in milliseconds between consecutive instances
        #  of drawing the ball.  If this time is too small the ball will
        #  zip across the canvas in a blur.
        self.wait_time = 100 

        #this will allow us to stop moving the ball when the program quits
        self.isstopped = False 

        self.maxx = 400 # canvas width, in pixels
        self.maxy = 400 # canvas height, in pixels

        #=============CREATE THE NEEDED GUI ELEMENTS===========
        ##  Create a frame, attach a canvas and a button to this frame
        ##  Button is used to cleanly exit the program
        ##  Canvas, like an image, is an object that we can draw objects on.
        ##  This canvas is called chart_1.  
        ##  Parent = root window, contains a frame
        ##  The frame contains the canvas and the quit button.
        ##  We only care about the canvas in our animation
        self.parent = parent
        self.frame = Frame(parent)
        self.frame.pack()
        self.top_frame = Frame(self.frame)
        self.top_frame.pack(side=TOP)
        self.canvas = Canvas(self.top_frame, background="white", \
                             width=self.maxx, height=self.maxy )
        self.canvas.pack()
        self.bottom_frame = Frame(self.frame)
        self.bottom_frame.pack(side=BOTTOM)
        self.restart = Button(self.bottom_frame, text="Restart", command=self.restart)
        self.restart.pack(side=LEFT)
        self.slow = Button(self.bottom_frame, text="Slower", command=self.slower)
        self.slow.pack(side=LEFT)
        self.fast = Button(self.bottom_frame, text="Faster", command=self.faster)
        self.fast.pack(side=LEFT)
        self.quit = Button(self.bottom_frame, text="Quit", command=self.quit)
        self.quit.pack(side=RIGHT)
Beispiel #19
0
 def loadBallinContainer(number, my_canvas):
     """ creates object of Ball class, stores in a list and returns the list"""
     store_ball_objects = []
     for i in range(number):
         container_Height = 180
         ball = Ball(my_canvas, 20, container_Height - 20 * i, 20, 0, 0,
                     "white", ("ball", str(i)))
         store_ball_objects.append(ball)
     return store_ball_objects
Beispiel #20
0
def setup():

    global mouse
    global centre
    global ball

    size(640, 360)
    mouse = Vector(mouse_x, mouse_y)
    centre = Vector(width / 2, height / 2)
    ball = Ball(width, height)
def calc_read():
    global balls
    Ball.Ball.width = WIDTH
    Ball.Ball.height = HEIGHT
    Ball.Ball.radius = RADIUS
    Ball.Ball.corner_width = CORNER_WIDTH

    for id in range(balls.shape[0]):
        ballList.append(Ball.Ball(id, balls[id]))
        lineList.append({'id': id, 'lines': [balls[id]]})
def calc_run():
    calc_read()

    head = np.array([310, 110])
    end = np.array([330, 130])

    cue = Ball.Ball(-1, head, head - end)
    calc_motion(cue)

    calc_write()
Beispiel #23
0
    def Createballs(self, ctrl, nbrBall):
        self.nbrBall = nbrBall

        self.CreatePos(ctrl)

        x = 0
        while x < self.nbrBall:
            self.listObject.append(
                Ball(ctrl, self.listPos[x][0], self.listPos[x][1]))
            x += 1
Beispiel #24
0
def process_queue():
    while len(queue) != 0:
        action = queue.pop(0)
        if action["type"] == "createPlayer":
            Ball.instances[action["addr"]] = Ball()
        if action["type"] == "destroyPlayer":
            player = Ball.instances.get(action["addr"], None)
            if player != None:
                player.delete()
            Ball.instances.pop(action["addr"], None)
Beispiel #25
0
def createFood():
    isCreateFood = random.random()

    if isCreateFood < 0.2 and len(FOOD) < maximum_food_number:
        x = random.randint(-screen_width + m_f_r, screen_width - m_f_r)
        y = random.randint(-screen_height + m_f_r, screen_height - m_f_r)
        radius = random.randint(M_f_r, m_f_r)
        #color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
        color = (0, 200, 0)
        food = Ball(x, y, 0, 0, radius, color)
        FOOD.append(food)
Beispiel #26
0
    def __init__(self):
        self.ball = Ball()

        #  tracker variables for keyboard keys (keyboard key ???)
        self.W_PRESSED = 0
        self.S_PRESSED = 0
        self.UP_PRESSED = 0
        self.DOWN_PRESSED = 0

        #  which AIs computer player are going to use
        self.COMPUTER_1_AI = INPUT_TYPE_COMPUTER_KURALBAZ
        self.COMPUTER_2_AI = INPUT_TYPE_COMPUTER_KURALBAZ
Beispiel #27
0
    def __init__(self):
        self.screen_size = (800, 800)
        self.ballObject = Ball(400, 400, 0, 200)  # x, y, z, r
        self.ballObject.setMaterialToMetal()
        self.LightObject = Light(400, 400, 400, 83)  # x, y, z, power
        self.Ia = 87
        self.Ka = 0.39
        self.fatt = 0.63

        super().__init__()

        if (len(sys.argv) > 1 and sys.argv[1] == "--debug"):
            nSlider = QSlider(Qt.Horizontal, self)
            nSlider.setGeometry(10, 10, 100, 10)
            nSlider.valueChanged[int].connect(self.changeN)
            self.labelN = QLabel("N=" + str(self.ballObject.n), self)
            self.labelN.setGeometry(110, 10, 50, 10)

            ksSlider = QSlider(Qt.Horizontal, self)
            ksSlider.setGeometry(10, 20, 100, 10)
            ksSlider.valueChanged[int].connect(self.changeKs)
            self.labelKs = QLabel("Ks=" + str(self.ballObject.Ks), self)
            self.labelKs.setGeometry(110, 20, 50, 10)

            kdSlider = QSlider(Qt.Horizontal, self)
            kdSlider.setGeometry(10, 30, 100, 10)
            kdSlider.valueChanged[int].connect(self.changeKd)
            self.labelKd = QLabel("Kd=" + str(self.ballObject.Kd), self)
            self.labelKd.setGeometry(110, 30, 50, 10)

            iaSlider = QSlider(Qt.Horizontal, self)
            iaSlider.setGeometry(10, 160, 100, 10)
            iaSlider.valueChanged[int].connect(self.changeIa)
            self.labelIa = QLabel("Ia=" + str(self.Ia), self)
            self.labelIa.setGeometry(110, 160, 50, 10)

            kaSlider = QSlider(Qt.Horizontal, self)
            kaSlider.setGeometry(10, 170, 100, 10)
            kaSlider.valueChanged[int].connect(self.changeKa)
            self.labelKa = QLabel("Ka=" + str(self.Ka), self)
            self.labelKa.setGeometry(110, 170, 50, 10)

            ipSlider = QSlider(Qt.Horizontal, self)
            ipSlider.setGeometry(10, 180, 100, 10)
            ipSlider.valueChanged[int].connect(self.changeIp)
            self.labelIp = QLabel("Ip=" + str(self.LightObject.power), self)
            self.labelIp.setGeometry(110, 180, 50, 10)

            fattSlider = QSlider(Qt.Horizontal, self)
            fattSlider.setGeometry(10, 190, 100, 10)
            fattSlider.valueChanged[int].connect(self.changeFatt)
            self.labelFatt = QLabel("fatt=" + str(self.fatt), self)
            self.labelFatt.setGeometry(110, 190, 50, 10)
Beispiel #28
0
def init():
    global ball, player, opp, blocks, blockSizes
    ball = Ball.Ball(screen, colours["WHITE"], 5, ballSpeed)
    #player = Block.PlayerBlock(screen, colours["WHITE"], blockWidth, blockWidth, blockHeight)
    opp = Block.NPC_Block(screen, colours["WHITE"], (sWidth - blockWidth * 2),
                          blockWidth, blockHeight, blockSpeed, ball)
    opp2 = Block.NPC_Block(screen, colours["WHITE"], blockWidth, blockWidth,
                           blockHeight, blockSpeed, ball)

    #blocks = [player, opp]
    blocks = [opp, opp2]
    blockSizes = []
Beispiel #29
0
    def __init__(self):
        self.__lives = GameConstants.LIVES
        self.__score = 0

        self.__level = Level(self)
        self.__level.load(0)
        # self.__level.load_random()

        self.__pad = Pad(
            (GameConstants.SCREEN_SIZE[0] / 2 - GameConstants.PAD_SIZE[0] / 2,
             GameConstants.SCREEN_SIZE[1] * 9 / 10),
            pygame.image.load(GameConstants.SPRITE_PAD))
        self.__balls = [
            Ball((GameConstants.SCREEN_SIZE[0] / 2,
                  GameConstants.SCREEN_SIZE[1] * 2 / 3),
                 pygame.image.load(GameConstants.SPRITE_BALL), self)
        ]

        pygame.init()
        pygame.mixer.init()
        pygame.display.set_caption("Breakout!")

        self.__clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode(GameConstants.SCREEN_SIZE,
                                              pygame.DOUBLEBUF,
                                              32)  #| pygame.FULLSCREEN, 32)
        pygame.mouse.set_visible(False)

        self.__scenes = [
            PlayingGameScene(self),
            GameOverScene(self),
            HighScoreScene(self),
            MenuScene(self)
        ]

        self.__current_scene = GameConstants.MENU_SCENE
        self.__sounds = (
            pygame.mixer.Sound(GameConstants.SOUND_FILE_GAME_OVER),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_HIT_BRICK),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_HIT_BRICK_LIFE),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_HIT_BRICK_SPEED),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_HIT_WALL),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_HIT_PAD),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_NEW_GAME),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_NEXT_LEVEL),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_YOU_DIE),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_HIGH_SCORES),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_BREAKOUT),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_HIT_BRICK_BALL),
            pygame.mixer.Sound(GameConstants.SOUND_FILE_MENU))

        print(GameConstants.SCREEN_SIZE)
Beispiel #30
0
    def __init__(self):

        # must call constructor of EventClass first!!
        viz.EventClass.__init__(self)
        self.ball = Ball()

        self.ballList = []
        self.ballList.append(self.ball)

        self.callback(viz.KEYDOWN_EVENT, self.onKeyPress)
        self.callback(viz.TIMER_EVENT, self.onTimer)

        self.starttimer(1, 0.04, viz.FOREVER)