我(有条件地)有一个变量text = "Hello"
。
我需要这样做print("text World")
:
我知道这样做是正确的print(text, " World")
:但是我的函数有一个参数。
如何将变量推入字符串?
我(有条件地)有一个变量text = "Hello"
。
我需要这样做print("text World")
:
我知道这样做是正确的print(text, " World")
:但是我的函数有一个参数。
如何将变量推入字符串?
打开菜单时,脚本应该运行,但它没有运行。
hook.Add('c_menu','OpenMenu', function(ply)
if SANDBOX:ContextMenuOpened() == true then
CmdDerma()
print('Context menu is open')
end
end)
为什么管道在接触窗口的开头时不会移动到末端?
import pygame
pygame.init()
sc = pygame.display.set_mode((700,800))
pygame.display.set_caption("Flappy Bird")
FPS = 30
clock = pygame.time.Clock()
x = 350
y = 400
xOfDuct = 732
yOfDuct = 800
flag = 0
def duct():
ductOne_surf = pygame.image.load('trubaDown.png')
ductOne_surf = pygame.transform.scale(ductOne_surf, (120,452))
ductOne_rect = ductOne_surf.get_rect(bottomright=(xOfDuct,yOfDuct))
sc.blit(ductOne_surf,ductOne_rect)
def ductTwo():
duct_surf = pygame.image.load('trubaUp.png')
duct_surf = pygame.transform.scale(duct_surf, (120,452))
duct_rect = duct_surf.get_rect(bottomright=(xOfDuct, yOfDuct - yOfDuct + 175))
sc.blit(duct_surf,duct_rect)
while True:
sc.fill((255,255,255))
duct()
ductTwo()
pygame.draw.circle(sc, (255,255,0),(x,y),20)
for i in pygame.event.get():
if i.type == pygame.QUIT:
exit()
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
flag = 0
y-=15
if xOfDuct == 0:
xOfDuct = 700
flag+=2
y+=flag
xOfDuct -= 10
pygame.display.update()
clock.tick(FPS)
我的程序垂直绘制线条并将它们按从低到高的顺序排列。为什么排序是一次发生而不是逐渐发生的?
import pygame
pygame.init()
sc = pygame.display.set_mode((1200,600))
FPS = 1
clock = pygame.time.Clock()
y = [230,240,270,210,300,220]
def draw(xOne,yOne,xTwo,yTwo,Width):
pygame.draw.line(sc,(0,0,255),(xOne,yOne),(xTwo,yTwo), Width)
while True:
sc.fill((255,255,255))
draw(200,400,200,y[0],10)
draw(250,400,250,y[1],10)
draw(300,400,300,y[2],10)
draw(350,400,350,y[3],10)
draw(400,400,400,y[4],10)
draw(450,400,450,y[5],10)
for h in pygame.event.get():
if h.type == pygame.QUIT:
exit()
for i in range(len(y)):
for j in range(len(y) - i - 1):
if y[j] < y[j+1]:
y[j], y[j+1] = y[j+1], y[j]
pygame.display.update()
clock.tick(FPS)
为什么,有了这个代码,船不会改变它的位置
import pygame
pygame.init()
sc = pygame.display.set_mode((1200, 1200))
clock = pygame.time.Clock()
FPS = 60
x = 600
y = 600
K = pygame
def SpaceShip(xShip, yShip):
ship_surf = pygame.image.load('spaceShip.png')
ship_rect = ship_surf.get_rect(bottomright=(xShip - 32, yShip - 32))
ship_surf = pygame.transform.scale(ship_surf, (100,100))
sc.blit(ship_surf, ship_rect)
pygame.display.update()
while True:
sc.fill((0,0,0))
SpaceShip(x, y)
for i in pygame.event.get():
if i.type == pygame.QUIT:
exit()
keys = pygame.key.get_pressed()
if keys == K.K_LEFT:
x -= 3
elif keys == K.K_RIGHT:
x += 3
pygame.display.update()
clock.tick(FPS)
为什么在这段代码中,触摸线时圆圈不会停止?如果有人知道如何在接触地面时停下来,请写信。
import pygame
pygame.init()
FPS = 30
x = 300
y = 200
xL = 200
xL2 = 400
yL = 300
sc = pygame.display.set_mode((600, 400))
clock = pygame.time.Clock()
pygame.display.update()
speedDown = 0
while True:
sc.fill((255,255,255))
clock.tick(FPS)
pygame.draw.circle(sc,(0,0,255),(x,y), 20, 0)
pygame.draw.line(sc,(0,0,0),(xL,yL),(xL2,yL),5)
for i in pygame.event.get():
if i.type == pygame.QUIT:
exit()
keys = pygame.key.get_pressed()
if y == yL:
speedDown = 0
y += 5
else:
speedDown += 1
y += speedDown
pygame.display.update()