import random
import time
BLACK = (0,0,0)
t = 145, 138
a = 75, 258
b = 275, 258
e = 165, 378
g = 95, 498
s = 295, 498
f = 395, 378
h = 535, 498
c = 495, 258
j = 745, 258
i = 795, 498
d = 695, 378
nodes = [t, a, b, e, g, s, f, h, c, j, i, d]
def spawn():
global trap
rspawn = random.randint(0,3)
tspawn = random.randint(0,3)
trap = random.choice(nodes)
global treasure
if tspawn == 0:
treasure = 't'
elif tspawn == 1:
treasure = 'a'
elif tspawn == 2:
treasure = 'e'
elif tspawn ==3:
treasure = 'g'
global rstart
if rspawn == 0:
rstart = 'c'
elif rspawn == 1:
rstart = 'j'
elif rspawn == 2:
rstart = 'd'
elif rspawn ==3:
rstart = 'i'
if rspawn == 'c':
trap != 'c'
elif rspawn == 'j':
trap != 'j'
elif rspawn == 'i':
trap != 'i'
elif rspawn == 'd':
trap != 'd'
spawn()
是的,所以这就是我到目前为止所做的,我要做的就是在陷阱的同一个地方产生一个正方形并且陷阱随机产生,为了产生陷阱,我有陷阱= random.choice(节点)以上,你可以看到节点。我尝试使用pygame.draw.rect这样做,因为我们在pygame中工作,但我不知道如何插入坐标,以便每当它产生随机坐标时都在pygame.draw.rect中。
答案 0 :(得分:0)
如果唯一的问题是如何使用PyGames draw.rect()
函数,那就像它那样简单:
pygame.draw.rect(屏幕,颜色,(x,y,宽度,高度),线宽)在表面上绘制一个矩形。
x
和y
是左上角的坐标width
和height
是矩形的宽度和高度linewidth
是该行的粗细及其可选的如果您想在屏幕上的(50, 50)
坐标处绘制一个矩形,其大小为10 x 10
像素,请致电
pygame.draw.rect(screen, (55, 155, 255), (50, 50, 10, 10))