Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Assets/Images/pong_title.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
492 changes: 453 additions & 39 deletions README.md

Large diffs are not rendered by default.

Binary file added bgm/bubble_bobble.wav
Binary file not shown.
Binary file added bgm/click.wav
Binary file not shown.
Binary file added bgm/game_over.wav
Binary file not shown.
Binary file added bgm/pingpongbat.wav
Binary file not shown.
Binary file added games/bgm/bubble_bobble.mp3
Binary file not shown.
Binary file added games/bgm/game_over.wav
Binary file not shown.
Binary file added games/bgm/pingpongbat.wav
Binary file not shown.
274 changes: 273 additions & 1 deletion games/pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,53 @@
# GNU General Public License for more details.
import numpy
import pygame
import os
from pygame.locals import *
from sys import exit
import random
import pygame.surfarray as surfarray
import time #modify
from tkinter import * #modify
import sqlite3
import datetime

#modify +++++++++++++++++++++++++++++++++++++++ 최용훈

blist=[]

white = (255, 255, 255)
pong_title_path = os.path.join('Assets','Images','pong_title.jpg')

#modify +++++++++++++++++++++++++++++++++++++++++++ 장민주

now=datetime.datetime.now()
nowDatetime=now.strftime('%Y-%m-%d %H:%M:%S')

conn=sqlite3.connect('rank.db', isolation_level=None)
c=conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY AUTOINCREMENT, \
username text, score text, regdate text)")

pygame.init()

# # modify +++++++++++++++++++++++++++++++++++++++ 오은상

music = os.path.join('bgm','bubble_bobble.wav')
bgm = pygame.mixer.Sound(music)
bgm.play(-1)
bgm.set_volume(0.3)

music2 = os.path.join('bgm',"game_over.wav")
game_over = pygame.mixer.Sound(music2)

music3 = os.path.join('bgm',"pingpongbat.wav")
pingpong = pygame.mixer.Sound(music3)

music4 = os.path.join('bgm', "click.wav")
click = pygame.mixer.Sound(music4)
# # +++++++++++++++++++++++++++++++++++++++++++


screen = pygame.display.set_mode((640,480),0,32)

#Creating 2 bars, a ball and background.
Expand Down Expand Up @@ -47,6 +87,194 @@
clock = pygame.time.Clock()
font = pygame.font.SysFont("calibri",40)


#modify ++++++++++++++++++++++++++++++++++++++++++++++++++장민주

def pg_rank():
rankwindow()
loop=1

while loop:
for event in pygame.event.get():
if event.type == pygame.QUIT:
loop = 0
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
loop = 0
pygame.quit()
pygame.display.update()
clock.tick(60)

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#modify +++++++++++++++++++++++++++++++++++++++임차희

def rankwindow():
screen.fill(white)
BLACK = (0,0,0)
RED = (255,0,0)
BLUE = (0,0,255)

myFont = pygame.font.SysFont("arial",30,True,False)
myFont2 = pygame.font.SysFont("arial", 14, True, False)
myFont3 = pygame.font.SysFont("arial", 25, True, False)

text_rank = myFont.render("RANKING", True, RED)
text_back = myFont2.render("Press space to go back", True,RED )
text_row=myFont.render("NAME SCORE REGDATE", True, (0,0,0))
screen.blit(text_rank, (240,30))
screen.blit(text_row, (140, 90))
for row, length in zip(c.execute("SELECT username, score, regdate FROM users ORDER BY score desc LIMIT 5"), range(140,610,30)):
row=(','.join(row)).split(',')
for s, width in zip(row, [140, 270, 320]):
rank=myFont3.render(s, True, BLACK)
screen.blit(rank, (width, length))

screen.blit(text_back, (240,380))

pygame.display.flip()
wait_key()


def wait_key():
waiting = True
while waiting:
clock.tick(600)
for event in pygame.event.get():
if event.type == pygame.QUIT:
waiting = False
running = False
if event.type == pygame.K_SPACE:
waiting = False
running = False



def paused():
loop =1
BLACK = (0,0,0)
RED = (255,0,0)
BLUE = (0,0,255)

myFont = pygame.font.SysFont("arial",30,True,False)
myFont2 = pygame.font.SysFont("arial", 20, True, False)

text_pause = myFont.render("PAUSE", True, RED)
text_continue = myFont2.render("Press space to continue", True,BLUE )
text_quit = myFont2.render("Press esc to quit", True, BLUE)

screen.blit(text_pause, (280,150))
screen.blit(text_continue, (230,260))
screen.blit(text_quit, (230, 320))



while loop:
for event in pygame.event.get():
if event.type == pygame.QUIT:
loop = 0
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
loop = 0
pygame.quit()
if event.key == pygame.K_SPACE:
screen.fill((0,0,0))
loop = 0
pygame.display.update()
clock.tick(60)

# +++++++++++++++++++++++++++++++++++++++++++ 임차희



#modify +++++++++++++++++++++++++++++++++++++++최용훈

class Button:
def __init__(self, color, x, y, width, height, text = ''):
self.color = color
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text

def draw(self, win, outline=None):
if outline:
pygame.draw.rect(win, outline, (self.x-2, self.y-2, self.width+4, self.height+4), 0)

pygame.draw.rect(win, self.color, (self.x, self.y, self.width, self.height), 0)

if self.text != '':
font = pygame.font.SysFont('comicsans', 60)
text = font.render(self.text, 1, (0,0,0))
win.blit(text, (self.x + (self.width/2 - text.get_width()/2), self.y + (self.height/2 - text.get_height()/2)))

def isOver(self, pos):
if pos[0] > self.x and pos[0] < self.x + self.width:
if pos[1] > self.y and pos[1] < self.y + self.height:
return True
return False


def intro():
i=True
StartButton = Button((0, 255, 0), 450, 100, 50, 50, 'Click')
RankingButton = Button((0, 255, 0), 450, 200, 50, 50, 'Click')
QuitButton = Button((0, 255, 0), 450, 300, 50, 50, 'Click')

Start = font.render('Start', True,(255,255,255))
Ranking = font.render('Ranking', True,(255,255,255))
Quit = font.render('Quit', True,(255,255,255))
while i:

for event in pygame.event.get():
pos = pygame.mouse.get_pos()
keyp = action()
if event.type == pygame.QUIT:
pygame.quit()
quit()
if keyp!=None or event.type==pygame.KEYDOWN :
try:
if keyp=='c' or event.key==pygame.K_c :
i=False
except:
continue
if event.type == pygame.MOUSEBUTTONDOWN:
if StartButton.isOver(pos):
click.play()
i=False
elif RankingButton.isOver(pos):
click.play()
i=False
pg_rank()
elif QuitButton.isOver(pos):
click.play()
pygame.quit()
quit()
image = pygame.image.load(pong_title_path)
screen.blit(image,(0,0))
screen.blit(Start,(450.,100.))
screen.blit(Ranking,(450.,200.))
screen.blit(Quit,(450.,300.))
pygame.display.update()
clock.tick(15)

def action():
global blist
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
for tup in blist:
if tup[0] + tup[2] > mouse[0] > tup[0] and tup[1] + tup[3] > mouse[1] > tup[1]:
if click[0] == 1:
return tup[4]
return None


intro()

# +++++++++++++++++++++++++++++++++++++++++++까지


done = False
while done==False:
for event in pygame.event.get(): # User did something
Expand All @@ -62,6 +290,21 @@
bar1_move = 0.
elif event.key == K_DOWN:
bar1_move = 0.


#modify **************************************************** 임차희
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
paused()

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++까지

#+++++++++++++++++++++++++++++++++++++++++++장민주
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
pg_rank()

#++++++++++++++++++++++++++++까지

score1 = font.render(str(bar1_score), True,(255,255,255))
score2 = font.render(str(bar2_score), True,(255,255,255))
Expand Down Expand Up @@ -104,10 +347,14 @@
if circle_y >= bar1_y - 7.5 and circle_y <= bar1_y + 42.5:
circle_x = 20.
speed_x = -speed_x
pingpong.play()

if circle_x >= bar2_x - 15.:
if circle_y >= bar2_y - 7.5 and circle_y <= bar2_y + 42.5:
circle_x = 605.
speed_x = -speed_x
pingpong.play()

if circle_x < 5.:
bar2_score += 1
circle_x, circle_y = 320., 232.5
Expand All @@ -119,11 +366,36 @@
if circle_y <= 10.:
speed_y = -speed_y
circle_y = 10.
pingpong.play()

elif circle_y >= 457.5:
speed_y = -speed_y
circle_y = 457.5
pingpong.play()


#modify **************************************************** 오은상, 장민주

if bar2_score == 3: # ai가 10점 달성시 종료 bgm
c.execute("INSERT INTO users('username', 'score', 'regdate') VALUES(?,?,?)", \
('playern', bar1_score, nowDatetime))
bgm.stop()
game_over.play()
game_over.set_volume(0.3)
# 게임 오버 메시지
msg = font.render("Game Over", True, (255, 255, 0))
screen.blit(msg, (230,260))
pygame.display.update()

# 4초 대기후 나가기
pygame.time.delay(4000)
pygame.quit()
exit()

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


pygame.display.update()

pygame.quit()

c.close()
Binary file added games/rank.db
Binary file not shown.
Binary file added rank.db
Binary file not shown.