pygame的新手只想知道如何在游戏中添加背景图片?这是我的代码到目前为止,我一直使用bg作为导入我的图像的方法,但py文件本身拒绝加载.
import pygame
import sys
from pygame.locals import *
clock = pygame.time.Clock()
screen = pygame.display.set_mode((600,500))
bg = pygame.image.load("images\space.png")
pygame.mouse.set_visible(0)
ship = pygame.image.load("images\ship.png")
ship_top = screen.get_height() - ship.get_height()
ship_left = screen.get_width()/2 - ship.get_width()/2
screen.blit(ship, (ship_left,ship_top))
shot = pygame.image.load("images\shot.png")
shoot_y = 0
pygame.display.set_caption('galaxy invaders')
while True:
clock.tick(60)
screen.fill((r,0,0))
screen.blit(bg.(0,0))
x,y = pygame.mouse.get_pos()
screen.blit(ship, (x-ship.get_width()/2, ship_top))
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == MOUSEBUTTONDOWN:
shoot_y = 500
shoot_x = x
if shoot_y > 0:
screen.blit(shot, (shoot_x, shoot_y))
shoot_y …Run Code Online (Sandbox Code Playgroud) 我在键盘上输入pip install discord.如果我再次尝试,我做了,它会像图像中那样响应.但是python说它没有安装.
pycharm说async def <name>():没关系,以前从未发生过没有正确导入discord(它会检查).PyCharm也通常告诉我什么时候没有安装模块.这种情况昨天没有发生,但现在突然发生了.
任何帮助都会非常受欢迎,因为这个机器人运行的服务器在它离线时讨厌它.
在尝试@javajavs的回答后,它仍在做同样的事情.只是这次说的不和谐和discord.py 被安装,即使它引发ImportError.
我将在此处包含源代码以供参考:
import discord
import random
import Utilities as util
import sys
client = discord.Client()
logs = []
#global giveaway
#giveaway = util.giveaway.Giveaway()
cats = ["https://media.giphy.com/media/l3q2SKnzUMdELQkpi/giphy.gif", "https://media.giphy.com/media/TA6Fq1irTioFO/giphy.gif", "https://media.giphy.com/media/ORBjACSOzSYq4/giphy.gif", "https://giphy.com/gifs/cat-2QHLYZFJgjsFq?utm_source=media-link&utm_medium=landing&utm_campaign=Media%20Links&utm_term="]
@client.event
async def on_message(message):
global logs#, giveaway
message.content = str(message.content)
if message.content.startswith("-pet"):
await client.send_message(message.channel, "{0}, {1} is petting you! \n {2}".format("Catto", str("<@"+message.author.id+">"), random.choice(cats)))
if …Run Code Online (Sandbox Code Playgroud) 我一直在改进和改进我的机器人。现在,我已经弄清楚了如何使漫游器清除消息,但是,不应将清除消息允许给任何成员,而只能允许具有特定角色的人员使用。
我已经完成了以下代码:
if author.roles.has("BotModerator"):
Run Code Online (Sandbox Code Playgroud)
我在此网站(https://anidiotsguide.gitbooks.io/discord-js-bot-guide/information/understanding_roles.html)上进行了查找,但似乎它们使用Java进行编码,我该怎么办用Python吗?
顺便说一句,输出中显示的错误是'list'对象没有属性'has'
如果我有一个字符串,让刚刚说了,b a hello b Hi怎么可能我分裂的所有字符串b小号后的字母第一次出现a?
如上,它将返回["b a hello", "Hi"]。