Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Tile Animation Example  (Read 2060 times)

0 Members and 1 Guest are viewing this topic.
Tile Animation Example
« on: January 28, 2012, 08:14:27 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
Been a long time since I've used GM, and I have been looking over my old Zelda GB engine that I have worked on months ago. One of the things that I have tried doing in the game is to allocate almost every static background object into tiles (that is surfaces, walls, and of course animations), but for the most part was not entirely successful. In trying to make my game work more efficiently, I have tried to create a single object that would animate all the background animations that the player cannot interact with. I don't know how much more efficient it is compared to using solid objects though, perhaps some people can give some feedback.
Logged
Re: Tile Animation Example
« Reply #1 on: January 28, 2012, 09:28:16 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
First of all, for background animations I would probably use tile animations as well. Altough I don't know if I would it similar to you, but your solution seems to work. And I have to say this because it was very difficult looking through your code.

Your coding style leaves a lot to be desired. Your code was just not readable. No matter how much comments you put in there it is a big mess. And it was clear from your code that even you lost track. I say this not to make you feel bad, but to give you advice. Because now it looks like you don't want people to understand your code.

1) Use indenting. After each bracket open and/or after each control statement add an additional indentation. You get to know how nested each piece of code is and what it is place is in the grand scheme of things. Especially when the number of lines far exceed the height of the screen.

2) Do not put several statements after one another without a line break. Especially when the line exceeds the width of the screen. After each ';' you start on a new line. An exception to this rule is when the combined statements do not even exceed half a screen and a block of several of these constructs are made more readable. For example:
Code: [Select]
switch( expression )
{
    case x:  single_statement1; break;
    case y:  single_statement2; break;
    case z:  single_statement3; break;
    default: single_statement4; break;
}


3) Use {, }, ( and ) brackets even when the syntax does not demand it to be mandatory. Using it makes the code more readable and understandable. Especially when the single statement is still spread over more lines than the height of the screen. It is best to place everything that belongs to a control sequence between brackets, the expression between rounded to visually separate it from the statements. And use curly brackets to signify a new scope.

4) This point is why I am certain that even you did not always know what you were doing. Avoid double jump/termination statements. I have often seen the following:
Code: [Select]
statement; statement; statement; break;
break; }
This is a double and redundant "break;" The second break is unreachable and only adds to the confusion for reading the code.

5) Be consistent and do not use ambiguous operators. Personally I like the C++/Java style operators. But GameMaker is not that strict in this matter. However it is best to stay consistent over your code, which also goes for the use of brackets with if-statements. Also I know that GameMaker can use the assignment operator as an equality operator, but this makes the code difficult to read. Especially when you also do not use the rounded brackets in an if-statement. Use the euality operator when comparing expressions.


Remember you want people to understand your code. So make it readable. No it is one big mess and it surprises me that the code works. However I also wonder how much redundant cases are in your code.
Logged
Re: Tile Animation Example
« Reply #2 on: January 28, 2012, 11:18:12 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
I understand that I have a sort of odd way of coding (for example, I usually don't use brackets when it is not absolutely necessary), but this is only my awkward preference. This was a quick cut and paste from my original code, at least the parts which I have thought were necessary, as right now my GM knowledge is not at all fresh. The redundant "breaks" may have followed from this and trying to organize it all together because they weren't in the orignal code when I checked. As for the comments most of the comments were originally made for myself to make sense of it better. I just wanted to put up the code itself first (as I was too lazy to explain the code right now and am not so great at explaining things), but I may provide an explanation later.
« Last Edit: January 28, 2012, 11:20:56 pm by shongshui »
Logged
Re: Tile Animation Example
« Reply #3 on: January 29, 2012, 08:33:24 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Just giving some advice. I don't know if you want to do programming as a mere hobby, or if you want to become a professional programmer. In the second case it is important that you learn the right conventions now. Because if bad codiing conventions become a habit then it will be difficult to unlearn it when it matters.
Logged
Re: Tile Animation Example
« Reply #4 on: January 29, 2012, 02:58:47 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
I know the proper conventions (I don't repeat the same habits when using other languages, such as C++ where such habits are not allowed) but I know when it is or is not needed. If it does not severely affect the way the game works, then I am okay with adopting a different take for different languages.

I am not trying to pursue a professional career, but I am working to complete a long planned fangame which is why I got into programming in the first place. I have given up on GM mainly though, and am trying to learn C++ and for the most part, I haven't been repeating the same conventions in GM.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.047 seconds with 48 queries.