如何解决如何子弹限制火力以及如何
from tkinter import *
from time import sleep
import random
class Ball:
def __init__(self,canvas,color,size,x,y,xspeed,yspeed):
self.canvas = canvas
self.color = color
self.size = size
self.x = x
self.y = y
self.xspeed = xspeed
self.yspeed = yspeed
self.id=canvas.create_oval(x,x+size,y+size,fill=color)
def move(self):
self.canvas.move(self.id,self.xspeed,self.yspeed)
(x1,y1,x2,y2)=self.canvas.coords(self.id)
(self.x,self.y)=(x1,y1)
if x1<=0 or x2>=WIDTH:
self.xspeed=-self.xspeed
if y1<=0 or y2>=HEIGHT:
self.yspeed=-self.yspeed
WIDTH=800
HEIGHT=400
bullets=[]
def fire(event):
bullets.append(Ball(canvas,10,"red",100,200,0))
## global bullet_count
## bullet_count=0
window = Tk()
canvas = Canvas(window,width=WIDTH,height=HEIGHT)
canvas.pack()
canvas.bind("<Button-1>",fire)
spaceship = Ball(canvas,"green",0)
enemy = Ball(canvas,500,5)
while True:
for bullet in bullets:
bullet.move()
if (bullet.x+bullet.size) >= WIDTH:
canvas.delete(bullet.id)
bullets.remove(bullet)
if (bullet_count<9):
bullet_count+=1
else:
id=canvas.create_text(100,50,fill="red",font="Times 30 italic
bold",text="Hello World")
break
enemy.move()
window.update()
sleep(0.03)
我只想发射 10 发子弹,如果没有剩余子弹,我想创建一个像 id = canvas.create_text(100,font="Times 30 italic bold",text="Hello World")
这样的消息框。请帮我。我不擅长python
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。