我试图制作一个有点像太空入侵者的小游戏,我很难让我的角色射击子弹。我的角色通过持有"空间"但是他只能射出一颗子弹,子弹会跟随我的角色的上下移动。我怎么能拍出一个独立于我角色运动的子弹?
这是制作子弹的代码:
public function editUser($id)
{
$editUsers = $this->getUserRepository()->find($id);
if($editUsers insteance User) { // here just check
//$editUsers = new User(); // here You don't need create new object of class User, just remove
$editUsers->setId($id);
$this->em->persist($editUsers);
$this->em->flush();
}
else {
// do something if you need
}
}
这是构成游戏剩余部分的代码
if keys[pygame.K_SPACE]:
pygame.draw.rect(WINDOW,COLOUR3,(y+35,z+7,5,2),2)
COLOUR3 =(1,234,254)
if keys[pygame.K_SPACE]:#Allows player character to shoot bullets
x=x+5 # Speed of bullet
pygame.draw.rect(WINDOW,COLOUR3,(y+35+x,z+7,5,2),2)#Bullet shape