我正在编写一个简单的pygame程序,它只包含在屏幕上移动一个框.盒子移动得非常快,我想知道如何控制速度.在我的代码中,更新的位置移动1而不是更小,因为如果数字不是整数,则会使事情变得更复杂.
import os, sys
import pygame
from pygame.locals import *
pygame.init()
mainClock = pygame.time.Clock()
WINDOWWIDTH = 400
WINDOWHEIGHT = 400
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption("Box")
BLACK = (0, 0, 0)
RED = (255, 0, 0)
WHITE = (255, 255, 255)
size1 = 20
size2 = 2
#character = pygame.Rect(30, 30, 20, 30)
player = pygame.Surface((40,40))
pos1 = 100
pos2 = 100
MOVESPEED = 6
x = 1
while True:
if pos1 == WINDOWWIDTH - 40 and pos1 > …Run Code Online (Sandbox Code Playgroud) 我正在开发一种游戏(导弹命令克隆),我需要检查一个surface(建筑物)是否与point(导弹)发生碰撞.

如何检查导弹是否撞击建筑物?
A Rect有这个collidepoint方法,但我希望它是像素完美的.
=>使用a Rect=>
=>但它应该是像素完美=> 
我很新,我无法正常工作.
我有这个字符串
[ "字符串1", "字符串2", "STRING3", "串,4", "STRING5", "string6", "string7", "string8", "string9", "string10"]
我希望得到"之间的所有价值"
我认为正则表达式最适合完成任务.
谢谢你的帮助.
我有以下代码可以在循环中创建一系列绑定:
from Tkinter import *
keys = {0:'m', 1:'n', 2:'o'}
def SomeFunc(event=None,number=11):
print keys[number], number
root = Tk()
field = Canvas(root, height = 200, width = 200, bg = "gray")
for i in range(2):
root.bind("<KeyPress-%c>" % keys[i],lambda ev:SomeFunc(ev,i))
field.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我按'm'或'n'时,函数SomeFunc以可变的'i'作为参数被调用。我希望在按“ m”时以0作为参数(使用“ bind”时使用数字“ i”),在按“ n”时以1作为参数来调用它。能做到吗?
if (File.Exists(file.csv))
{
return file.csv;
}
else if (File.Exists(file.dbf))
{
return file.dbf;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用一行简化此表达式吗?
我正在寻找一种方法来改变.NET exe中引用的DLL.
为什么?我有一个CrackMe,为了破解它,我不允许使用Reflector进行修改(太简单了 - 但我可以阅读它的来源).我也必须这样做.(这就是这个裂缝的挑战)
问题是源被控制流混淆了,我不允许使用任何自动工具来解决它,因此手动操作将是漫长而痛苦的.
crackme使用一个嵌入其自身的开源库来工作,所以我可以下载库的源代码,用一些"转储"代码修改它(因为CrackMe使用它的API并且还提供了该API的序列,我会修改转储),把它放回到crackme中,运行它并在我的桌面上获取密钥.
它应该(但不是强制性的)与ILDASM一起完成.
所以,问题是:有没有办法用我自己的"更新"引用的DLL?
当逐个删除文件时,会生成错误,因为"进程无法访问文件",因为在尝试删除文件时,其他进程正在使用该文件
代码:有关删除文件的任何建议吗?
private void DeleteFilesFromDestination()
{
string consolidatedFolder = System.Configuration.ConfigurationManager.AppSettings["path"].ToString();
foreach (String file in ListBoxDeleteFiles.Items)
{
try
{
// delete each selected files from the specified TargetFolder
if (System.IO.File.Exists(consolidatedFolder + @"\" + System.IO.Path.GetFileName(file)))
{
proc.WaitForExit();
System.IO.File.Delete(consolidatedFolder + @"\" + System.IO.Path.GetFileName(file));
}
}
catch (Exception ex)
{
MessageBox.Show("Error Could not Delete file from disk " + ex.Message, "Shipment Instruction",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
Run Code Online (Sandbox Code Playgroud)
注意:图像将被加载到这样的flowlayout面板
//Open the files to see
private void ListBoxSourceFiles_Click(object sender, EventArgs e)
{
try
{
if …Run Code Online (Sandbox Code Playgroud) 如果我有一个列表如下:
["apples" "pears" "oranges"]
Run Code Online (Sandbox Code Playgroud)
从这里获取随机物品的最简单方法是什么?
我在 pygame 中使用数字键盘,但数字键盘无法被识别。
我知道我必须使用下面的代码,但不知道如何使用:
if (event.key >= 0x100 and event.key <= 0x109)
Run Code Online (Sandbox Code Playgroud)
这是我使用return密钥的代码:
if event.type == KEYDOWN and event.key != 300:
if (event.key >= 0x100 and event.key <= 0x109 and event.key == pygame.K_RETURN):
....
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
对于学校项目,我需要通过实现向鼠标位置射击 Kunais/Shurikens 的方法来完成下面的 pygame 程序,以便能够击中敌人的精灵。
import pygame
import math
import random
from pygame.locals import *
pygame.init()
fenetre = pygame.display.set_mode((640,480), RESIZABLE)
pause = False
class perso():
def __init__(self,image,x=0,y=0,directionX=1,directionY=1):
self.image = pygame.image.load(image).convert_alpha()
self.x = x
self.y = y
self.directionX = directionX
self.directionY = directionY
def move(self):
if self.x==0:
self.directionX=1
if self.x==640-60:
self.directionX=-1
if self.y==0:
self.directionY=1
if self.y==480-100:
self.directionY=-1
self.x+=self.directionX
self.y+=self.directionY
fond = pygame.image.load("background.png").convert_alpha()
naruto = perso("naruto.png")
tobi = perso("tobi.png", 250, 100)
kunai = perso("kunai.png")
kunai.x = naruto.x + 40
kunai.y = naruto.y …Run Code Online (Sandbox Code Playgroud)