파이썬 게임 프로젝트 1일차
import pygame
import random
import os
pygame.init()
BLACK = (0, 0, 0)
WHITE = (255,255,255)
resolution = [1280, 720]
screen = pygame.display.set_mode(resolution)
font = pygame.font.Font(None,30)
point = 0
level = 1
pygame.display.set_caption("좌절 금지")
clock = pygame.time.Clock()
set_time = pygame.time.get_ticks()
mob_list = []
speed_level = [1,5]
char = pygame.image.load('char.png')
char_size = pygame.Rect(char.get_rect())
char_size.left = resolution[0] // 2 - char_size.width // 2
char_size.top = resolution[1] - char_size.height
for i in range(6):
mob = pygame.image.load('mob.png')
mob_size = pygame.Rect(mob.get_rect())
mob_size.left = random.randrange(0,resolution[0] - mob_size[3])
mob_size.top = -100
speed = random.randint(1,4)
mob_list.append({'img':mob, 'size': mob_size, 'speed': speed})
game = True
while game:
clock.tick(60)
screen.fill(BLACK)
for event in pygame.event.get():
if event.type == pygame.QUIT:
game = False
break
time = pygame.time.get_ticks() - set_time
if time > 5000:
set_time = pygame.time.get_ticks()
speed_level[0] = speed_level[0] + 1
speed_level[1] = speed_level[1] + 1
level += 1
print(speed_level)
for mob in mob_list:
if mob['size'].top > resolution[1]:
point += 1
mob_list.remove(mob)
mob = pygame.image.load('mob.png')
mob_size = pygame.Rect(mob.get_rect())
mob_size.left = random.randrange(0,resolution[0] - mob_size[3])
mob_size.top = -100
speed = random.randint(speed_level[0],speed_level[1])
mob_list.append({'img':mob, 'size': mob_size, 'speed': speed})
for mob in mob_list:
mob['size'].top += mob['speed']
screen.blit(mob['img'], mob['size'])
point_text = font.render('POINT : ' + str(point) ,True,WHITE)
level_text = font.render('LEVEL : ' + str(level) ,True,WHITE)
screen.blit(point_text, (10,10))
screen.blit(level_text, (10,40))
pygame.display.update()
print('게임종료')
pygame.quit()