2/9 모각소 4주차 스터디 팀명: 데이터란 무엇인가

박종일·2023년 2월 9일
0
post-thumbnail

아주대학교 인공지능융합학과 학생들이 모여 진행하는 pygame

2/8 아주대학교 팔달관 317호
활동시간 : 15:00 ~ 18:20

<주제> 파이썬 pygame - 2인용 탁구 게임

실행 코드

import pygame

BLACK = (0,0,0)

class Paddle(pygame.sprite.Sprite):
    #This class represents a car. It derives from the "Sprite" class in Pygame.

    def __init__(self, color, width, height): # 필수 
        # Call the parent class (Sprite) constructor
        super().__init__()

        
        
        self.image = pygame.Surface([width, height])
        self.image.fill(BLACK)
        self.image.set_colorkey(BLACK)

        # 패들 그리기 
        pygame.draw.rect(self.image, color, [0, 0, width, height])

        # 
        self.rect = self.image.get_rect()

    def moveUp(self, pixels):
        self.rect.y -= pixels
        #Check that you are not going too far (off the screen)
        if self.rect.y < 0:
          self.rect.y = 0

    def moveDown(self, pixels):
        self.rect.y += pixels
        #Check that you are not going too far (off the screen)
        if self.rect.y > 400:
          self.rect.y = 400

import pygame
from random import randint

BLACK = (0, 0, 0)

class Ball(pygame.sprite.Sprite):
    #This class represents a car. It derives from the "Sprite" class in Pygame.

    def __init__(self, color, width, height):
        # Call the parent class (Sprite) constructor
        super().__init__()

       
        
        self.image = pygame.Surface([width, height])
        self.image.fill(BLACK)
        self.image.set_colorkey(BLACK)

        # 공 그리기 
        pygame.draw.rect(self.image, color, [0, 0, width, height])

        self.velocity = [randint(4,8),randint(-8,8)]

        
        self.rect = self.image.get_rect()

    def update(self):
        self.rect.x += self.velocity[0]
        self.rect.y += self.velocity[1]

    def bounce(self):
        self.velocity[0] = -self.velocity[0]
        self.velocity[1] = randint(-8,8)

pygame.init() # 초기화 필수 

# 색 정의 
BLACK = (0,0,0)
WHITE = (255,255,255)

# 새 창 열기 
size = (700, 500)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Pong")

paddleA = Paddle(WHITE, 10, 100)
paddleA.rect.x = 20
paddleA.rect.y = 200

paddleB = Paddle(WHITE, 10, 100)
paddleB.rect.x = 670
paddleB.rect.y = 200

ball = Ball(WHITE,10,10)
ball.rect.x = 345
ball.rect.y = 195


all_sprites_list = pygame.sprite.Group()



all_sprites_list.add(paddleA)
all_sprites_list.add(paddleB)
all_sprites_list.add(ball)


clock = pygame.time.Clock()

#Initialise player scores
scoreA = 0
scoreB = 0

# -------- Main Program Loop -----------
while True:
    # --- Drawing code should go here
    # First, clear the screen to black. 
    screen.fill(BLACK)
    #Draw the net
    pygame.draw.line(screen, WHITE, [349, 0], [349, 500], 5)

    # 메인 이벤트 루프!! 
    event = pygame.event.poll()
    if event.type == pygame.QUIT: # If user clicked close
          break
    elif event.type==pygame.KEYDOWN:
            if event.key==pygame.K_x: #Pressing the x Key will quit the game
                 break

    #wsad, 화살표로 2인용 게임을 만든다. 
    keys = pygame.key.get_pressed()
    if keys[pygame.K_w]:
        paddleA.moveUp(7)
    if keys[pygame.K_s]:
        paddleA.moveDown(7)
    if keys[pygame.K_UP]:
        paddleB.moveUp(7)
    if keys[pygame.K_DOWN]:
        paddleB.moveDown(7)    

   
    all_sprites_list.update()

    
    
    if ball.rect.x>=690:
        scoreA+=1
        ball.velocity[0] = -ball.velocity[0]
    if ball.rect.x<=0:
        scoreB+=1
        ball.velocity[0] = -ball.velocity[0]
    if ball.rect.y>490:
        ball.velocity[1] = -ball.velocity[1]
    if ball.rect.y<0:
        ball.velocity[1] = -ball.velocity[1]     

    #패들과 충돌 감지 
    
    if pygame.sprite.collide_mask(ball, paddleA) or pygame.sprite.collide_mask(ball, paddleB):
      ball.bounce()

    #2개의 군집으로 게임을 실행시킨다.
    all_sprites_list.draw(screen) 

    #디스플레이 점수 
    font = pygame.font.Font(None, 74)
    text = font.render(str(scoreA), 1, WHITE)
    screen.blit(text, (250,10))
    text = font.render(str(scoreB), 1, WHITE)
    screen.blit(text, (420,10))

    # --- 디스플레이 업데이트 
    pygame.display.update()

    # --- fps 설정 
    clock.tick(60)

# 게임 종료 
pygame.quit()

동영상링크

동영상 링크를 누르면 제작한 동영상이 나옵니다.

<팀원 github 주소>
< 깃허브 주소 >
박종일 :https://github.com/aosdbfc/every_software
김산 : https://github.com/3n952/every_soft.git
임재환 : https://github.com/Jxxhwan/mogakso
최강인 : https://github.com/ganggri
최웅환 : https://github.com/dnstjr4567

2/9일 4주차 모각소 모임을 시작하였다.
2인용 탁구게임은 그 전에 만들었던 pygame 보다 구현할 것이 적어 빠르게 마무리한 후 각자의 개인 프로젝트를 진행하였다.
각자의 프로젝트는 각 깃허브에 첨부하였다.
(python을 활용한 데이터사이언스(머신러닝) 분야, 딥러닝 분야 등 각 학우들의 프로젝트의 맞게 공부를 진행하였다.)
2월 초에 계속해서 진행되고 모두 고학년이다보니 학우 모두가 각자의 일이 바쁜 것도 느껴졌다. 그럼에도 불구하고 화이팅하는 모습에 모두가 파이팅 넘치게 모각소 활동을 오늘도 마무리 했다.

정말 팀명 답게 4주차를 진행하며 느낀 것은...
데이터란 무엇일까...?

우리 팀 5명 모두가 마지막까지 열심히 하며 python에 대해 한 단계 높아진 모습을 보여주고 싶다.

다음 스터디 계획도 자료구조/알고리즘 및 개인 프로젝트를 만들기를 하기로 하였다.

2023.02.09
데이터란 무엇인가...!

profile
존경하는 인물: 스토브리그 백승수 단장(남궁민)

0개의 댓글