Ejemplo n.º 1
0
x_velocity = 10
y_velocity = 0
score_left = 0
score_right = 0
first_serve = True


# tkinter 클래스으로부터 윈도우 호출
window = Tk(mixer.music.play(-1,0.0))
window.title("MiniminiPong")
       
# Table 클래스으로부터 table 호출
my_table = table.Table(window, net_colour="red", vertical_net=True)

# Ball 클래스으로부터 볼을 호출합니다
my_ball = ball.Ball(table=my_table, x_speed=x_velocity, y_speed=y_velocity,
                    width=30, height=30, colour="red", x_start=288, y_start=188)

# Bat 클래스으로부터 배트를 호출합니다
bat_L = bat.Bat(table=my_table, width=15, height=100, x_posn=20, y_posn=150, colour="green")
bat_R = bat.Bat(table=my_table, width=15, height=100, x_posn=575, y_posn=150, colour="green")

def on_close():
    mixer.music.stop()
    window.destroy()

window.protocol("WM_DELETE_WINDOW", on_close)

#### 함수:
def game_flow():
    global first_serve
    global score_left
Ejemplo n.º 2
0
def show_fps(screen, clock):
    fps_overlay = FONT.render('FPS: '+str(int(clock.get_fps())), True, FONT_COLOUR)
    screen.blit(fps_overlay, (screen_width - 80, 5))

clock = pygame.time.Clock()
FPS = 60
FONT = pygame.font.SysFont("Arial", 20)
FONT_COLOUR = pygame.Color("white")

screen_width = 640
screen_height = 640

# Set up the drawing window
screen = pygame.display.set_mode([screen_width, screen_height])

ball = ball.Ball()
ball.x = screen_width/2
ball.y = ball.radius + 20

paddle = paddle.Paddle()
paddle.x = screen_width/2 - paddle.width/2
paddle.y = screen_height - paddle.height - 20

# Colour
ball_colour = (254,74,73)
paddle_colour = (254,215,102)
bg_colour = (69, 69, 69)

### GAME ###

# Run until the user asks to quit
Ejemplo n.º 3
0
from constants import *
import pygame
import player
import ball

clock = pygame.time.Clock()
surface = pygame.display.set_mode((GAME_WIDTH, GAME_HEIGHT))

pygame.init()
player_group = pygame.sprite.Group()
player_group.add(player.Player())

ball_group = pygame.sprite.Group()
ball_group.add(ball.Ball())


def main():
    running = True

    while running:
        clock.tick(TICK_RATE)
        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                running = False

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_q:
                    pygame.quit()

        draw()
Ejemplo n.º 4
0
            tank.speedy = 1
            tank.speedx = 0
        if d.type == pygame.KEYUP and d.key == pygame.K_DOWN:
            tank.speedy = 0
        if d.type == pygame.KEYDOWN and d.key == pygame.K_UP:
            tank.speedy = -1
            tank.speedx = 0
        if d.type == pygame.KEYUP and d.key == pygame.K_UP:
            tank.speedy = 0

        vrem = pygame.time.get_ticks()
        rasn = vrem - tims
        if d.type == pygame.KEYDOWN and d.key == pygame.K_SPACE:
            if rasn >= 3000:
                tims = pygame.time.get_ticks()
                ballpy = ball.Ball(tank.rect.right, tank.rect.centery - 2)
                groopa.add(ballpy)

    groopa.update()

    screen.fill([s, 164, 231])
    if s < 255:
        s += 1

    i = clock.get_fps()
    i = str(i)
    fps = shr.render(i, False, [0, 0, 0])
    screen.blit(fps, [0, 0])

    groopa.draw(screen)
    pygame.display.flip()
Ejemplo n.º 5
0
def main():
    pygame.font.init()
    pygame.display.set_caption("BREAKOUT")
    # Constants that will be used in the program
    APPLICATION_WIDTH = 400
    APPLICATION_HEIGHT = 600
    PADDLE_Y_OFFSET = 30
    BRICKS_PER_ROW = 10
    BRICK_SEP = 4  # The space between each brick
    BRICK_Y_OFFSET = 70
    BRICK_WIDTH = (APPLICATION_WIDTH -
                   (BRICKS_PER_ROW - 1) * BRICK_SEP) / BRICKS_PER_ROW
    NUM_TURNS = 3
    myFont = pygame.font.SysFont("Helvetica", 24)
    # The following lines of code create the pygame window and two sprite groups
    window = pygame.display.set_mode((APPLICATION_WIDTH, APPLICATION_HEIGHT),
                                     0, 32)
    blocksGroup = pygame.sprite.Group()
    paddleGroup = pygame.sprite.Group()

    # Sets up the colors
    RED = (255, 0, 0)
    ORANGE = (255, 165, 0)
    YELLOW = (255, 255, 0)
    GREEN = (0, 255, 0)
    CYAN = (0, 255, 255)
    BLACK = (0, 0, 0)
    WHITE = (255, 255, 255)
    PINK = (255, 20, 147)
    # Puts colors in a list and assigns x and y coordinates for bricks
    colors = [
        RED, RED, ORANGE, ORANGE, YELLOW, YELLOW, GREEN, GREEN, CYAN, CYAN
    ]
    xPos = BRICK_SEP
    yPos = BRICK_Y_OFFSET
    # This for loop creates the array of bricks on the screen
    for x in range(10):
        for y in range(BRICKS_PER_ROW):
            row_of_bricks = brick.Brick(BRICK_WIDTH, colors[x])
            row_of_bricks.rect.x = xPos
            row_of_bricks.rect.y = yPos
            blocksGroup.add(row_of_bricks)
            window.blit(row_of_bricks.block, row_of_bricks.rect)
            xPos += BRICK_WIDTH + BRICK_SEP
        yPos += BRICK_SEP + 8
        xPos = BRICK_SEP
    # The following lines of code create and blit the paddle on the screen
    my_paddle = paddle.Paddle(WHITE)
    my_paddle.rect.x = APPLICATION_WIDTH / 2
    my_paddle.rect.y = APPLICATION_HEIGHT - PADDLE_Y_OFFSET
    paddleGroup.add(my_paddle)
    window.blit(my_paddle.image, my_paddle.rect)
    # The following lines of code create and blit the ball on the screen
    my_ball = ball.Ball(PINK, APPLICATION_WIDTH, APPLICATION_HEIGHT)
    my_ball.rect.x = APPLICATION_WIDTH / 2
    my_ball.rect.y = APPLICATION_HEIGHT / 2
    window.blit(my_ball.image2, my_ball.rect)
    # label prints 'GAME OVER' on the screen if you lose
    label = myFont.render("GAME OVER", 1, ORANGE)

    pygame.display.update()
    # This while loop ultimately makes the game play
    while NUM_TURNS >= 0:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
        window.fill(BLACK)
        # This for loop continuously blits the blocks on the screen and makes the paddle and ball move
        for x in blocksGroup:
            window.blit(x.block, x.rect)
            my_paddle.move(APPLICATION_WIDTH)
        window.blit(my_paddle.image, my_paddle.rect)
        my_ball.move()
        my_ball.collideBricks(blocksGroup)
        my_ball.collidePaddle(paddleGroup)
        # This if statement subtracts a life from gameplay if your ball hits the bottom of the screen
        if my_ball.rect.bottom >= APPLICATION_HEIGHT:
            my_ball.rect.x = APPLICATION_WIDTH / 2
            my_ball.rect.y = APPLICATION_HEIGHT / 2
            NUM_TURNS -= 1
        window.blit(my_ball.image2, my_ball.rect)
        pygame.display.update()
        # This if statement prints "GAME OVER" on the screen if you lose
        if NUM_TURNS == 0:
            window.blit(label, (APPLICATION_WIDTH / 2, APPLICATION_HEIGHT / 2))
            pygame.display.update()
            pygame.time.wait(2000)
            break
Ejemplo n.º 6
0
    def __init__(self, id=1, score=0, life=3, f=None, map=None):
        self.custom = False
        if map is not None:
            self.current_level_index = "Custom.{0}".format(map)
            self.custom = True
            self.life = life
            self.score = score
            self.multiplier = 1.0
            self.map = m.Map(map)
            self.current_level = self.map.map
            self.field_width = len(self.current_level[0]) * 20 - 20
            self.win_width = self.field_width + 150
            self.win_height = len(self.current_level) * 20
            self.blocks = self.map.blocks
            self.platform = pl.Platform(self.field_width)
            self.ball = b.Ball(self.field_width, self.win_height)
        elif f is not None:
            args = f.split(";")
            if args[0][:6] == "Custom":
                self.custom = True
            if not self.custom:
                self.current_level_index = int(args[0])
                try:
                    self.map = m.Map("Levels/level" +
                                     str(self.current_level_index) + ".txt")
                except:
                    stat = statistic.Statistic(
                        "{0}".format(self.current_level_index), self.score)
                    stat.draw_stats()
            else:
                self.map = m.Map(args[0][7:])
            self.score = int(args[1])
            self.life = int(args[2])
            self.multiplier = float(args[3])

            self.current_level = self.map.map
            self.field_width = len(self.current_level[0]) * 20 - 20
            self.win_width = self.field_width + 150
            self.win_height = len(self.current_level) * 20
            self.platform = pl.Platform(self.win_width, float(args[4]),
                                        float(args[5]))
            b_args = args[6].split(',')
            self.ball = b.Ball(self.field_width, self.win_height,
                               float(b_args[0]), float(b_args[1]),
                               float(b_args[2]), float(b_args[3]),
                               float(self.win_height - 50), float(b_args[4]))
            self.blocks = []
            for i in range(7, len(args)):
                if args[i] == '':
                    break
                block_args = args[i].split(',')
                self.blocks.append(
                    bl.Block(int(block_args[0]), int(block_args[1]),
                             int(block_args[2])))
        else:
            self.current_level_index = id
            self.life = life
            self.score = score
            self.multiplier = 1.0
            try:
                self.map = m.Map("Levels/level" +
                                 str(self.current_level_index) + ".txt")
            except:
                stat = statistic.Statistic(
                    "{0}".format(self.current_level_index - 1), self.score)
                stat.draw_stats()
            self.current_level = self.map.map
            self.field_width = len(self.current_level[0]) * 20 - 20
            self.win_width = self.field_width + 150
            self.win_height = len(self.current_level) * 20
            self.blocks = self.map.blocks
            self.platform = pl.Platform(self.field_width)
            self.ball = b.Ball(self.field_width, self.win_height)
        self.active_bonuses = []
        self.display = (self.win_width, self.win_height)
        self.background_color = "#001a82"
        self.border_color = "#000e47"
        self.on_pause = False
        self.lose = False
        self.screen = pygame.display.set_mode(self.display)
        self.bg = pygame.Surface(self.display)
        self.timer = pygame.time.Clock()
        self.ctrl_pressed = False
        self.ball_cant_drop = False
Ejemplo n.º 7
0
l_paddle.goto(PADDLE_STARTING_POSITIONS['LEFT_PADDLE_STARTING_POSITION'])
r_paddle.goto(PADDLE_STARTING_POSITIONS['RIGHT_PADDLE_STARTING_POSITION'])

background.update()


# TODO Scoreboard


# TODO Ball
# move ball
size = float(background.textinput(title='Ball Sizer', prompt =
'how big do you want your ball?' ))


ball = ball.Ball(size)
scoreboard = Scoreboard()
game_is_on = True

# move paddles
background.listen()
background.onkey(key='Up', fun=r_paddle.up)
background.onkey(key='Down', fun=r_paddle.down)
background.onkey(key='o', fun=l_paddle.up)
background.onkey(key='q', fun=l_paddle.down)

while game_is_on:
    time.sleep(0.05)
    ball.move()
    background.update()
    x = ball.xcor()
Ejemplo n.º 8
0
import pygame.freetype
import player, ball

pygame.init()

width = 960
# Formula for 16:9
height = int(width/2+width/16)

screen = pygame.display.set_mode((width, height))

pygame.display.set_caption("Pong by MysteryBlokHed")

player1 = player.Player(25, 200, 25, 150)
player2 = player.Player(width-75, 200, 25, 150)
ball1 = ball.Ball(480, 270, 15, 15)
ball1.set_vel_x(10)
ball1.set_vel_y(-10)

player1_score = 0
player2_score = 0

scored = False
ai = True

text = pygame.freetype.SysFont("Roboto", 30)

running = True
while running:
    pygame.time.delay(50)
Ejemplo n.º 9
0
#creating game window
screen = pygame.display.set_mode((glob_width, glob_height))
pygame.display.set_caption("PONGER v 0.04")

#loading background image,scaling to monitor
bckgrnd = pygame.image.load("TEXTURES/space.jpg")
bckgrnd = pygame.transform.scale(bckgrnd, (glob_width, glob_height))

#starting players parameters
P1_y = glob_height / 3
P2_y = glob_height / 3
P1_points = 0
P2_points = 0

#Creating ball and it's basic parameters
meteoroid = ball.Ball(13, 3, (glob_width / 2),
                      (glob_height / 2))  #radius,speed,x,y

#TEXTURING BALL WORK IN PROGRESS
meteoroid_img = pygame.image.load("TEXTURES/moon.png")
meteoroid_img = pygame.transform.scale(meteoroid_img, (400, 400))

#point counters
myfont = pygame.font.SysFont('Arial', 30)

#game pause boolean
paused = False

#MAIN LOOP
run = True
while run:
    for event in pygame.event.get():
Ejemplo n.º 10
0
    def brick_ball(self):
        if (self.strength > 0):
            # Lower side collision handle
            low_col = global_var.ball_vely / global_var.ball_velx
            low_col *= (self.x + 1 - global_var.ball_x)
            low_col += global_var.ball_y
            if (((low_col) >= self.y) and ((low_col) <= self.y + 4)
                    and (self.x + 1 <= global_var.ball_x) and
                (self.x + 1 >= global_var.ball_x + global_var.ball_velx)):
                if (global_var.thru != 0):
                    global_var.ball_velx *= -1
                self.strength -= 1
                self.contact = 1
                global_var.score += 10

            # upper side collision handle
            upp_col = global_var.ball_vely / global_var.ball_velx
            upp_col *= (self.x - global_var.ball_x)
            upp_col += global_var.ball_y
            if (((upp_col) >= self.y) and ((upp_col) <= self.y + 4)
                    and (self.x >= global_var.ball_x)
                    and (self.x <= global_var.ball_x + global_var.ball_velx)):
                if (global_var.thru != 0):
                    global_var.ball_velx *= -1
                self.strength -= 1
                self.contact = 1
                global_var.score += 10

            # left side collision handle
            if global_var.ball_vely != 0:
                lef_col = global_var.ball_velx / global_var.ball_vely
                lef_col *= (self.y - global_var.ball_y)
                lef_col += global_var.ball_x
                if (((lef_col) >= self.x) and ((lef_col) <= self.x + 1)
                        and (self.y >= global_var.ball_y) and
                    (self.y <= global_var.ball_y + global_var.ball_vely)):
                    if (global_var.thru != 0):
                        global_var.ball_vely *= -1
                    self.strength -= 1
                    self.contact = 1
                    global_var.score += 10

            # right side collision handle
            if global_var.ball_vely != 0:
                rig_col = global_var.ball_velx / global_var.ball_vely
                rig_col *= (self.y + 4 - global_var.ball_y)
                rig_col += global_var.ball_x
                if (((rig_col) >= self.x) and ((rig_col) <= self.x + 1)
                        and (self.y + 4 <= global_var.ball_y) and
                    (self.y + 4 >= global_var.ball_y + global_var.ball_vely)):
                    if (global_var.thru != 0):
                        global_var.ball_vely *= -1
                    self.strength -= 1
                    self.contact = 1
                    global_var.score += 10

            #updation
            a = ball.Ball()
            a.updatevar()
            if (self.strength == 0 and self.expo == 1):
                global_var.expolosion = 1
Ejemplo n.º 11
0
# x축과 y축의 속
x_velocity = 10
y_velocity = 10
score_left = 0
score_right = 0
first_serve = True

window = Tk()
window.title("MyPong")

my_table = table.Table(window, vertical_net=True)

my_ball = ball.Ball(table=my_table,
                    x_speed=x_velocity,
                    y_speed=y_velocity,
                    width=24,
                    height=24,
                    color="red",
                    x_start=300,
                    y_start=200)

bat_L = bat.Bat(table=my_table,
                width=15,
                height=100,
                x_posn=20,
                y_posn=150,
                color="blue")
bat_R = bat.Bat(table=my_table,
                width=15,
                height=100,
                x_posn=575,
                y_posn=150,
Ejemplo n.º 12
0
screen = pygame.display.set_mode(screen_size)
pygame.display.set_caption("Laser Pong")
clock = pygame.time.Clock()

fwork_holder = frame.FrameHolder()
laser = renderer.LaserRenderer(fwork_holder, gstt.centerx, gstt.centery, gstt.zoomx, gstt.zoomy, gstt.sizex, gstt.sizey)


dac_threading = threading.Thread(target=dac_thread, args=[])
dac_threading.start()

update_screen = False

gstt.score = score.Score()
gstt.score2 = score2.Score2()
gstt.bll = ball.Ball()
gstt.flp = flips.Flips()
gstt.txt = text.Text()
gstt.flt = filet.Filet()
gstt.brdrs = borders.Borders()
gstt.xvel = - 1
gstt.yvel = 0
gstt.lscore = 0
gstt.rscore = 0
gstt.ly = FLIPS_lorigin[1]
gstt.ry = FLIPS_rorigin[1]
flipsy = [gstt.ly, gstt.ry]
gstt.stick = 0
gstt.x = ball_origin[0]
gstt.y = ball_origin[1]
gstt.remain = BALL_MAX