Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Class Structure Question

$
0
0

@MuntyScruntFundle wrote:

Hello again folks.

I realise this is a general coding question and not a specific MonoGame issue, but you folks do a lot of this coding lark and I'd sooner ask people who actually work at this rather than ask a forum of VS specialists who would answer with the "correct" VS way of coding.

The issue...

Say I have a whole bunch of sprites bouncing around the screen. Some are blue, some are red. Some are orange and some are pink.

All of these different 'types' of sprite have basic properties, velocity, position, spin, width, etc.
The orange sprites behave differently and have extra properties, spin2, target, etc.

So I thought I'd create a 'base' class that would hold all the common properties the sprites have.
Public Class Basics
Private property c_Velocity
etc.
(Please assume I've also completed the property code)

Now in the orange class I can say
Import Basics
Private Property c_Spin2
Private Property c_Drift
etc.

Now orange has all the basic properties and Spin2. I've saved a whole load of time as I'm not repeating all the common stuff.

But now I have the problem of remembering which is which, and the code in the parent classes looks untidy. Example:
Private Sub SpinMe
With Me
.Basics.Spin+=1
.cSpin2-=1
.Basics.Position+=cDrift
etc.

I hope you can see where I'm coming from. If someone handed me this to bug test, I'd be a bit confused!

All the classes, once I've cleaned them up, will be completely self contained so there won't be tons of code in Game1 that looks confusing.

So the question is; would you folks put every property in all your classes and have loads more code (in the case of this app hundreds of lines of properties in each class) or put all properties, used or not, in the Basics class and save all that code writing? Or go with this hybrid version?

Please comment as you see fit!
(My previous coding years weren't big on classes as they really weren't required often, and certainly not this inheritance stuff)

Thanks.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles