• Advertisement
Sign in to follow this  

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

This topic is 1593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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();

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

 

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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement