Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Improving code readability and maintenance with character movement and attack animations functionalities


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 warnexus   Prime Members   -  Reputation: 1504

Like
0Likes
Like

Posted 10 September 2013 - 03:12 PM

I am making a small-scale legend of zelda game.

 

I have incorporated both movement and attack functionalities inside a class Link because the character name is Link.

 

This means all the variables and methods and arraylists of the animation frames and logic are all in one class.

 

I just want to know if there are any issues doing it this way or can it be improved for the sake of better maintenance and readability or any convenience for the other programmers looking at the code in the future.


Edited by warnexus, 10 September 2013 - 03:16 PM.


Sponsor:

#2 PandaDragonThing   Members   -  Reputation: 311

Like
0Likes
Like

Posted 10 September 2013 - 05:03 PM

If you properly comment the code and enumerate the functions and variables such that you can understand how they work and their inteded use at a glance, there should be no problem. Everything related to "Link" is inside "Link" so it shouldn't be hard to find bugs relating to Link.

 

You might be able to divide classes down a bit. For example you mentioned all animation frames were inside Link. They way I've always done is it was to have a class called Sprite that would handle all the animation and animation frames, and the entity, Link in this case, would simply call a function like MySprite->DrawSprite();



#3 L. Spiro   Crossbones+   -  Reputation: 14374

Like
0Likes
Like

Posted 10 September 2013 - 05:11 PM

This means all the variables and methods and arraylists of the animation frames and logic are all in one class.
 
I just want to know if there are any issues doing it this way or can it be improved for the sake of better maintenance and readability or any convenience for the other programmers looking at the code in the future.

This is far too convoluted—the class does way too much.

You should have a CSprite class for anything related to sprites.
A CAnimation class uses sprites and draws them in order to play animations.

A CEntity is a thing in the game world and has a COrientation.
A CCharacter is any character-type object in the game and inherits from CEntity.
A CDrawableCharacter inherits from CCharacter and has a CAnimation for rendering.
A CLink inherits from CDrawableCharacter and adds logic specifically about Link.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#4 Kryzon   Prime Members   -  Reputation: 3314

Like
0Likes
Like

Posted 10 September 2013 - 06:54 PM

This means all the variables and methods and arraylists of the animation frames and logic are all in one class.

 

Since it's a small project, you can invest some time in learning how to use a Component model.

 

http://stackoverflow.com/questions/1901251/component-based-game-engine-design

http://gamedev.stackexchange.com/questions/19830/game-components-game-managers-and-object-properties


Edited by Kryzon, 10 September 2013 - 06:55 PM.


#5 Washu   Senior Moderators   -  Reputation: 5493

Like
0Likes
Like

Posted 10 September 2013 - 07:27 PM

 

This means all the variables and methods and arraylists of the animation frames and logic are all in one class.
 
I just want to know if there are any issues doing it this way or can it be improved for the sake of better maintenance and readability or any convenience for the other programmers looking at the code in the future.

This is far too convoluted—the class does way too much.

You should have a CSprite class for anything related to sprites.
A CAnimation class uses sprites and draws them in order to play animations.

A CEntity is a thing in the game world and has a COrientation.
A CCharacter is any character-type object in the game and inherits from CEntity.
A CDrawableCharacter inherits from CCharacter and has a CAnimation for rendering.
A CLink inherits from CDrawableCharacter and adds logic specifically about Link.


L. Spiro

 

You could also have a Sprite, Animation, Entity, Character, DrawableCharacter, and Link. All of which elide the disgusting wart you threw on there for no apparent reason :)


In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS