|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
附上部分代码(基本上都是按小甲鱼来的):
bullets.py
------
import pygame
class Bullet1(pygame.sprite.Sprite):
def __init__(self,position):
pygame.sprite.Sprite.__init__(self)
self.img = pygame.image.load('images/bullet1.png').convert_alpha()
self.rect = self.img.get_rect()
self.rect.left, self.rect.top = position
self.speed = 12
self.active = True
self.mask = pygame.mask.from_surface(self.img)
def move(self):
self.rect.top = -self.speed
if self.rect.top < 0:
self.active = False
def reset4(self,position):
self.rect.left, self.rect.top = position
self.active = True
------
main.py
------
...
# Bullet
bullet1=[]
bullet1_num = 4
bullet1_index = 0
for each in range(bullet1_num):
bullet1.append(bullets.Bullet1(me.rect.midtop))
...
while 1:
...
if not (delay % 4):
bullet1[bullet1_index].reset4(me.rect.midtop)
bullet1_index = (bullet1_index + 1) % bullet1_num
for b in bullet1:
if b.active:
b.move()
screen.blit(b.img,b.rect)
enemy_hit = pygame.sprite.spritecollide(b,total_enemy,False,pygame.sprite.collide_mask)
if enemy_hit:
b.active = False
for e in enemy_hit:
e.destory = True
...
------
能跑起来就是没子弹,看了一下午。。求大神指点,会有libpng warning: iCCP: known incorrect sRGB profile,但网上看说没什么关系 |
|