469,935 Members | 2,155 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

Why won't the sprites in my group show up? (PyGame)

Hi all,
I am writing a snake game, but all is not going well...

Two problems here. First of all, the little circles I use for my sprite
images only show up as quadrants.
Second of all, only the Head sprite for my snake shows up at all. Why?

Here are the class definitions:

! /usr/bin/python

import pygame as PG

seg_size = 20

class SnakeSegment(PG.sprite.Sprite):
def __init__(self, pos):
PG.sprite.Sprite.__init__(self)
self.image = PG.Surface([seg_size,seg_size])
self.rect = self.image.get_rect()
self.rect.topleft = pos

# self.direction = 0
class SnakeHead(SnakeSegment):

def __init__(self,pos,spd = 10):
PG.sprite.Sprite.__init__(self)
SnakeSegment.__init__(self,pos)
PG.draw.circle(self.image,(255,0,0),self.rect.cent er,4)
self.speed = spd # governs speed of whole snake

def update(self):
self.rect.left += self.speed

class SnakeBody(SnakeSegment):
def __init__(self,pos,prev):
PG.sprite.Sprite.__init__(self)
SnakeSegment.__init__(self,pos)
PG.draw.circle(self.image,(0,255,0),self.rect.cent er,4)

self.previous=prev
def update(self):
self.rect.center = self.previous.rect.center

class SnakeTail(SnakeSegment):
def __init__(self,pos,prev):
PG.sprite.Sprite.__init__(self)
SnakeSegment.__init__(self,pos)
PG.draw.circle(self.image,(0,0,255),self.rect.cent er,4)

self.previous=prev

def update(self):
self.rect.center = self.previous.rect.center

class Snake(PG.sprite.OrderedUpdates):

def __init__(self, pos, length = 6):
PG.sprite.OrderedUpdates.__init__(self)
self.head = SnakeHead(pos)
self.segs = length - 2
self.position = pos
self.add(self.head)

prev = self.head

posx, posy = pos

for x in range(self.segs):
posx += seg_size
prev = (SnakeBody((posx,posy),prev))
self.add(prev)
# print prev.rect.center
posx += seg_size
self.add(SnakeTail((posx, posy),prev))
self._spritelist.reverse() # we need tail first, head last

Whew!
And here is my little test program.

#!/usr/bin/python

from snake import *
#import pygame as PG
DBUF = PG.DOUBLEBUF
FSCR = PG.FULLSCREEN
screenx = 640
screeny = 480

def main():
PG.init()

screen = PG.display.set_mode((screenx, screeny)) #python likes to make
pointers.

q = Snake((100,100))
q.draw(screen)
q.update()
PG.display.flip()
while 1:
PG.event.pump()
keyinput = PG.key.get_pressed()
if keyinput[PG.K_ESCAPE] or PG.event.peek(PG.QUIT):
break

if __name__ == '__main__':
main()

Whoop, there it is. What have I done wrong?

Mar 18 '06 #1
1 1410
Isis wrote:
Hi all,
I am writing a snake game, but all is not going well...


Chances are good that you'll get access to many more potential
respondents by posting the question to the Pygame mailing list.
Mar 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Marian Aldenhövel | last post: by
3 posts views Thread by Tim Knauf | last post: by
reply views Thread by Lunpa | last post: by
1 post views Thread by liuliuliu | last post: by
11 posts views Thread by dynamo | last post: by
3 posts views Thread by globalrev | last post: by
11 posts views Thread by globalrev | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.