음성고등학교 로고이미지

RSS 페이스북 공유하기 트위터 공유하기 카카오톡 공유하기 카카오스토리 공유하기 네이버밴드 공유하기 프린트하기
10123 한재민 파이썬 작품
좋아요:0
작성자 한재민 등록일 19.12.18 조회수 170
첨부파일

키보드의 A,D 버튼으로 움직입니다 

 

import pygame

import sys

import random

import time

 

WIDTH = 480

HEIGHT = 720

 

def captionscore(count):

    global Field

    font = pygame.font.Font("ch.ttf", 30)

    text = font.render("점수:" +str(count), True, (255,255,255))

    Field.blit(text, (10,0))

 

def captiondifficult(dif):

    global Field

    font = pygame.font.Font("ch.ttf", 30)

    text = font.render("난이도:" +str(dif), True, (255,255,255))

    Field.blit(text, (10,30))

 

def gameover():

    global Field,Buhi

    textfont = pygame.font.Font("ch.ttf", 50)

    text = textfont.render("GAME OVER", True, (255,0,0))

    textpos = text.get_rect()

    Field.blit(text,(130,300))

    pygame.display.update()

    pygame.mixer.music.stop()

    Buhi.play()

    time.sleep(3)

    pygame.mixer.music.play(-1)

    rungame()

 

def drawobject(obj,x,y):

    global Field

    Field.blit(obj, (x,y))

 

def initgame():

    global Field,Frame,Background,Hawk,Buhi,Handy

    pygame.init()

    Field = pygame.display.set_mode((WIDTH,HEIGHT))

    Frame = pygame.time.Clock()

    pygame.display.set_caption("The Caption Of Knight , HAWK")

    Background = pygame.image.load("BG.png")

    Hawk = pygame.image.load("Hawkimg.png")

    Handy = pygame.image.load("Handy.png")

    pygame.mixer.music.load("BGM.mp3")

    pygame.mixer.music.play(-1)

    Buhi = pygame.mixer.Sound("Buhi.wav")

 

def rungame():

    global Field,Frame,Background,Hawk,Handy

 

    Hawksize = Hawk.get_rect().size

    Hawkwidth = Hawksize[0]

    Hawkheight = Hawksize[1]

 

    x = 200

    y = 557

    HawkXpos=0

    Score = 0

    Difficult = 1

 

    fireball = pygame.image.load("Fireball.png")

    Fireballsize = fireball.get_rect().size

    Fireballwidth = Fireballsize[0]

    Fireballheight = Fireballsize[1]

 

    fireballX = random.randrange(0 , WIDTH - Fireballwidth)

    fireballY = 0

    fireballspeed = 10

        

    Ongame= False

    while not Ongame:

        for event in pygame.event.get():

            if event.type in [pygame.QUIT]:

                pygame.quit()

                sys.exit()

 

            if event.type in [pygame.KEYDOWN]:

                if event.key == pygame.K_a:

                    HawkXpos -= 7

 

                elif event.key == pygame.K_d:

                    HawkXpos += 7

 

            if event.type in [pygame.KEYUP]:

                if event.key == pygame.K_a:

                    HawkXpos = 0

 

                elif event.key == pygame.K_d:

                    HawkXpos = 0

        x += HawkXpos

        if x < 0:

            x = 0

        elif x > WIDTH - Hawkwidth:

            x= WIDTH - Hawkwidth

 

        fireballY += fireballspeed

 

        if fireballY > 600:

            Fireballsize = fireball.get_rect().size

            Fireballwidth = Fireballsize[0]

            Fireballheight = Fireballsize[1]

            fireballX = random.randrange(0 , WIDTH - Fireballwidth)

            fireballY = 0

 

            Score += 100

            if Score % 1000 == 0:

                Difficult += 1

                fireballspeed +=1

 

        if y < fireballY + Fireballheight - 23:

            if(fireballX> x and fireballX < x + Hawkwidth - 23) or \

                (fireballX + Fireballwidth - 23 > x and fireballX + Fireballwidth - 23 < x + Hawkwidth):

                    gameover()

        

        drawobject(Background, 0,0)

 

        drawobject(Hawk, x,y)

 

        drawobject(Handy, fireballX-12,0)

 

        drawobject(fireball, fireballX,fireballY)

 

        captionscore(Score)

 

        captiondifficult(Difficult)

        

        pygame.display.update()

 

        Frame.tick(60)

 

    pygame.quit()

 

initgame()

rungame()

 

 

이전글 임유리, 전지윤 작품보고서
다음글 10221최재민 파이썬 타자게임