473,698 Members | 2,643 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sprit e.__init__(self )
self.image = PG.Surface([seg_size,seg_si ze])
self.rect = self.image.get_ rect()
self.rect.tople ft = pos

# self.direction = 0
class SnakeHead(Snake Segment):

def __init__(self,p os,spd = 10):
PG.sprite.Sprit e.__init__(self )
SnakeSegment.__ init__(self,pos )
PG.draw.circle( self.image,(255 ,0,0),self.rect .center,4)
self.speed = spd # governs speed of whole snake

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

class SnakeBody(Snake Segment):
def __init__(self,p os,prev):
PG.sprite.Sprit e.__init__(self )
SnakeSegment.__ init__(self,pos )
PG.draw.circle( self.image,(0,2 55,0),self.rect .center,4)

self.previous=p rev
def update(self):
self.rect.cente r = self.previous.r ect.center

class SnakeTail(Snake Segment):
def __init__(self,p os,prev):
PG.sprite.Sprit e.__init__(self )
SnakeSegment.__ init__(self,pos )
PG.draw.circle( self.image,(0,0 ,255),self.rect .center,4)

self.previous=p rev

def update(self):
self.rect.cente r = self.previous.r ect.center

class Snake(PG.sprite .OrderedUpdates ):

def __init__(self, pos, length = 6):
PG.sprite.Order edUpdates.__ini t__(self)
self.head = SnakeHead(pos)
self.segs = length - 2
self.position = pos
self.add(self.h ead)

prev = self.head

posx, posy = pos

for x in range(self.segs ):
posx += seg_size
prev = (SnakeBody((pos x,posy),prev))
# print prev.rect.cente r
posx += seg_size
self.add(SnakeT ail((posx, posy),prev))
self._spritelis t.reverse() # we need tail first, head last

And here is my little test program.


from snake import *
#import pygame as PG
screenx = 640
screeny = 480

def main():

screen = PG.display.set_ mode((screenx, screeny)) #python likes to make

q = Snake((100,100) )
PG.display.flip ()
while 1:
keyinput = PG.key.get_pres sed()
if keyinput[PG.K_ESCAPE] or PG.event.peek(P G.QUIT):

if __name__ == '__main__':

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

Mar 18 '06 #1
1 1526
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Marian Aldenhövel | last post by:
Hi, I am trying to make pygame play music on windows. This simple program: import pygame,time pygame.init() print "Mixer settings", pygame.mixer.get_init() print "Mixer channels", pygame.mixer.get_num_channels() pygame.mixer.music.set_volume(1.0) pygame.mixer.music.load('file1.mp3)
by: Tim Knauf | last post by:
Hi everyone, I'm glad to have found this list. I've written a small script for my own use which, amongst other things, captures mouse click information from a window containing an image. I used Pygame to manage the image window, as it was the easiest way to implement the functionality I needed. The surrounding interface windows (there are two) are constructed with Tkinter. Despite their unholy union, Pygame and Tkinter seem, generally,...
by: kjm | last post by:
Hi everyone, I have recently acquired a Logitech Rumble pad to use as an input device. I have been having trouble getting the event que to respond that a button or hat arrow has been pressed. This is on a system running OS 10.3.9. I have modified/written a small piece of code that initializes the joystick, and pygame does recognize it. I was wondering if someone has a small snippet of code to get me going? I have posted the code...
by: Lunpa | last post by:
My project: I'm working on a game, where in the ui, it takes the pygame window, and shoves it into a gtk2 socket widget. (gtk2 widgets are generated with glade, with the exception of the socket widget, which is manualy added into a window) My problem: Since adding the gtk half, it is realy slow. I can make one or the other update realy fast, or I can make it so the pygame window/widget gets a fluctuation in framerate between realy...
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image file during specific events in the script execution? image format doesnt matter. thanks! christine
by: dynamo | last post by:
Hi guys i have come again with more problems.This time it has to do with pygame.The following code does not give any error messages but it does not do what it is supposed to do either.the code is a bit long but it's straightforward.Please help import pygame from pygame.locals import * pygame.init() screen=pygame.display.set_mode((900,900)) class Hero(pygame.sprite.Sprite): def __init__(self): ...
by: globalrev | last post by:
im doing this : http://www.learningpython.com/2006/03/12/creating-a-game-in-python-using-pygame-part-one/ and when closing the program the window stays up and doesnt respond. i tried adding this: http://www.pygame.org/wiki/FrequentlyAskedQuestions bu it doesnt work, or maybe im doing it wrong. heres the code without the added tutorial exit:
by: globalrev | last post by:
http://www.pygame.org/docs/ref/mixer.html import pygame #pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072) //it complained abiout words= so i guess its only the nbrs should be there// pygame.mixer.init(22050, -16, 2, 3072) pygame.mixer.music.load("example1.mp3")
by: defn noob | last post by:
Im using PyGame to draw images of graphs and trees. Howver right now i am looping using: while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() screen.fill(screencolor) pygame.draw.circle(screen, linecolor, (500, 20), 12, 0)
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.