2

Once again i'm working on a school project and I'm having a hard time with something i feel should be pretty easy..

I have the code working; its not crashing but its also not blitting. I have created a first person shooter style game using Sprites as "Zombie targets" I have the update in the Zombie Class to move the images but I know i have multiple problems.
As always i'm just asking for some direction.

Thanks so much!

import pygame, random, glob

pygame.init()
screen = pygame.display.set_mode((640, 480))

class Circle(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((50, 50))
        self.image.fill((255, 255, 255))
        self.image.set_colorkey(255)
        pygame.draw.circle(self.image, (255, 0, 0), (25, 25), 25, 1)
        self.image.set_alpha(75)
        pygame.draw.circle(self.image, (255,0, 0), (25,25), 3, 0)
        self.rect = self.image.get_rect()
            
    def update(self):
        self.rect.center = pygame.mouse.get_pos()
    
class Zombie(pygame.sprite.Sprite):

    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((50,50))
        self.image.fill((255,255,255))
        self.rect = self.image.get_rect()
        pos = pygame.mouse.get_pos()
        self.x = random.randrange(0,screen.get_width())
        self.y = random.randrange(0, screen.get_height())
        self.ani_speed_init = 8
        self.ani_speed = self.ani_speed_init
        self.ani = glob.glob("zombie_walk_r*.png")
        self.ani.sort()
        self.ani_pos = 0
        self.ani_max = len(self.ani) - 1
        self.img = pygame.image.load(self.ani[1])
    
    def update(self, pos):
        screen.blit(self.img, (self.x, self.y))               
    
    def shoot(killShotSpot):
        killshotbullet = pygame.mixer.Sound("bullet.wav")  
        killshotbullet.play()
        print "record point" + str(killShotSpot)                
    
def main():
    pygame.display.set_caption("Zombie Be GONE")

    background = pygame.Surface(screen.get_size())
    background.fill((255, 255, 255))
    screen.blit(background, (0, 0))
    circle = Circle()
    zombie = Zombie()
    allSprites = pygame.sprite.Group(circle, zombie)
    
    #hide mouse
    pygame.mouse.set_visible(False)
    clock = pygame.time.Clock()
    keepGoing = True

    while keepGoing:
        clock.tick(30)
        for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keepGoing = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            killShotSpot = pygame.mouse.get_pos()
            shoot(killShotSpot)
            pygame.draw.circle(background,(255,0,0),killShotSpot,3,0)
                
    allSprites.clear(screen, background)
    allSprites.update()
    allSprites.draw(screen)
    pygame.display.flip()

    pygame.display.flip()
    
#return mouse
pygame.mouse.set_visible(True)

if __name__ == "__main__":
    main()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
drummerboy
  • 85
  • 6
  • 2
    Did you forget to indent the execution loop in the question code? It looks like it should be a part of your `main()` function. Also, I'd remove the giant blocks of white space... they don't seem to add anything and require more scrolling. –  Mar 30 '14 at 07:42
  • I was waiting for someone to say something about that possibly. The indentions are fine in my original program. when I attempted to post it on here for review, the forum wasn't putting all the lines of code in the scroll box. I manually indented the lines to get the scroll box to accept them – drummerboy Mar 30 '14 at 16:35
  • 1
    Correct me if I'm wrong but from what I can see in the zombie update method you are just blitting background. Aren't you suppose to draw it's actual image as well? – Alex Koukoulas Mar 30 '14 at 17:38
  • You know what your right! self.img is what I needed to blit. – drummerboy Mar 30 '14 at 19:13
  • ok I redid the code.. works but now I'm needing to understand the update to redraw after a successful collision with the rect and the mouse click to score "a hit" – drummerboy Mar 30 '14 at 21:09

0 Answers0