Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. **General**
  2. - When using Mega Engine, follow the format objPlayer instead of obj_player for consistency. Use this camelCase in variable names too.
  3. - I didn't come across any comments. I highly recommend commenting your code at least a little; describe what the code under the comment does in one or two sentences, it will help if you come across a bug and have to revisit the code.
  4.  
  5. **Create event**
  6. - Don't use ``alarm_set``, it is harder to read and unnecessary. Just use ``alarm[0] = 120;`` instead of ``alarm_set(0,120);``
  7. - While on the topic of that alarm_set line: it's good practice to put a space inbetween function arguments. ``alarm_set(0, 120);`` is easier on the eye than ``alarm_set(0,120);``, specially when the arguments get complex. The same goes for operations: use ``x + y`` instead of ``x+y``. It also applies to assignments: use ``variable = 1;`` instead of ``variable=1;``. It applies to a lot of things actually, but I can't list them all; it should feel natural. Note that I also made this mistake in some places in Mega Engine, but I have since learned this is not the way to go.
  8. - Those manual array assignments look ugly, and are really unnecessary. You could replace all those lines with the following code:
  9.  
  10. ```Javascript
  11. for(var i = 0; i <= 21; i++)
  12. {
  13. black[i] = false;
  14. send[i] = false;
  15. }```
  16.  
  17. As a general guideline, don't use manual array assignments if you have over 3 indexes.
  18.  
  19. **Alarm 0**
  20. - Because of some stupid design decision YoYoGames made, the game always starts with the same random seed. What this means is that you will always get the same pattern if you just use choose; but only if no other random functions have been called before it, so it's consistent yet inconsistent at the same time. You probably want to make it completely random; to create a random seed, use ``randomize();`` before calling ``choose`` or any other random function.
  21. - You could remove the switch/case statement in favor of a calculation to make it shorter... but that would get complicated, so I can't hold it against you.
  22.  
  23. **Alarm 1**
  24. - In the switch/case statement, you always call black[x] with x being the number from the case. Instead of all that, you could just write ``black[global.blobs] = true;`` above the switch line.
  25. - You don't want to write extra code on the line you end a statement, aka the line with }. Leave that line alone, and continue below it. You can, however, write ``else`` (or ``else if <condition>``) on this line if you want. On that note, it's probably easier to read if you leave an empty line between your statements:
  26.  
  27. ```Javascript
  28. if condition
  29. // do something
  30.  
  31. if otherCondition
  32. // do something else```
  33.  
  34. instead of
  35.  
  36. ```Javascript
  37. if condition
  38. // do something
  39. if otherCondition
  40. // do something else```
  41.  
  42. - Minor thing, but image_xscale cannot be 1 and -1 at the same time. Thus, you could have used ``else if image_xscale == -1`` (notice the added else) to save Game Maker some processing power.
  43.  
  44. **Alarm 2**
  45. - Has the "don't write code on the } line" problem, but clean aside from that!
  46.  
  47. **Step**
  48. - That's too many blacks for one line. It may be a little more complicated, but this would look a lot cleaner:
  49.  
  50. ```Javascript
  51. var canContinue = true;
  52. for(var i = 0; i <= 21; i++)
  53. {
  54. if black[i] == false
  55. {
  56. canContinue = false;
  57. break;
  58. }
  59. }
  60.  
  61. if canContinue == true
  62. {
  63. // Do the image_xscale things
  64. }```
  65.  
  66. I can see why this may not be your first thought, and it may be too complicated for what it's worth. Just saying it's cleaner, but your solution works too.
  67.  
  68. - Instead of using ``x = 216``, try making it more obvious how you got this number. In this case, ``x = room_width - 40`` would make it more obvious.
  69.  
  70. **Draw**
  71. - I'm not going to lie... this looks really ugly. There is no easy fix, but you can try something like this:
  72.  
  73. ```Javascript
  74. xx[0] = -41; yy[0] = 40;
  75. xx[1] = -24; yy[1] = 40;
  76. // etc...
  77.  
  78. for(var i = 0; i <= 21; i++)
  79. draw_rectangle(x + xx[i], y + yy[i], x + xx[i] + 17, y + yy[i] - 16, false);```
  80.  
  81. This doesn't have the exceptions for image_xscale == 1/-1, but you can add these in the for-loop.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement