- ํ์ด์ฌ์ผ๋ก ๊ฒ์ ๋ง๋ค๊ธฐ(๊ฐ์ธํ๋ก์ ํธ) ์๋ฃ! : 'Juke Dino'
VSCode, Python 3.x
pygame, os, sys, datetime
๊ณต๋ฃก์ด ์ธํธ๋กํ๋ฉด์์๋ ์์ง์ผ ์ ์์ต๋๋ค!(๋ฐฉํฅํค ์ฌ์ฉ)
[SPACE] ํค๋ฅผ ๋๋ฅด๋ฉด ๋ฉ์ธ ํ๋ฉด์ผ๋ก ์ด๋ํฉ๋๋ค!(์ด๋์ Please Wait ๋ฌธ๊ตฌ ๋์)
์ฐฝ ํ๋, ์ถ์๊ฐ ๊ฐ๋ฅํฉ๋๋ค! (F1์ผ๋ก ํ๋, F2๋ก ์ถ์)
๊ณต๋ฃก์ด ๋ฌผ์ฒด์ ๋ฟ์ผ๋ฉด ์์
์ ๋ํ ์ค๋ช
์ด ๋์ค๋ฉด์ ์์
์ด ์ฌ์๋ฉ๋๋ค! (์ค๋ฅธ์ชฝ ์๋จ ๋์ค๋ ์์
์ด ํ์๋จ, ๋ค๋ฅธ ์ฅฌํฌ๋ฐ์ค์ ๋ฟ์ผ๋ฉด ๊ธฐ์กด ์ฌ์ํ๋ ์์
์ข
๋ฃ ํ ์๋ก์ด ์์
์ฌ์๋จ)
[SPACE] ํค ๋๋ฅผ ์ ์์
์ข
๋ฃ๋จ
[ESC] ํค ๋๋ฅผ ์ '์ข
๋ฃํ์๊ฒ ์ต๋๊น?' ํ๋ฉด์ ์ถ๋ ฅ
์ธํธ๋ก ํ๋ฉด(๊ณต๋ฃก ์์ง์ ๊ตฌํ) -> ๋ฉ์ธ ํ๋ฉด ์ ์ ๋ฐ ๊ธฐ๋ฅ ์ถ๊ฐ(ํค ์ค์ , ํ์ด๋จธ ๋ฐ ์๊ฐ๊ธฐ๋ฅ ์ถ๊ฐ, ๊ธ์จ ๋์ฐ๊ธฐ ๊ธฐ๋ฅ ์ถ๊ฐ, ์ถฉ๋์ฒ๋ฆฌ, ์ฐฝ ํ๋์ถ์ ๊ธฐ๋ฅ ์ถ๊ฐ, ์์ ์ค์ ) -> ์ธํธ๋กํ๋ฉด๊ณผ ๋ฉ์ธํ๋ฉด ์ฐ๊ฒฐ -> ํ ์คํธ -> ์ด๋ฏธ์ง ํ์ผ ์ ํ๊ธฐ
import os
import pygame
import sys
from pygame import *
from datetime import datetime
current_path = os.path.dirname(__file__) # ํ์ฌ ํ์ผ์ ์์น ๋ฐํ
image_path = os.path.join(current_path, "images") # images ํด๋ ์์น ๋ฐํ
music_path = os.path.join(current_path, "music") # music ํด๋ ์์น ๋ฐํ
# ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
background = pygame.image.load(
os.path.join(image_path, "white.png"))
# ์บ๋ฆญํฐ(์คํ๋ผ์ดํธ) ๋ถ๋ฌ์ค๊ธฐ
character = pygame.image.load(
os.path.join(image_path, "dino1.png"))
# ์๋ฆฌ์ด๊ธฐํ
se_afternoon = None
se_bug = None
se_button = None
se_chill = None
se_clear = None
se_coin = None
se_fire = None
se_loading = None
se_morning = None
se_night = None
se_npc = None
se_opening = None
se_quest = None
se_sleep = None
se_sunny = None
se_woman = None
def play():
# ์๋ฆฌ๋ฐ์ดํฐ
global se_afternoon, se_coin, se_morning, se_, se_night, se_sleep, se_chill, se_npc, se_clear, se_loading, se_fire, se_bug, se_opening, se_quest, se_sunny, se_button, se_woman
# ์ด๊ธฐํ
pygame.init()
# ํ๋ฉด ํ์ดํ ์ค์
pygame.display.set_caption("Juke Dino") # ๊ฒ์ ์ด๋ฆ
# Font ์ ์
game_font = pygame.font.Font(None, 35)
game_result_1 = "Good Afternoon"
game_result_2 = "There are swarm of fireflies"
game_result_3 = "Stay Chill Hear"
game_result_4 = "Hello, Here is office"
game_result_5 = "I gathered some wood"
game_result_6 = "Good Morning"
game_result_7 = "Good Night"
game_result_8 = "Hello, I'm Bob"
game_result_9 = "This is opening song"
game_result_10 = "This is quest"
game_result_11 = "Time to Sleep"
game_result_12 = "Sunny Day"
sound_off = "Sound OFF"
want_quit = "Do you Want Quit?"
song_msg = "None"
# ๋ ์ง ์ถ๋ ฅ
now = datetime.now()
game_now = "Today Date : "+str(now.year)+"."+str(now.month)+"."+str(now.day) + \
"."
# ํ๋ฉด ํฌ๊ธฐ ์ค์
screen_width = 840 # ๊ฐ๋ก ํฌ๊ธฐ
screen_height = 600 # ์ธ๋ก ํฌ๊ธฐ
screen = pygame.display.set_mode((screen_width, screen_height))
# FPS
clock = pygame.time.Clock()
# ์๋ฆฌ
se_afternoon = pygame.mixer.Sound(
os.path.join(music_path, "afternoon.mp3"))
se_bug = pygame.mixer.Sound(
os.path.join(music_path, "bug.mp3"))
se_button = pygame.mixer.Sound(
os.path.join(music_path, "button.mp3"))
se_chill = pygame.mixer.Sound(
os.path.join(music_path, "chill.mp3"))
se_clear = pygame.mixer.Sound(
os.path.join(music_path, "clear.mp3"))
se_coin = pygame.mixer.Sound(
os.path.join(music_path, "coin.mp3"))
se_fire = pygame.mixer.Sound(
os.path.join(music_path, "fire.mp3"))
se_loading = pygame.mixer.Sound(
os.path.join(music_path, "loading.mp3"))
se_morning = pygame.mixer.Sound(
os.path.join(music_path, "morning.mp3"))
se_night = pygame.mixer.Sound(
os.path.join(music_path, "night.mp3"))
se_npc = pygame.mixer.Sound(
os.path.join(music_path, "npc.mp3"))
se_opening = pygame.mixer.Sound(
os.path.join(music_path, "opening.mp3"))
se_quest = pygame.mixer.Sound(
os.path.join(music_path, "quest.mp3"))
se_sleep = pygame.mixer.Sound(
os.path.join(music_path, "sleep.mp3"))
se_sunny = pygame.mixer.Sound(
os.path.join(music_path, "sunny.mp3"))
se_woman = pygame.mixer.Sound(
os.path.join(music_path, "woman.mp3"))
se_clear.play()
character_size = character.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
character_width = character_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐ
character_height = character_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
character_x_pos = (screen_width / 2) - (character_width /
2) # ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
character_y_pos = screen_height - character_height
# ์บ๋ฆญํฐ๊ฐ ์ด๋ํ ์ขํ
to_x = 0
to_y = 0
# ์บ๋ฆญํฐ ์ด๋ ์๋
character_speed = 0.13
# afternoon ์บ๋ฆญํฐ
afternoon = pygame.image.load(
os.path.join(image_path, "1.png"))
afternoon_size = afternoon.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
afternoon_width = afternoon_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
afternoon_height = afternoon_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ์ผ์ชฝ ์๋จ
afternoon_x_pos = 300
afternoon_y_pos = 100
# bug ์บ๋ฆญํฐ
bug = pygame.image.load(
os.path.join(image_path, "2.png"))
bug_size = bug.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
bug_width = bug_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
bug_height = bug_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
bug_x_pos = 540
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
bug_y_pos = 100
# chill ์บ๋ฆญํฐ
chill = pygame.image.load(
os.path.join(image_path, "3.png"))
chill_size = chill.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
chill_width = chill_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
chill_height = chill_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
chill_x_pos = 420
chill_y_pos = 200
# clear ์บ๋ฆญํฐ
clear = pygame.image.load(
os.path.join(image_path, "4.png"))
clear_size = clear.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
clear_width = clear_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
clear_height = clear_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
clear_x_pos = 60
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
clear_y_pos = 400
# fire ์บ๋ฆญํฐ
fire = pygame.image.load(
os.path.join(image_path, "5.png"))
fire_size = fire.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
fire_width = fire_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
fire_height = fire_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
fire_x_pos = 720
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
fire_y_pos = 100
# morning ์บ๋ฆญํฐ
morning = pygame.image.load(
os.path.join(image_path, "6.png"))
morning_size = morning.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
morning_width = morning_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
morning_height = morning_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
morning_x_pos = 180
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
morning_y_pos = 200
# night ์บ๋ฆญํฐ
night = pygame.image.load(
os.path.join(image_path, "7.png"))
night_size = night.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
night_width = night_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
night_height = night_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
night_x_pos = 720
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
night_y_pos = 200
# npc ์บ๋ฆญํฐ
npc = pygame.image.load(
os.path.join(image_path, "8.png"))
npc_size = npc.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
npc_width = npc_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
npc_height = npc_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
npc_x_pos = 400
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
npc_y_pos = 400
# opening ์บ๋ฆญํฐ
opening = pygame.image.load(
os.path.join(image_path, "9.png"))
opening_size = opening.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
opening_width = opening_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
opening_height = opening_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
opening_x_pos = 240
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
opening_y_pos = 400
# quest ์บ๋ฆญํฐ
quest = pygame.image.load(
os.path.join(image_path, "10.png"))
quest_size = quest.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
quest_width = quest_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
quest_height = quest_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
quest_x_pos = 540
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
quest_y_pos = 400
# sleep ์บ๋ฆญํฐ
sleep = pygame.image.load(
os.path.join(image_path, "11.png"))
sleep_size = sleep.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
sleep_width = sleep_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
sleep_height = sleep_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
sleep_x_pos = 720
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
sleep_y_pos = 400
# sunny ์บ๋ฆญํฐ
sunny = pygame.image.load(
os.path.join(image_path, "12.png"))
sunny_size = sunny.get_rect().size # ์ด๋ฏธ์ง์ ํฌ๊ธฐ๋ฅผ ๊ตฌํด์ด
sunny_width = sunny_size[0] # ์บ๋ฆญํฐ์ ๊ฐ๋ก ํฌ๊ธฐx
sunny_height = sunny_size[1] # ์บ๋ฆญํฐ์ ์ธ๋ก ํฌ๊ธฐ
# ํ๋ฉด ๊ฐ๋ก์ ์ ๋ฐ ํฌ๊ธฐ์ ํด๋นํ๋ ๊ณณ์ ์์น (๊ฐ๋ก)
sunny_x_pos = 60
# ํ๋ฉด ์ธ๋ก ํฌ๊ธฐ ๊ฐ์ฅ ์๋์ ํด๋นํ๋ ๊ณณ์ ์์น (์ธ๋ก)
sunny_y_pos = 100
# ์ด๋ฒคํธ ๋ฃจํ
# ๊ฒ์์ด ์งํ์ค์ธ๊ฐ?
running = True
while running:
dt = clock.tick(60) # ๊ฒ์ํ๋ฉด์ ์ด๋น ํ๋ ์ ์๋ฅผ ์ค์
for event in pygame.event.get(): # ์ด๋ค ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ์๋๊ฐ?
if event.type == pygame.QUIT: # ์ฐฝ์ด ๋ซํ๋ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ์๋๊ฐ?
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN: # ํค๊ฐ ๋๋ฌ์ก๋์ง ํ์ธ
if event.key == pygame.K_LEFT: # ์บ๋ฆญํฐ๋ฅผ ์ผ์ชฝ์ผ๋ก
to_x -= character_speed # to_x = to_x - 5
elif event.key == pygame.K_RIGHT: # ์บ๋ฆญํฐ๋ฅผ ์ค๋ฅธ์ชฝ์ผ๋ก
to_x += character_speed
elif event.key == pygame.K_UP: # ์บ๋ฆญํฐ๋ฅผ ์๋ก
to_y -= character_speed
elif event.key == pygame.K_DOWN: # ์บ๋ฆญํฐ๋ฅผ ์๋๋ก
to_y += character_speed
elif event.key == K_F1: # F1ํค ๋๋ฅด๋ฉด ์ฐฝํ๋
screen = pygame.display.set_mode(
(screen_width, screen_height), FULLSCREEN)
elif event.key == K_F2: # F2ํค ๋๋ฅด๋ฉด ์ฐฝ ์ถ์
screen = pygame.display.set_mode(
(screen_width, screen_height))
elif event.key == pygame.K_SPACE: # space ๋๋ฅด๋ฉด ๋ชจ๋ ์์
๋ฉ์ถค
song_off()
msg = game_font.render(
sound_off, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "None"
elif event.key == pygame.K_ESCAPE: # ESC๋๋ฅด๋ฉด ์๋ฌด๊ฒ๋ ๋์ ์ํจ
msg = game_font.render(
want_quit, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(1000)
# if event.type == pygame.KEYDOWN: # ๋ฐฉํฅํค๋ฅผ ๋ผ๋ฉด ์ฃผ์ธ๊ณต ์บ๋ฆญํฐ ๋ฉ์ถค
# if event.key == pygame.K_a:
# running = False
# elif event.key == pygame.K_n:
# running = True
if event.type == pygame.KEYUP: # ๋ฐฉํฅํค๋ฅผ ๋ผ๋ฉด ์ฃผ์ธ๊ณต ์บ๋ฆญํฐ ๋ฉ์ถค
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
to_x = 0
elif event.key == pygame.K_UP or event.key == pygame.K_DOWN:
to_y = 0
character_x_pos += to_x * dt
character_y_pos += to_y * dt
# ๊ฐ๋ก ๊ฒฝ๊ณ๊ฐ ์ฒ๋ฆฌ
if character_x_pos < 0:
character_x_pos = 0
elif character_x_pos > screen_width - character_width:
character_x_pos = screen_width - character_width
# ์ธ๋ก ๊ฒฝ๊ณ๊ฐ ์ฒ๋ฆฌ
if character_y_pos < 0:
character_y_pos = 0
elif character_y_pos > screen_height - character_height:
character_y_pos = screen_height - character_height
# ์ถฉ๋ ์ฒ๋ฆฌ๋ฅผ ์ํ rect ์ ๋ณด ์
๋ฐ์ดํธ
character_rect = character.get_rect()
character_rect.left = character_x_pos
character_rect.top = character_y_pos
afternoon_rect = afternoon.get_rect()
afternoon_rect.left = afternoon_x_pos
afternoon_rect.top = afternoon_y_pos
bug_rect = bug.get_rect()
bug_rect.left = bug_x_pos
bug_rect.top = bug_y_pos
chill_rect = chill.get_rect()
chill_rect.left = chill_x_pos
chill_rect.top = chill_y_pos
clear_rect = clear.get_rect()
clear_rect.left = clear_x_pos
clear_rect.top = clear_y_pos
fire_rect = fire.get_rect()
fire_rect.left = fire_x_pos
fire_rect.top = fire_y_pos
morning_rect = morning.get_rect()
morning_rect.left = morning_x_pos
morning_rect.top = morning_y_pos
night_rect = night.get_rect()
night_rect.left = night_x_pos
night_rect.top = night_y_pos
npc_rect = npc.get_rect()
npc_rect.left = npc_x_pos
npc_rect.top = npc_y_pos
opening_rect = opening.get_rect()
opening_rect.left = opening_x_pos
opening_rect.top = opening_y_pos
quest_rect = quest.get_rect()
quest_rect.left = quest_x_pos
quest_rect.top = quest_y_pos
sleep_rect = sleep.get_rect()
sleep_rect.left = sleep_x_pos
sleep_rect.top = sleep_y_pos
sunny_rect = sunny.get_rect()
sunny_rect.left = sunny_x_pos
sunny_rect.top = sunny_y_pos
# afternoon ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(afternoon_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = afternoon_y_pos+afternoon_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_afternoon.play()
se_coin.play()
msg = game_font.render(
game_result_1, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Afternoon"
# bug ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(bug_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = bug_y_pos+bug_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_bug.play()
se_coin.play()
msg = game_font.render(
game_result_2, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Bug"
# chill ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(chill_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = chill_y_pos+chill_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_chill.play()
se_coin.play()
msg = game_font.render(
game_result_3, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Chill"
# clear ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(clear_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = clear_y_pos+clear_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_clear.play()
se_coin.play()
msg = game_font.render(
game_result_4, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Clear"
# fire ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(fire_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = fire_y_pos+fire_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_fire.play()
se_coin.play()
msg = game_font.render(
game_result_5, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Fire"
# morning ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(morning_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = morning_y_pos+morning_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_morning.play()
se_coin.play()
msg = game_font.render(
game_result_6, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Morning"
# night ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(night_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = night_y_pos+night_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_night.play()
se_coin.play()
msg = game_font.render(
game_result_7, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Night"
# npc ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(npc_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = npc_y_pos+npc_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_npc.play()
se_coin.play()
msg = game_font.render(
game_result_8, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "NPC"
# opening ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(opening_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = opening_y_pos+opening_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_opening.play()
se_coin.play()
msg = game_font.render(
game_result_9, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Opening"
# quest ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(quest_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = quest_y_pos+quest_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_quest.play()
se_coin.play()
msg = game_font.render(
game_result_10, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Quest"
# sleep ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(sleep_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = sleep_y_pos+sleep_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_sleep.play()
se_coin.play()
msg = game_font.render(
game_result_11, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Sleep"
# sunny ์ถฉ๋ ์ฒดํฌ
if character_rect.colliderect(sunny_rect):
print("์ถฉ๋ํ์ด์")
character_y_pos = sunny_y_pos+sunny_height
# ์ถฉ๋์ ์ฌ์ด๋
song_off()
se_sunny.play()
se_coin.play()
msg = game_font.render(
game_result_12, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), int(screen_height / 2)))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
song_msg = "Sunny"
screen.blit(background, (0, 0)) # ๋ฐฐ๊ฒฝ ๊ทธ๋ฆฌ๊ธฐ
# ์ฃผ์ธ๊ณต์บ๋ฆญํฐ ๊ทธ๋ฆฌ๊ธฐ
screen.blit(character, (character_x_pos, character_y_pos))
# ๋ค๋ฅธ ์บ๋ฆญํฐ ๊ทธ๋ฆฌ๊ธฐ
screen.blit(afternoon, (afternoon_x_pos, afternoon_y_pos))
screen.blit(bug, (bug_x_pos, bug_y_pos))
screen.blit(chill, (chill_x_pos, chill_y_pos))
screen.blit(clear, (clear_x_pos, clear_y_pos))
screen.blit(fire, (fire_x_pos, fire_y_pos))
screen.blit(morning, (morning_x_pos, morning_y_pos))
screen.blit(night, (night_x_pos, night_y_pos))
screen.blit(npc, (npc_x_pos, npc_y_pos))
screen.blit(opening, (opening_x_pos, opening_y_pos))
screen.blit(quest, (quest_x_pos, quest_y_pos))
screen.blit(sleep, (sleep_x_pos, sleep_y_pos))
screen.blit(sunny, (sunny_x_pos, sunny_y_pos))
# ํ์ด๋จธ:๊ฒฝ๊ณผ์๊ฐ ๊ณ์ฐ (์ค๋ฒ์๊ฐ- ๊ฒ์์์์๊ฐ=0=๊ฒ์์ข
๋ฃ)
sec = int(pygame.time.get_ticks()/1000)
timer = game_font.render("Playtime : " +
str(int(pygame.time.get_ticks()/1000/60))+"m", True, (0, 0, 0)) # ์ถ๋ ฅํ ๊ธ์, True, ๊ธ์ ์์
screen.blit(timer, (10, 10))
msg = game_font.render(
game_now, True, (0, 0, 0))
screen.blit(msg, (10, 40))
msg_2 = game_font.render(
'Play Now : '+song_msg, True, (0, 0, 0))
screen.blit(msg_2, (540, 40))
pygame.display.update() # ๊ฒ์ํ๋ฉด์ ๋ค์ ๊ทธ๋ฆฌ๊ธฐ!
def intro():
global sec, se_opening
pygame.init()
screen_width = 840
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('Juke Dino')
game_font = pygame.font.Font(None, 35)
background = pygame.image.load(
os.path.join(image_path, "white.png"))
character = pygame.image.load(
os.path.join(image_path, "dino1.png"))
character_size = character.get_rect().size
character_width = character_size[0]
character_height = character_size[1]
character_x_pos = (screen_width/2-character_width/2)
character_y_pos = (screen_height/2)
se_opening = pygame.mixer.Sound(
os.path.join(music_path, "opening.mp3"))
se_opening.play()
to_x = 0
to_y = 0
loading = "Pleas Wait ..."
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
to_x -= 2
elif event.key == pygame.K_RIGHT:
to_x += 2
elif event.key == pygame.K_UP:
to_y -= 2
elif event.key == pygame.K_DOWN:
to_y += 2
elif event.key == pygame.K_SPACE:
sec = 0
msg = game_font.render(
loading, True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), 400))
screen.blit(msg, msg_rect)
pygame.display.update()
pygame.time.delay(500)
se_opening.stop()
play()
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
to_x = 0
elif event.key == pygame.K_UP or event.key == pygame.K_DOWN:
to_y = 0
character_x_pos += to_x
character_y_pos += to_y
if character_x_pos < 0:
character_x_pos = 0
elif character_x_pos > screen_width-character_width:
character_x_pos = screen_width-character_width
if character_y_pos < 0:
character_y_pos = 0
elif character_y_pos > screen_height-character_height:
character_y_pos = screen_height-character_height
screen.blit(background, (0, 0))
screen.blit(character, (character_x_pos, character_y_pos))
msg = game_font.render(
'Juke Dino', True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), 200))
screen.blit(msg, msg_rect)
msg = game_font.render(
'Press [SPACE] to Start', True, (0, 0, 0))
msg_rect = msg.get_rect(
center=(int(screen_width / 2), 500))
screen.blit(msg, msg_rect)
pygame.display.update() # ๊ฒ์ํ๋ฉด์ ๋ค์ ๊ทธ๋ฆฌ๊ธฐ!
def main():
intro()
def song_off():
global se_afternoon, se_coin, se_morning, se_, se_night, se_sleep, se_chill, se_npc, se_clear, se_loading, se_fire, se_bug, se_opening, se_quest, se_sunny, se_button, se_woman
se_afternoon.stop()
se_bug.stop()
se_button.stop()
se_chill.stop()
se_clear.stop()
se_coin.stop()
se_fire.stop()
se_loading.stop()
se_morning.stop()
se_night.stop()
se_npc.stop()
se_opening.stop()
se_quest.stop()
se_sleep.stop()
se_sunny.stop()
se_woman.stop()
se_coin.play()
if __name__ == '__main__':
main()
๊ฐ์์ง ์ด๋ฏธ์ง
๊ณต๋ฃก ์ด๋ฏธ์ง
๊ณ ์์ด ์ด๋ฏธ์ง
์๋ฆฌ 1
์๋ฆฌ 2
ํ์ด๊ฒ์์ด ์๋๋๋ผ๋ ์ถํ ๊ฒ์์ ๋ค๋ฅธ ํด๋ก ์ ์ํ๊ฒ ๋๋ค๋ฉด ์ด๋ ๊ฒ ๋ฐ์ ์์ผ ๋ณด๊ณ ์ถ์ต๋๋ค!
ํ๋ก์ ํธ๋ฅผ ๋ง๋ค๊ธฐ ์ pygame์ ์ด์ฉํด ์ด๋ค ํ๋ก์ ํธ๋ฅผ ๋ง๋ค ์ ์๋์ง ๋ ํผ๋ฐ์ค๋ฅผ ๋ง์ด ์ฐพ์๋ณด๊ณ ๊ธฐ๋ณธ ๊ธฐ๋ฅ์ ์ตํ๋ ์๊ฐ์ ํ๋ฃจ์ ๋ ์ก์๋ค. ์ฒ์์ ์ด๋ค ๊ฒ์์ ๋ง๋ค์ง ๊ณ ๋ฏผ์ด ๋ง์์๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ ๊ฐํผ๋ฅผ ์ก์๋ ๊ฒ์ '๋ด๊ฐ ์ข์ํ๋ ๊ฒ์์์ ์ฐ์ด๋ ๊ธฐ๋ฅ์ ๊ตฌํํด๋ณด์.' ์๋ค. ์ญ์ ๋ฌด์ธ๊ฐ ๋ง๋ค ๋ ๋์ ์ ์ ์ด ๋ด๊ธธ์๋ก ๋ ์ฌ๋ฐ๊ณ ์ฆ๊ฒ๋ค๊ณ ๋๊ผ๋ ํ๋ก์ ํธ์๋ค.
์ค๋ ์์ ํ ์์ธํ ์ฝ๋๋ ๋์_๊นํ๋ธ ์ ๊ฒ์๋์ด ์์ต๋๋ค ๐ฉ
๊ณ ์ ๋ง์ผ์ จ์ต๋๋ค :)
๊ธ ์ ๋ฆฌ ์์ฒญ ์ํ์๋ค์ ใ ใ ใ
์ด ๊ธฐ์ธ๋ชฐ์ ํด๋์ค์ ํจ์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ฒ ๋ ๋ฆฌํํ ๋ง์ ๊ฐ๋ณ๊ฒ ํด๋ณด์๋ ๊ฒ์ ๊ถ์ฅ๋๋ฆฝ๋๋ค!
๊ฐ๋ฐ์ ํ๋ค ๋ณด๋ฉด ์๋ฌ๊ฐ ์ข ์ข ๋๊ฒ ๋ฉ๋๋ค. ์ฆ ์๋ฌ ์ฝ๋๋ ์๋ฒฝํ๊ฒ ์ก์ ์ ์์ต๋๋ค. ๊ทธ๋ผ ์ด๋ฅผ ์ด๋ป๊ฒ ๋ง์ ์ ์์์ง ๊ณ ๋ฏผํด๋ณด์ธ์.
(์์ธ์ฒ๋ฆฌ ๊ฒ์)
๋ง์ง๋ง์ผ๋ก ๊ฒ์์ด๋ ํ๋ก๊ทธ๋จ์ ๋ง๋ค๊ฒ ๋๋ฉด ์กฐ๊ฑด๋ฌธ์ ๊ฝค ๋ง์ด ์ ์ํ๊ฒ ๋๋ฉฐ
์์ฐ์ค๋ฝ๊ฒ ์ฝ๋๊ฐ ์ฝ๊ฐ ์ง์ ๋ถํด์ง๋๋ค.
์ด๋ด๋ ํ์ด์ฌ์์๋ ์ด๋ป๊ฒ ์ฝ๋๋ฅผ ๊น๋ํ๊ฒ ์ ๋ฆฌํ ์ ์๋์ง ๊ฒ์ํด๋ณด์ธ์ :)
(switch ๋ฌธ๋ฒ)
์ด๋ ๊ฒ ๊ณต๋ถ๋ฅผ ์ด์ฌํ ํ์ ๋งํผ ๋ค์ ํ๋ก์ ํธ๋ ์ ํด๋ด์ค ์ ์์๊ฒ ์ ๋๋ค.
๋ง์ง๋ง์ผ๋ก ์ธ์คํ ํ๋ก์ ํธ๋ ์ ๋ถํ๋๋ฆฝ๋๋ค!