我正在尝试使用tkinter在python中制作类似于Block Dodger的游戏。 我想要做的是从矩形接触另一个矩形时进行输出。我找到了类似于我的问题的答案,但它没有解释该怎么做以及如何使用该命令。这是我的代码:
from tkinter import *
def change_coord(event):
if event.keysym == 'Right':
canvas.move(a, 20,0)
if event.keysym == 'Left':
canvas.move(a, -20,0)
def tet1():
canvas.move(b, 0, 30)
root.after(250, tet1)
def tet2():
canvas.move(c, 0, 20)
root.after(250, tet2)
def tet3():
canvas.move(d, 0, 50)
root.after(250, tet3)
root = Tk()
canvas = Canvas(root, width=1000, height=5000, bg='white')
canvas.pack(pady=0)
a = canvas.create_rectangle(0, 0, 100, 100, fill='red')
b = canvas.create_rectangle(0, 0, 100, 100, fill='blue')
c = canvas.create_rectangle(0, 0, 100, 100, fill='blue')
d = canvas.create_rectangle(0, 0, 100, 100, fill='blue')
canvas.move(a, 450, 850)
canvas.move(c, 450, 0)
canvas.move(d, 675, 0)
canvas.bind("<Motion>", change_coord)
root.bind_all('<Left>', change_coord)
root.bind_all('<Right>', change_coord)
tet1()
root.after(200, tet2)
root.after(2000, tet3)
root.mainloop()
我不知道如何做到这一点,所以我很感激一些帮助。谢谢 :) -Jake
答案 0 :(得分:1)
要检查const async = require('async');
var list = ['Ann', 'Bob', 'John', 'Karl'];
var counting = function (item, doneCallback) {
var query = Clients.count({name: item});
query.then(function (doc) {
return doneCallback(null, doc);
});
};
async.map(list, counting, function(err, data) {
console.log(data);
});
是否与任何对象重叠,您可以获得a
坐标并与a
一起使用。它为您提供了重叠find_overlapping()
a
您可以使用def check_collision():
x1, y1, x2, y2 = canvas.coords(a)
result = canvas.find_overlapping(x1, y1, x2, y2)
if b in result:
print('b overlaps a')
if c in result:
print('c overlaps a')
if d in result:
print('d overlaps a')
root.after(250, check_collision)
或者您可以分别对每个对象使用after()
- 然后您可以停止对象并从画布中删除。
find_overlapping