Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[bgm.wav]: Composed by SHK, Source by http://soundholick.com
- #[wave file with 'smb_'] : Copyright (C)Nintendo. All Rights Reserved.
- #Resource Download = https://drive.google.com/open?id=0B6cO1-wuv0zkcklVRW5ISS1xbGs
- import turtle as t
- import random
- import time
- import pygame
- import sys
- score = 0; high_score = 0;
- playing = False;stage = 5;ck_clear=0;
- cnt = 1;item=1;ck_item=0
- t_start=0; t_now=0; t_end=0;
- pygame.init()
- eat_set=[2,3,5,7,9]
- #적설정1
- te = [0,0,0,0,0,0,0,0,0,0]
- for x in range(10):
- te[x] = t.Turtle()
- #먹이지정
- ts = t.Turtle()
- ts.shape("circle")
- ts.color("green")
- ts.speed(0)
- ts.up()
- ts.goto(0,-200)
- #1_UP지정
- tf = t.Turtle()
- tf.shape("triangle")
- tf.color("yellow")
- tf.speed(0)
- tf.up()
- tf.goto(-100,-100)
- tf.ht()
- #스코어,시간 출력
- info = t.Turtle()
- info.shape("square")
- info.color("white")
- info.ht()
- #D-Key설정
- def turn_right():
- t.setheading(0)
- def turn_up():
- t.setheading(90)
- def turn_left():
- t.setheading(180)
- def turn_down():
- t.setheading(270)
- #게임시작
- def start():
- global playing
- global t_start,t_end
- if playing == False:
- t.write("")
- t.goto(0,0)
- playing = True
- t.clear()
- stage_start()
- message("","")
- t_start = time.time()
- play()
- #게임플레이
- def play():
- ang =[0,0,0,0,0,0,0,0,0,0]
- global score
- global playing,stage,ck_clear
- global cnt,item,ck_item,t_now
- t_now = time.time()
- t.forward(10)
- monster(cnt)
- info_out(score)
- for x in range(cnt):
- if random.randint(1,5) == 3:
- ang[x] = te[x].towards(t.pos())
- te[x].setheading(ang[x])
- #speed = score/(100-(stage/2)) + 2
- speed = stage + 3
- if speed > 15:
- speed = 15
- te[x].forward(speed)
- if t.distance(te[x]) < 12:
- if item > 0:
- ddmm = pygame.mixer.Sound("resource/smb_pipe.wav")
- pygame.mixer.Sound.play(ddmm)
- item-=1
- else:
- gameover()
- if t.distance(ts) < 12:
- score = score + 100
- cnt+=1
- coin = pygame.mixer.Sound("resource/smb_coin.wav")
- pygame.mixer.Sound.play(coin)
- star_x = random.randint(-230,230)
- star_y = random.randint(-230,230)
- ts.goto(star_x,star_y)
- if random.randint(1,2) == 2:
- tf.st()
- ck_item=1
- if ck_item==1 and t.distance(tf) < 12:
- score = score + 50
- item+=1
- upup = pygame.mixer.Sound("resource/smb_1-up.wav")
- pygame.mixer.Sound.play(upup)
- star_x = random.randint(-230,230)
- star_y = random.randint(-230,230)
- tf.goto(star_x,star_y)
- tf.ht()
- ck_item=0
- if stage*2 == cnt-1:
- if stage == 5:
- ck_clear=1
- gameover()
- else:
- pygame.mixer.music.stop()
- pygame.mixer.music.load('resource/smb_stage_clear.wav')
- pygame.mixer.music.play()
- cnt=1
- message("Stage Clear","How! Your Great!")
- time.sleep(6);
- stage+=1
- stage_start()
- te_clear()
- message("","")
- if playing:
- t.ontimer(play,100)
- #메세지출력
- def message(m1, m2):
- t.clear()
- t.goto(0,100)
- t.write(m1,False,"center",("",20))
- t.goto(0,-100)
- t.write(m2,False, "center",("",15))
- t.home()
- #스테이지시작 출력
- def stage_start():
- if stage == 1:
- message("Stage1","Too Easy")
- elif stage == 2:
- message("Stage2","Easy Well...")
- elif stage == 3:
- message("Stage3","Normal Well...")
- elif stage == 4:
- message("Stage4","Hard....")
- elif stage == 5:
- message("Stage5","Too Hardest")
- else:
- message("ERR-1W","Welcome To Error Stage!")
- time.sleep(5)
- pygame.mixer.music.load('resource/bgm.wav')
- pygame.mixer.music.play(-1)
- #게임오버/게임클리어출력
- def gameover():
- global score, high_score;
- global playing,stage,ck_clear
- global cnt,item,ck_item
- #text = "Score :"+ str(score)
- #message("GameOver",text)
- if ck_clear == 1:
- pygame.mixer.music.stop()
- pygame.mixer.music.load('resource/smb_world_clear.wav')
- pygame.mixer.music.play()
- message("GameClear","See You Next Time!")
- else:
- pygame.mixer.music.stop()
- pygame.mixer.music.load('resource/smb_gameover.wav')
- pygame.mixer.music.play()
- message("GameOver","You Need More Practice")
- if score > high_score:
- high_score = score
- playing = False
- score = 0;cnt = 1;stage=1;ck_clear=0;item=1;
- t.onkeypress(dummy,"space")
- time.sleep(8)
- title_clear()
- #적설정2/적초기화
- def te_clear():
- for x in range(10):
- te[x].reset()
- #te[x] = t.Turtle()
- #te[x].clear()
- te[x].shape("turtle")
- te[x].speed(0)
- te[x].up()
- te[x].goto(0,(x+1)*50)
- te[x].ht()
- if x==0:te[x].color("darkred")
- elif x==1:te[x].color("red")
- elif x==2:te[x].color("yellow")
- elif x==3:te[x].color("lightgreen")
- elif x==4:te[x].color("green")
- elif x==5:te[x].color("skyblue")
- elif x==6:te[x].color("blue")
- elif x==7:te[x].color("darkblue")
- elif x==8:te[x].color("pink")
- elif x==9:te[x].color("purple")
- else: te[x].color("red")
- #적표시
- def monster(cnt):
- for x in range(cnt):
- te[x].st()
- #라이프/스코어/타임 출력
- def info_out(score):
- global cnt,item,ck_item, t_start, t_now
- playtime = t_now - t_start
- info.clear()
- info.up()
- info.goto(0,230)
- info.write("|Life="+str(item).zfill(2)+"|Score="+str(score).zfill(5)+"|Time="+str(int(playtime/60)).zfill(2)+":"+str(int(playtime%60)).zfill(2)+"|",False,"center",("",10))
- #타이틀출력
- def title_clear():
- global high_score
- te_clear()
- info_out(high_score)
- t.reset()
- t.title("Turtle MAN Ver1.5")
- t.setup(500,500)
- t.bgcolor("orange")
- t.shape("turtle")
- t.speed(0)
- t.up()
- t.color("white")
- message("Turtle MAN","Press Space To Start")
- t.onkeypress(start,"space")
- #말그대로 더미
- def dummy():
- return
- #캐릭터및키보드설정
- title_clear()
- t.onkeypress(turn_right,"Right")
- t.onkeypress(turn_up,"Up")
- t.onkeypress(turn_left,"Left")
- t.onkeypress(turn_down,"Down")
- t.onkeypress(start,"space")
- t.listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement