Oriented Object discussion

Hi panda helper,

I’m currently working on my first game. It will be a 3d version of space invaders with good sound, music and speech.(Nothing original in fact…)

My question is the following:

-I want my game to be oriented object but I’m not sure how to do it with Panda. Let me explain, I clearly understand class and all that stuff. The issue is that take for example I have 1 fighter and 3 enemies. Fighter have life, ammo left, dammage, sheild info. Same things plus different thing for the enemies. I know how to create good object with these information BUT when the model come into the problem, that’s where I loose it.

For example, take this part of code:

def loadHeros(self):
        #Load the Spaceship
        self.fighter = loader.loadModelCopy("models/Fighter/Fighter.egg")

This is the model but how do you guy incorporate this model with the fighter object? For example, it would be good for me to have a self.fighter.getLifeLeft() method or something like that…

I hope my question is clear, I’m sorry my english is very bad and I’m searching the good word to explain what I want to say…

Don’t hesitate to ask question :slight_smile:



If I understand you correctly:

class Hero:

    def loadHeros(self): 
        #Load the Spaceship 
        self.fighter = loader.loadModelCopy("models/Fighter/Fighter.egg") 

    def getLifeLeft(self):
        #your code here

Yeah, it’s almost that but how do I move my hero in the rest of the application? Do I need to duplicate every function already in my model like Hero.setX() or could it be ok to do: Hero.fighter.setX(). I’m not at home right now so I can’t test it but I also want to know if it’s a “good procedure” (if it’s possible) :slight_smile:



What it sounds like you might want to do is create a class that derives from Actor, so that funcs like setX are included automatically.

My question seems to be strange to you guys to but lets take an easy example:

If you do a game with Roaming Ralph, and want Ralph to have some caracteristics like health, ammo, etc. There are 2 different things:
-The object Ralph
-The model Ralph

All I want to know is how you deal with that in your games? Do you do 2 class, one is ralph, the other is the model. Do you do a solution like proposed to do a class that derive from Actor? What are you doing in your game? All in one class with global variable and constant?

I’m waiting for your answers! thank you :slight_smile:


P.S: I will try the derived class this weekend…!

class Ralph:

    def __init__(self):
        self.model = Actor.Actor("ralph")

    def moveForward(self):

Actually, I might want to take back what I said about subclassing Actor. I looked at the Running Ralph mod I made a while back, and in it my Ralph class contains an Actor rather than deriving from it. Think more about this I remembered that I originally tried to derive from Actor, but there was some sort of weird problem, the details of which I can’t remember now.

In any case, my Ralph class has a constructor which takes an environment for finding the correct model to create an Actor and a parent node to reparent to. It has a function to add itself to a collision traverser (a lot of my mod was improving the collision detection for Ralph), an update function which handles keyboard input, changes animations and applies movement, and controls camera tracking, and a function to handle collisions detected by a collision handler.

While the update function should probably be split up into separate update and input handlers, this basic method will work well for most kinds of objects. There aren’t a lot of Hero.fighter.setX() type function calls because most complex behavior is handled inside member functions of the Ralph class.


That’s exactly what I wanted to know. This is my first game so I want the architecture to be realy good and not be in the middle of development and need to start over…!

If you don’t mind, I would be realy interested with you roaming ralph mod. In fact, if you can’t share all of the code, the class of ralph can be enough.

You can post it here if you don’t care if the code is public or you can PM me the code.

Thanks a lot man!


monsterden.net/misc/RunningR … 0061227.py

I posted the code on my website. Items of interest are fog, an improved camera, ability to jump with improved collision detection, walk/run animation blending, and evil Pandas who chase Ralph if he gets too close.

It uses the normal Ralph resources, so just create a directory and copy the necessary files into a “models” subdirectory: