python海龟代码大全鹦鹉螺,python海龟作图简单代码

这篇文章主要介绍了海龟程序如何在python中打开,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获,下面让小编带着大家一起了解一下。

所以我有一个项目,我必须创建一个海龟图形游戏,而不使用任何其他模块,除了海龟和随机模块。我正在创造传统的蛇游戏,除了当蛇“吃”的对象,它不会变大python怎么画拱形。我的游戏的问题是,当“蛇”到达目标时,对象并没有消失,我希望它消失并重新出现在另一个位置。请帮忙。代码如下:from turtle import *

import random

setup(700, 700)

title("Snake Game!")

bgcolor("blue")

# Boundary

bPen = Pen()

bPen.color("Orange")

bPen.up()

bPen.goto(-300, -300)

bPen.down()

for i in range(4):

bPen.ht()

bPen.fd(600)

bPen.lt(90)

# Player

playerPen = Pen()

playerPen.color("Orange")

playerPen.up()

playerPen.width(4)

# Create Circle

circle = Pen()

circle.shape("circle")

circle.color("Red")

circle.up()

circle.speed(0)

circle.goto(-100, 100)

# Speed

speed = 2

# Movement functions

def left():

playerPen.lt(90)

def right():

playerPen.rt(90)

def speedBoost():

global speed

speed += 1

# Key Prompts

onkey(left, "Left")

onkey(right, "Right")

onkey(speedBoost, "Up")

listen()

# Infinity loop and player knockback

while True:

playerPen.fd(speed)

if playerPen.xcor() < -300 or playerPen.xcor() > 300:

playerPen.rt(180)

elif playerPen.ycor() < - 300 or playerPen.ycor() > 300:

playerPen.rt(180)

# Collision with circle

if playerPen.xcor() == circle.xcor() and playerPen.ycor() == circle.ycor():

circle.goto(random.randint(-300, 300), random.randint(-300, 300))

done()

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值