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

Started by
3 comments, last by Washu 10 years, 7 months ago

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.

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

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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

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.

This topic is closed to new replies.

Advertisement