[Tutor] Help with a game

j j jeffq16 at yahoo.com
Thu Nov 13 14:09:43 EST 2003


Whenever i run the game it says:
 script 'A:\game folder\game.py' returned exit code 0
 
If you want the bitmaps then let me know, i didn't want to send everyone an attachment, thanks again guys.
 
Maybe some help?  Thank you guys...here is the code.                  --Jeff
                                                                  
 
 

import os, pygame
from pygame.locals import *
if not pygame.font:print 'Warning, fonts disabled'
 
def load_image(name, colorkey=None):
        fullname = os.path.join('data', name)
        try:
            image = pygame.image.load(fullname)
        except pygame.error, message:
            print 'Cannot load image:', fullname
            raise SystemExit, message
        image = image.convert()
        if colorkey is not None:
            if colorkey is -1:
                colorkey = image.get_at((0,0))
            image.set_colorkey(colorkey, RLEACCEL)
        return image, image.get_rect()

class Gun(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = load_image('gun.bmp', -1)
        self.punching = 0
    def update(self):
        pos = pygame.mouse.get_pos()
        self.rect.midtop = pos
        if self.punching:
            self.rect.move_ip(5, 10)
    def shoot(self, target):
        if not self.punching:
            self.punching = 1
            hitbox = self.rect.inflate(-5,-5)
            return hitbox.colliderect(target.rect)
    def unshoot(self):
        self.punching = 0
        
class ship(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = load_image('new.bmp',-1)
        screen = pygame.display.get_suface()
        self.area = screen.get_rect()
        self.rect.topleft = 10, 10
        self.move = 9
        self.dizzy = 0
    def update(self):
        if self.dizzy:
            self._spin()
        else:
            self._walk()
    def _walk(self):
        change = self.rect.move((self.move, 0))
        if self.rect.left< self.area.left or \
           self.rect.right > self.area.right:
            self.move = -self.move
            change = self.rect.move((self.move, 0))
            self.image = pygame.transform.flip(self.image, 1, 0)
        self.rect = change            
    def _change(self):
        center = self.rect.center
        self.dizzy = self.dizzy + 12
        if self.dizzy >= 360:
            self.dizzy = 0
            self.image = self.original
        else:
            rotate = pygame.transform.rotate
            self.image = rotate(self.original, slef.dizzy)
        self.rect = self.image.get_rect()
        self.rect.center = center
        def done(self):
                if not self.dizzy:
                        self.dizzy = 1
                        self.original = self.image
                        
                def main():
                        pygame.init()
                        screen = pygame.display.set_mode((480, 60))
                        pygame.display.set_caption('Battleship')
                        pygame.mouse.set_visible(0)
                        backround = pygame.Surface(screen.get_size())
                        backround = backround.convert()
                        backround.fill((250, 250, 250))

        screen.blit(backround, (0, 0))
        pygame.display.flip()
        clock = pygame.time.Clock()
        new = New()
        gun = Gun()
        allsprites = pygame.sprite.RenderPlain((gun, new))
        while 1:
            clock.tick(60)
            for  event in pygame.event.get():
                if event.type == QUIT:
                    return
                elif event.type == KEYDOWN and event.key == K_ESCAPE:
                    return
                elif event.type == MOUSEBUTTONDOWN:
                    if fist.punch(chimp):
                        chimp.punched()
                elif event.type == MOUSEBUTTONUP:
                    fist.unpunch()
                allsprites.update()
                screen.blit(backround, (0, 0))
                allsprites.draw(screen)
                pygame.display.flip()
                if __name__ == '__main__':
                        main()


---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20031113/f5c052c5/attachment.html


More information about the Tutor mailing list