Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pygame Groups
#1
I'm working on a project that's nearing its completion. I'm in the process of addressing my problem with painting all the sprites in the correct order and here is what I have come up with so far. It would be good to get your feedback and suggestions on the topic.


My immediate thoughts were to create something that's:
- simple to use
- require low maintenance
- flexible enough to apply to future projects

I thought I would just build on the existing stuff from pygame (the class pygame.sprite.Group). I figure in most cases game screens are created with the following elements:

BackGround
----------
All the objects involved in making up the background.
This approach would allow the use of a big picture, and additional objects like trees could be added to it, or moved during game play to give a sense of depth.


ZPlanes
-------
Focuses more on the player and enemies that are moving about.
I'm thinking this should be some sort of array, but that's still in the theory stage.


Interface
---------
Objects used to make up the user interface like score, strength, etc.


Overlay
-------
Images that need to be painted on the topmost screen like "Game paused", "Loading ...", etc.


import pygame

pygame.init()

class ScreenObject(pygame.sprite.Sprite):
    pass
# ScreenObject() ------------------------------------------------------------



class SOGroups:
    'Class - manages groups from the pygame.sprite.Group collection.'
    _groups =[] # <-- don't know about this bit.
    
    class BackGround(pygame.sprite.Group):
        def __init__(self):
            self._group =pygame.sprite.Group()
        # __init__() --------------------------------------------------------

        
        def add(self, screen_object):
            'Function - adds an object to this group.'
            self._group.add(screen_object)
        # add() -------------------------------------------------------------


        def remove(self, screen_object):
            'Function - removes the object from this group.'
            pass
        # remove() ----------------------------------------------------------
        

    class ZPlanes(pygame.sprite.Group):
        'Container - for all the screen objects in the Z-Plane.'
        def __init__(self):
            self._group =pygame.sprite.Group()
        # __init__() --------------------------------------------------------

        
        def add(self, screen_object):
            'Function - adds a screen object to the background group.'
            self._group.add(screen_object)
        # add() -------------------------------------------------------------


        def remove(self, screen_object):
            'Function - removes the object from this group.'
            pass
        # remove() ----------------------------------------------------------

        
    class Interface(pygame.sprite.Group):
        'Container - for all the screen objects in the Interface.'
        def __init__(self):
            self._group =pygame.sprite.Group()
        # __init__() --------------------------------------------------------

        
        def add(self, screen_object):
            'Function - adds a screen object to the background group.'
            self._group.add(screen_object)
        # add() -------------------------------------------------------------


        def remove(self, screen_object):
            'Function - removes the object from this group.'
            pass
        # remove() ----------------------------------------------------------
        

    class Overlay(pygame.sprite.Group):
        'Container - for all the screen objects in the Overlay.'
        def __init__(self):
            self._group =pygame.sprite.Group()
        # __init__() --------------------------------------------------------

        
        def add(self, screen_object):
            'Function - adds a screen object to the background group.'
            self._group.add(screen_object)
        # add() -------------------------------------------------------------


        def remove(self, screen_object):
            'Function - removes the object from this group.'
            pass
        # remove() ----------------------------------------------------------
        
    
    @classmethod
    def paint(cls):
        'Function - paints any screen object found in the groups onto the screen.'
        pass
    # paint() ---------------------------------------------------------------
    

    @classmethod
    def remove(cls, screen_object):
        'Function - removes the screen object from all of the grooups.'
        pass
    # remove() --------------------------------------------------------------
    
# SOGroups ------------------------------------------------------------------
Reply


Messages In This Thread
Pygame Groups - by microphone_head - Aug-27-2018, 03:28 PM
RE: Pygame Groups - by Windspar - Aug-27-2018, 08:20 PM
RE: Pygame Groups - by microphone_head - Aug-28-2018, 07:30 AM
RE: Pygame Groups - by microphone_head - Aug-28-2018, 09:53 AM
RE: Pygame Groups - by microphone_head - Aug-28-2018, 10:40 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020