예제 #1
0
def start_game(e):
    global in_play, paddle, ball
    if not in_play:
        in_play = True
        # Create Paddle
        paddle = Paddle(game_area)
        paddle.create_paddle(432 / 2, 180)
        # Create Ball
        ball = Ball(game_area)
        ball.create_ball(220, 170)

        create_area()
        game_area.itemconfigure('end', text="")
        game_area.itemconfigure('menu', text="")
        game_area.create_text(CANVAS_WIDTH - 30,
                              CANVAS_HEIGHT - 20,
                              text=" ".join(ball.lives),
                              fill="blue",
                              font=("Helvetica", 10, "bold"),
                              tags="lives")
        movement()
예제 #2
0
        sleep(2)

        game_screen.reset()

        # a new game ball
        game_ball.create_ball()

        # rebuild new block
        game_blocks.build_blocks()

        # reset the scoreboard
        scores.user_score = 0
        scores.display_score()

        # reset the user paddle
        user_paddle.create_paddle((0, -200))

    else:
        # keep the ball moving so far the game is on
        game_ball.move()

    # end the game once all the blocks have been destroyed
    if scores.user_score == 52 and len(game_blocks.block_list) == 0:

        game_on = False
        scores.winning_message()

    for block in game_blocks.block_list:

        if game_ball.distance(block) < 20:
예제 #3
0
screen.title("Python Pong Game")

#Turning screen animation off
screen.tracer(0)

#Setting up Scoreboard and field
scoreboard = Score()
line = Score()
line.draw_game_field()

#Setting up the paddles
initial_position_l = [-300, 40]
initial_position_r = [300, 40]
l_paddle = Paddle()
r_paddle = Paddle()
l_paddle.create_paddle(initial_position_l)
r_paddle.create_paddle(initial_position_r)

#Setting up the ball.
ball = Ball()

#Initializing the game while loop.
game = True

#Making screen to listen to keyboard "keys" to execute command inside of loop to move_up or move_down.
screen.listen()

game = True

while game == True:
예제 #4
0
from turtle import Turtle, Screen
from paddle import Paddle
from ball import Ball
from scoreboard import Scoreboard
import random
import time

screen = Screen()
paddle = Paddle()
ball = Ball()
scoreboard = Scoreboard()

# index 0 paddle on the right
paddle.create_paddle(-350)
paddle.create_paddle(350)
ball.create_ball()

screen.setup(width=800, height=600)
screen.bgcolor("black")
screen.title("My PingPong Game")
screen.listen()

screen.onkey(paddle.go_up1, "w")
screen.onkey(paddle.go_down1, "s")
screen.onkey(paddle.go_up2, "p")
screen.onkey(paddle.go_down2, ";")

screen.tracer(0)

Game_On = True