help.
j j <[email protected]> Fri, 7 Nov 2003 11:36:59 -0800 (PST)
| Newsgroups | gmane.comp.python.meta |
|---|---|
| Message-ID | <[email protected]> |
--===============0883199024==
Content-Type: multipart/alternative; boundary="0-844066779-1068233819=:62650"
--0-844066779-1068233819=:62650
Content-Type: text/plain; charset=us-ascii
Hello, maybe you can help me. I'm in a programming class and i need some help. I've created a game based off of pythons example of "Chimp" and i need some help. It never works for me, i've enclosed the code.
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()
Thanks again, Bye. Jeff "_Q_uart_z" Q.
---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
--0-844066779-1068233819=:62650
Content-Type: text/html; charset=us-ascii
<DIV>
<DIV>Hello, maybe you can help me. I'm in a programming class and i need some help. I've created a game based off of pythons example of "Chimp" and i need some help. It never works for me, i've enclosed the code.</DIV>
<DIV> </DIV>
<DIV>import os, pygame<BR>from pygame.locals import *</DIV>
<DIV>if not pygame.font:print 'Warning, fonts disabled'</DIV>
<DIV> </DIV>
<DIV>def load_image(name, colorkey=None):<BR> fullname = os.path.join('data', name)<BR> try:<BR> image = pygame.image.load(fullname)<BR> except pygame.error, message:<BR> print 'Cannot load image:', fullname<BR> raise SystemExit, message<BR> image = image.convert()<BR> if colorkey is not None:<BR> if colorkey is -1:<BR> colorkey = image.get_at((0,0))<BR>
image.set_colorkey(colorkey, RLEACCEL)<BR> return image, image.get_rect()</DIV>
<DIV><BR>class Gun(pygame.sprite.Sprite):<BR> def __init__(self):<BR> pygame.sprite.Sprite.__init__(self)<BR> self.image, self.rect = load_image('gun.bmp', -1)<BR> self.punching = 0</DIV>
<DIV> def update(self):<BR> pos = pygame.mouse.get_pos()<BR> self.rect.midtop = pos<BR> if self.punching:<BR> self.rect.move_ip(5, 10)</DIV>
<DIV> def shoot(self, target):<BR> if not self.punching:<BR> self.punching = 1<BR> hitbox = self.rect.inflate(-5,-5)<BR> return hitbox.colliderect(target.rect)</DIV>
<DIV> def unshoot(self):<BR> self.punching = 0</DIV>
<DIV> <BR>class ship(pygame.sprite.Sprite):<BR> def __init__(self):<BR> pygame.sprite.Sprite.__init__(self)<BR> self.image, self.rect = load_image('new.bmp',-1)<BR> screen = pygame.display.get_suface()<BR> self.area = screen.get_rect()<BR> self.rect.topleft = 10, 10<BR> self.move = 9<BR> self.dizzy = 0</DIV>
<DIV> def update(self):<BR> if self.dizzy:<BR> self._spin()<BR> else:<BR> self._walk()</DIV>
<DIV> def _walk(self):<BR> change = self.rect.move((self.move, 0))<BR> if self.rect.left< self.area.left or \<BR> self.rect.right > self.area.right:<BR> self.move = -self.move<BR> change = self.rect.move((self.move, 0))<BR> self.image = pygame.transform.flip(self.image, 1, 0)<BR> self.rect = change </DIV>
<DIV> def _change(self):<BR> center = self.rect.center<BR> self.dizzy = self.dizzy + 12<BR> if self.dizzy >= 360:<BR> self.dizzy = 0<BR> self.image = self.original<BR> else:<BR> rotate = pygame.transform.rotate<BR> self.image = rotate(self.original, slef.dizzy)<BR> self.rect = self.image.get_rect()<BR> self.rect.center = center</DIV>
<DIV> def done(self):<BR> if not self.dizzy:<BR> self.dizzy = 1<BR> self.original = self.image</DIV>
<DIV> def main():<BR> pygame.init()<BR> screen = pygame.display.set_mode((480, 60))<BR> pygame.display.set_caption('Battleship')<BR> pygame.mouse.set_visible(0)</DIV>
<DIV> backround = pygame.Surface(screen.get_size())<BR> backround = backround.convert()<BR> backround.fill((250, 250, 250))</DIV>
<DIV><BR> screen.blit(backround, (0, 0))<BR> pygame.display.flip()</DIV>
<DIV> clock = pygame.time.Clock()<BR> new = New()<BR> gun = Gun()<BR> allsprites = pygame.sprite.RenderPlain((gun, new))</DIV>
<DIV> while 1:<BR> clock.tick(60)</DIV>
<DIV> for event in pygame.event.get():<BR> if event.type == QUIT:<BR> return<BR> elif event.type == KEYDOWN and event.key == K_ESCAPE:<BR> return<BR> elif event.type == MOUSEBUTTONDOWN:<BR> if
fist.punch(chimp):<BR> chimp.punched()<BR> elif event.type == MOUSEBUTTONUP:<BR> fist.unpunch()</DIV>
<DIV> allsprites.update()</DIV>
<DIV> screen.blit(backround, (0, 0))<BR> allsprites.draw(screen)<BR> pygame.display.flip()</DIV>
<DIV> </DIV>
<DIV> <BR> <BR> <BR>Thanks again, Bye. Jeff "_Q_uart_z" Q.</DIV>
<DIV> </DIV></DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
<a href="http://antispam.yahoo.com/whatsnewfree">Protect your identity with Yahoo! Mail AddressGuard</a>
--0-844066779-1068233819=:62650--
--===============0883199024==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Meta-sig maillist - [email protected]
http://mail.python.org/mailman/listinfo/meta-sig
--===============0883199024==--