Game Development Community

To Component or Not to Component

by Kareem Glover · in Torque X 2D · 11/16/2009 (10:32 pm) · 4 replies


Okay.. just so everyone understands what I am doing I am building a bejeweled clone from scratch to better understand the TorqueX engine and sharpen up my C#.

At this moment I am trying to get some ideas on the best way to implement my next step.. logically.

So far this is what I have done. (i'm avoiding using the builder and doing everthing from code) Maybe I'll do a blog..

1) Code to create the game objects and place them randomly on the screen is complete. So you get you a nice random bejeweled map on game startup.

2) Player object created attached to a movement component. So now you can move around the grid within the confines.

The next phase I am working on is to have the user press a button and the jewel next to them is changed. (this is not really bejeweled but if I can understand this process logically I can build the code out)What I need is some guidance on how do you think the best way to implement this.

One of my ideas was in the player movement component is to have them press X. That will run a delegate but I'm stuck on how that delegate will interact with the gameobject[23] (lets assume thats the yellow jewel next to the highlighted player) in the game.cs code.

So I guess my main question is how would you reference another torqueobject from a component or am I going about this all wrong.

PsuedoCode

player is on over gameobject[23] x0,y0
Player press X Button
activate movementcomponent
x delegate is called
x delegate pulls gameobject[24] and changes material
new material shows on screen so we know the call worked

Thanks,

#1
11/17/2009 (9:33 am)
You might want to dump your T2DSceneObjects into an array and then load them from there.

from my memory (I'm at work don't have code in front of me) one the way to reference an object is:
TorqueObjectDataBase.Instance.FindObject<T2DSceneObject>("object name");

Also you might want to try using a tile map. I would take a look at John K's book. he has a Tetras section that could probably be turned into a Bejeweled game.
#2
11/17/2009 (9:58 am)
I actually have that book and made the Tetris clone. It doesn't deal much with components so I have been piecing in some of the other examples. To be honest not sure why I decided not to use tilemap but instead went with Sprite objects.

I think my logic problem is more with C# objects and not torque. (searching for a book on c# object programming to jog my brain) I am trying to understand logically (psuedo code will be just fine) on how to have a component minuplate a object within the main game class.

So

xxxxxx
xxxoxx
xxxxxx

O is the playerobject which has a movement component added to it. You press the X button and from the movement component it manipulates the object to the right. To be honest I really think I'm thinking about this the wrong way.

xxxxxx
xxxo+x
xxxxxx

Thanks

#3
11/18/2009 (4:48 pm)
I wouldn't use a component for this as it doesn't fit IMO and the ways I could think of using a component would be more complicated then using a tile map and tile positions.

IE:
Player at Tile X:0,Y:0
Player Presses X
X delegate gets called and Swaps Player Tile and Player Tile + 1

I'm assuming you already have either the player tiles or an x,x array that could be mapped into tile positions.
#4
11/22/2009 (8:58 pm)
Scott,

Thanks for the advice. I moved the player movement into the main class and out of the components.

-Kareem