1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Development] Earth Defend (web game)

Discussion in 'Game Development' started by SnaKy, Jun 10, 2015.

  1. SnaKy

    SnaKy

    Joined:
    Jul 15, 2004
    Messages:
    333
    Resources:
    8
    Models:
    2
    Icons:
    1
    Maps:
    5
    Resources:
    8
    Hello there,

    in winter this year I started this small web-based game in javascript. Without much of beforehand idea it turned out to this. It's about an one man, known as Astronaut, defending whole Earth with various weapons against asteroids and various alien lifeforms. Main core of it took me whole two weeks but in some freetime I eventually was able to form it closer to my vision. It's still far from being labeled as finished project but it is playable at this point.

    [​IMG]

    You will need the newest Chrome, best played with full hd resolution (use fullscreen). It's capped on 60 fps.

    Play the game here: http://ed.baranok.eu/



    If you want to test all weapons tap key "T". Or just check console.

    Enjoy and don't hesitate to leave a comment.



    *
     
    Last edited: Jun 10, 2015
  2. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,840
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    Looks decent for a prototype, I only find it ridiculous that you don't properly listen to simple events such as mouse clicks in a proper standard way, such that it will work in all decent browsers, though the source is kind of jumbled, so I can't even find where the event is registered.

    For starters, use EventTarget.addEventListener instead of the 10 years obsolete function properties, and don't get information from w3schools...(hint: it's a terrible site)

    I don't quite understand why you are using timeouts all over the place. Especially in places that are called pretty much right away (e.g. Main, what's even the point of the timeout there, just have it run in global scope, or let it be a self-executing function).

    Beyond that, the code is a bit too messy, and depends on too libraries, to really look around.
     
    Last edited: Jun 11, 2015
  3. SnaKy

    SnaKy

    Joined:
    Jul 15, 2004
    Messages:
    333
    Resources:
    8
    Models:
    2
    Icons:
    1
    Maps:
    5
    Resources:
    8
    That explains why it didn't listened mouse with Apple products. I was learning on the run that explains the mess I guess. Never really wanted to refactor the code until I would be convinced it's good enough.

    When I tried to run too many funcs at once it kinda never got to the end, I guessed there is some limiter like in WC3 and timeouts fixed it.

    Anyway I never really guessed somebody would look at the code (tho' I would do the same). I appreciate the new perspective you gave me upon this. Also thanks for feedback.

    Have a Good day.
     
  4. GhostWolf

    GhostWolf

    Joined:
    Jul 29, 2007
    Messages:
    4,840
    Resources:
    2
    Tools:
    1
    Tutorials:
    1
    Resources:
    2
    There are no limiters of any kind, and there isn't really a point in having main-flow code run with timeouts.
    Now if you want to organize code better and not have everything in global scope, self-executing functions kind of achieve the job.
    If it hang, then there is an issue with the code.

    As to refactoring, that's perfectly sensible, I am all for making bad but working code, and later on rewriting it (ala code iterations), especially when learning a new language.
    One of the more noticeable things to me is the lack of prototypes. E.g. for the different AI types, where you can have a generic attack method for every type, instead of a large switch, and just having functions inside their scopes, for example - createAstronaut could as well be the constructor of your player, and the rest of the functions be its methods.
    Code (Javascript):

    function Player(...) {
        // initialize all the stuff you put in the Player variable
        // then do the stuff in createAstronaut
    }

    Player.prototype = {
        destroy: function () {
            // destroyAstronaut
        },

        animate: function () {
            // animateAstronaut
        },

        load: function () {
            // loadPlayer
        },

        ... // and so on
    };

    // Example of usage
    var myPlayer = new Player();
    myPlayer.animate();
     

    Right now your code is very similar to procedural code, and having prototypes and methods tends to result in neater and more readable code (I am tempted to write OOP, however I scorn that overused and overemphasized term).

    Generally speaking though, try to stick to standard ECMAScript 5 features, instead of mixing all sorts of really old and obsolete things. In this regard, w3schools is a terrible site. MDN, and searching for stuff on stackoverflow, is much more preferable.