MUstar

IoT Python3 0816 - Turtle Man

Aug 20th, 2017
287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #[bgm.wav]: Composed by SHK, Source by http://soundholick.com
  2. #[wave file with 'smb_'] : Copyright (C)Nintendo. All Rights Reserved.
  3. #Resource Download = https://drive.google.com/open?id=0B6cO1-wuv0zkcklVRW5ISS1xbGs
  4.  
  5. import turtle as t
  6. import random
  7. import time
  8. import pygame
  9. import sys
  10.  
  11. score = 0; high_score = 0;
  12. playing = False;stage = 5;ck_clear=0;
  13. cnt = 1;item=1;ck_item=0
  14. t_start=0; t_now=0; t_end=0;
  15.  
  16.  
  17. pygame.init()
  18. eat_set=[2,3,5,7,9]
  19.  
  20. #적설정1
  21. te = [0,0,0,0,0,0,0,0,0,0]
  22. for x in range(10):
  23.     te[x] = t.Turtle()
  24.  
  25. #먹이지정
  26. ts = t.Turtle()
  27. ts.shape("circle")
  28. ts.color("green")
  29. ts.speed(0)
  30. ts.up()
  31. ts.goto(0,-200)
  32.  
  33. #1_UP지정
  34. tf = t.Turtle()
  35. tf.shape("triangle")
  36. tf.color("yellow")
  37. tf.speed(0)
  38. tf.up()
  39. tf.goto(-100,-100)
  40. tf.ht()
  41.  
  42. #스코어,시간 출력
  43. info = t.Turtle()
  44. info.shape("square")
  45. info.color("white")
  46. info.ht()
  47.  
  48.  
  49. #D-Key설정
  50. def turn_right():
  51.     t.setheading(0)
  52. def turn_up():
  53.     t.setheading(90)
  54. def turn_left():
  55.     t.setheading(180)
  56. def turn_down():
  57.     t.setheading(270)
  58.  
  59. #게임시작
  60. def start():
  61.     global playing
  62.     global t_start,t_end
  63.     if playing == False:
  64.         t.write("")
  65.         t.goto(0,0)
  66.         playing = True
  67.         t.clear()
  68.         stage_start()
  69.         message("","")
  70.         t_start = time.time()
  71.         play()
  72.  
  73. #게임플레이        
  74. def play():
  75.     ang =[0,0,0,0,0,0,0,0,0,0]
  76.     global score
  77.     global playing,stage,ck_clear
  78.     global cnt,item,ck_item,t_now
  79.     t_now = time.time()
  80.     t.forward(10)
  81.     monster(cnt)
  82.     info_out(score)
  83.     for x in range(cnt):
  84.         if random.randint(1,5) == 3:
  85.             ang[x] = te[x].towards(t.pos())
  86.             te[x].setheading(ang[x])
  87.         #speed = score/(100-(stage/2)) + 2
  88.         speed = stage + 3
  89.         if speed > 15:
  90.             speed = 15
  91.         te[x].forward(speed)
  92.         if t.distance(te[x]) < 12:
  93.             if item > 0:
  94.                 ddmm = pygame.mixer.Sound("resource/smb_pipe.wav")
  95.                 pygame.mixer.Sound.play(ddmm)
  96.                 item-=1
  97.             else:
  98.                 gameover()        
  99.     if t.distance(ts) < 12:
  100.         score = score + 100
  101.         cnt+=1
  102.         coin = pygame.mixer.Sound("resource/smb_coin.wav")
  103.         pygame.mixer.Sound.play(coin)
  104.         star_x = random.randint(-230,230)
  105.         star_y = random.randint(-230,230)
  106.         ts.goto(star_x,star_y)
  107.         if random.randint(1,2) == 2:
  108.             tf.st()
  109.             ck_item=1
  110.     if ck_item==1 and t.distance(tf) < 12:
  111.         score = score + 50
  112.         item+=1
  113.         upup = pygame.mixer.Sound("resource/smb_1-up.wav")
  114.         pygame.mixer.Sound.play(upup)
  115.         star_x = random.randint(-230,230)
  116.         star_y = random.randint(-230,230)
  117.         tf.goto(star_x,star_y)
  118.         tf.ht()
  119.         ck_item=0
  120.     if stage*2 == cnt-1:
  121.         if stage == 5:
  122.             ck_clear=1
  123.             gameover()
  124.         else:
  125.             pygame.mixer.music.stop()
  126.             pygame.mixer.music.load('resource/smb_stage_clear.wav')
  127.             pygame.mixer.music.play()
  128.             cnt=1
  129.             message("Stage Clear","How! Your Great!")
  130.             time.sleep(6);
  131.             stage+=1
  132.             stage_start()
  133.             te_clear()
  134.             message("","")
  135.     if playing:
  136.         t.ontimer(play,100)
  137.  
  138. #메세지출력
  139. def message(m1, m2):
  140.     t.clear()
  141.     t.goto(0,100)
  142.     t.write(m1,False,"center",("",20))
  143.     t.goto(0,-100)
  144.     t.write(m2,False, "center",("",15))
  145.     t.home()
  146.  
  147. #스테이지시작 출력
  148. def stage_start():
  149.     if stage == 1:
  150.         message("Stage1","Too Easy")
  151.     elif stage == 2:
  152.         message("Stage2","Easy Well...")
  153.     elif stage == 3:
  154.         message("Stage3","Normal Well...")
  155.     elif stage == 4:
  156.         message("Stage4","Hard....")
  157.     elif stage == 5:
  158.         message("Stage5","Too Hardest")
  159.     else:
  160.         message("ERR-1W","Welcome To Error Stage!")
  161.     time.sleep(5)
  162.     pygame.mixer.music.load('resource/bgm.wav')
  163.     pygame.mixer.music.play(-1)
  164.  
  165. #게임오버/게임클리어출력  
  166. def gameover():
  167.     global score, high_score;
  168.     global playing,stage,ck_clear
  169.     global cnt,item,ck_item
  170.     #text = "Score :"+ str(score)
  171.     #message("GameOver",text)
  172.     if ck_clear == 1:
  173.         pygame.mixer.music.stop()
  174.         pygame.mixer.music.load('resource/smb_world_clear.wav')
  175.         pygame.mixer.music.play()
  176.         message("GameClear","See You Next Time!")
  177.     else:
  178.         pygame.mixer.music.stop()
  179.         pygame.mixer.music.load('resource/smb_gameover.wav')
  180.         pygame.mixer.music.play()
  181.         message("GameOver","You Need More Practice")
  182.     if score > high_score:
  183.         high_score = score
  184.     playing = False
  185.     score = 0;cnt = 1;stage=1;ck_clear=0;item=1;
  186.     t.onkeypress(dummy,"space")
  187.     time.sleep(8)
  188.     title_clear()
  189.  
  190. #적설정2/적초기화
  191. def te_clear():
  192.     for x in range(10):
  193.         te[x].reset()
  194.         #te[x] = t.Turtle()
  195.         #te[x].clear()
  196.         te[x].shape("turtle")
  197.         te[x].speed(0)
  198.         te[x].up()
  199.         te[x].goto(0,(x+1)*50)
  200.         te[x].ht()
  201.         if x==0:te[x].color("darkred")
  202.         elif x==1:te[x].color("red")
  203.         elif x==2:te[x].color("yellow")
  204.         elif x==3:te[x].color("lightgreen")
  205.         elif x==4:te[x].color("green")
  206.         elif x==5:te[x].color("skyblue")
  207.         elif x==6:te[x].color("blue")
  208.         elif x==7:te[x].color("darkblue")
  209.         elif x==8:te[x].color("pink")
  210.         elif x==9:te[x].color("purple")
  211.         else: te[x].color("red")
  212.  
  213. #적표시
  214. def monster(cnt):
  215.     for x in range(cnt):
  216.         te[x].st()
  217.  
  218. #라이프/스코어/타임 출력
  219. def info_out(score):
  220.     global cnt,item,ck_item, t_start, t_now
  221.     playtime = t_now - t_start
  222.     info.clear()
  223.     info.up()
  224.     info.goto(0,230)
  225.     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))
  226.  
  227. #타이틀출력
  228. def title_clear():
  229.     global high_score
  230.     te_clear()
  231.     info_out(high_score)
  232.     t.reset()
  233.     t.title("Turtle MAN Ver1.5")
  234.     t.setup(500,500)
  235.     t.bgcolor("orange")
  236.     t.shape("turtle")
  237.     t.speed(0)
  238.     t.up()
  239.     t.color("white")
  240.     message("Turtle MAN","Press Space To Start")
  241.     t.onkeypress(start,"space")
  242.  
  243. #말그대로 더미
  244. def dummy():
  245.     return
  246.  
  247. #캐릭터및키보드설정
  248. title_clear()
  249. t.onkeypress(turn_right,"Right")
  250. t.onkeypress(turn_up,"Up")
  251. t.onkeypress(turn_left,"Left")
  252. t.onkeypress(turn_down,"Down")
  253. t.onkeypress(start,"space")
  254. t.listen()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×