[python 게임]공룡 게임 만들기!

이 공룡 게임은 원래 c#이나 c++쪽에서 만들다가 파이썬 쪽으로 온 간단한 게임인데요~ 파이썬용으로 쓰기가 더 좋은 거 같습니다!

pygame을 이용한 공룡 게임 만들기 – 소스공개

# python game with pygame : Jumping dino
# by. BlockDMask

import pygame
import sys

# step1 : set screen, fps
# step2 : show dino, jump dino
# step3 : show tree, move tree

pygame.init()
pygame.display.set_caption(‘Jumping dino’)
MAX_WIDTH = 800
MAX_HEIGHT = 400


def main():
# set screen, fps
screen = pygame.display.set_mode((MAX_WIDTH, MAX_HEIGHT))
fps = pygame.time.Clock()

# dino
imgDino1 = pygame.image.load(‘images/dino1.png’)
imgDino2 = pygame.image.load(‘images/dino2.png’)
dino_height = imgDino1.get_size()[1]
dino_bottom = MAX_HEIGHT – dino_height
dino_x = 50
dino_y = dino_bottom
jump_top = 200
leg_swap = True
is_bottom = True
is_go_up = False

# tree
imgTree = pygame.image.load(‘images/tree.png’)
tree_height = imgTree.get_size()[1]
tree_x = MAX_WIDTH
tree_y = MAX_HEIGHT – tree_height

while True:
screen.fill((255, 255, 255))

# event check
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if is_bottom:
is_go_up = True
is_bottom = False

# dino move
if is_go_up:
dino_y -= 10.0
elif not is_go_up and not is_bottom:
dino_y += 10.0

# dino top and bottom check
if is_go_up and dino_y <= jump_top:
is_go_up = False

if not is_bottom and dino_y >= dino_bottom:
is_bottom = True
dino_y = dino_bottom

# tree move
tree_x -= 12.0
if tree_x <= 0:
tree_x = MAX_WIDTH

# draw tree
screen.blit(imgTree, (tree_x, tree_y))

# draw dino
if leg_swap:
screen.blit(imgDino1, (dino_x, dino_y))
leg_swap = False
else:
screen.blit(imgDino2, (dino_x, dino_y))
leg_swap = True

# update
pygame.display.update()
fps.tick(30)


if __name__ == ‘__main__’:
main()

-> 이렇게 짜여진 쏘스가 한 세개 정도 있는데요. 완전 다든 소스 밑에 링크로 들어가셔서 깃허브로 들어가면 볼 수 있습니다.

이런식으로 파이썬을 실행하면 게임화면이 나타나는데요…ㅇㅅㅇ! 별 다른 기능을 엎지만 점프와 나무가 넘어가는 게임 간단게임입니다!

뭐 나무에 박으면 점수가 깎은다던지 도중에 다른 물건이나 몬스터 같은게 나온다던지는 없는 게임이지만 아주 기초 지식을 다져주는 게임입니다.

-참고 링크

https://blockdmask.tistory.com/419

4 thoughts on “[python 게임]공룡 게임 만들기!”

  1. According to expert opinion, in the near future, new studies with dual inhibitors or multi pathways inhibitors as mono or combination therapies with conventional chemotherapy or other targeted drugs may provide more promising data priligy generic Few things are scarier than facing the prospect of jail

    응답
  2. [url=https://fastpriligy.top/]priligy amazon canada[/url] primidone will decrease the level or effect of enzalutamide by affecting hepatic intestinal enzyme CYP3A4 metabolism

    응답

Leave a Comment