自己编的Python游戏
举报
发布于:2022-12-25
更新于:2022-12-25
2
625
作品介绍:
以下是完整代码(Python3.10.0版编的)(为啥社区不能发Python作品): (字数太多,有些放说明里了) import turtle as t import random as r #function def start_****(): global ****_start global ****_score global bullet_is_fling text.clear() if ****_start: return ****_start=True ****_score=0 while True: if bullet_is_fling==False: bullet.setheading(player.heading()) kill_enemy() (x,y)=enemy.pos() if y<-299: ****_over() break def ready_bullet(): bullet.hideturtle() bullet.goto(0,-300) bullet.showturtle() def bullet_fly(): if a_bullet: leftw=-t.window_width()/2 rightw=t.window_width()/2 topw=t.window_height()/2 bullet_is_fling=True t.clear() while True: bullet.forward(10) (x2,y2)=bullet.pos() out=x2<leftw or x2>rightw or y2>topw t.clear() if out: ready_bullet() bullet_is_fling=False break else: t.write('No bullet',align='center',font=('Arial',16,'bold')) def ready_enemy(): enemy.hideturtle() enemy.goto(r.randrange(-300,300),300) enemy.showturtle() def ****_over(): text.clear() text.write('GAME OVER!',align='center',font=('Arial',16,'bold')) def left(): player.left(15) def right(): player.right(15) def enemy_go(): enemy.setheading(270) enemy.forward(50) def kill_enemy(): if bullet.distance(enemy)᝺: bulle_is_fling=False ready_enemy() ready_bullet() ****_score=****_score+10 score.write(****_score,align='center',font=('Arial',16,'bold')) #ready t.bgcolor('dark blue') ****_start=False bullet_is_fling=False a_bullet=True ****_score=0 score=t.Turtle() player=t.Turtle() text=t.Turtle() bullet=t.Turtle() enemy=t.Turtle() enemy.shape('circle') score.hideturtle() score.penup() score.goto(300,279) enemy.color('red') enemy.penup() enemy.goto(0,300)
操作说明:
(续) player.penup() player.color('yellow') player.goto(0,-300) text.write('please press spase to start(don\'t full screen)',align='center',font=('Arial',16,'bold')) text.hideturtle() bullet.penup() bullet.goto(0,-300) bullet.color('yellow') #MindPlus t.ontimer(enemy_go,t=2000) t.onkey(start_****,'space') t.onkey(left,'Left') t.onkey(right,'Right') t.onkey(bullet_fly,'Down') t.listen() t.mainloop() 空格启动,左右方向键分别左右转,↓键发射 (不知道缩进位置的小伙伴看图,缩进=4个空格\1次tab键)