SJA random projects - Page 4

User Tag List

Page 4 of 24 FirstFirst ... 2345614 ... LastLast
Results 31 to 40 of 236
  1. #31
    Moderator TimTim's Avatar
    Join Date
    Aug 2013
    Posts
    1,804
    Country:
    Polymorphism is another name for class inheritance. Polymorphism is bad for any large scale application.

    --- Updated ---

    Just so we're clear, the patterns I'm describing are completely different from the code @Higor provided. I would actually like to put together a live-editable example for you guys to play around with so you can see what I mean. Perhaps tomorrow I'll get around to it if I'm feeling up to it.

  2. #32
    Whicked Sick ~~D4RR3N~~'s Avatar
    Join Date
    Jul 2012
    Location
    Venezuela
    Posts
    1,614
    Country:
    Please do if you can @TimTim because I was thinking you something like what Higor posted...
    Quote Originally Posted by |uK|UNrealshots View Post
    You're playing a game that came out in 1999 in the year 2012 who is the fucking nerd here?
    All of us. Enjoy.

  3. #33
    snakeware's Avatar
    Join Date
    Dec 2014
    Posts
    39
    Country:
    my brain hurts, give me some links to start learning this much deeper, i barely know js and html5, have done some few works with visual studio, but all of them very newb

  4. #34
    Moderator TimTim's Avatar
    Join Date
    Aug 2013
    Posts
    1,804
    Country:
    Here, I'll convert the code @Higor provided to what I'm talking about real quick. For the record, describing animals is actually kind of a bad example (no offense to Higor) since it's kind of impractical, doesn't really have any real world use, and using classes to describe something like an animal is pretty silly. If you're going to describe (store data about) something like an animal, just use an object with keys and values. In real world applications, you'll have a ton of functions and some kind of output for humans to interface with, which is where things get messy with polymorphism.

    I'm sure the following could be done with C++, but I'm not trying to spend more than a couple minutes on this so I'll just write it using modern JS.

    ...Actually you know what, that's such an impractical example I'm not even going to go that far. Just create some objects that describes your `Ants` lol. Anything more than that is completely unnecessary. Let's expose our ants' data via some RESTful API where some requests and responses might look like this:

    Code:
    GET `/api/ants/0`:
    {
      "id": 0,
      "age": 2,
      "queen": true,
      "children": [1, 2]  // other existing ant ids
    }
    Code:
    GET `/api/ants/0?populate=children`:
    {
      "id": 0,
      "age": 2,
      "queen": true,
      "children": [
        {
          "id": 1,
          "age": 1,
          "queen": false,
          "children": []
        },
        {
          "id": 2,
          "age": 0.5,
          "queen": false,
          "children": []
        }
      ]
    }
    Maybe later on I'll put together something that actually uses functions so you can see what I'm talking about in my other posts, like a simple in-browser ShockRifle or something. Although I'm already feeling kinda lazy today lol. We'll see...
    Last edited by TimTim; 08-30-2015 at 01:40 PM.

  5. #35
    Whicked Sick Chamberly's Avatar
    Join Date
    Jul 2012
    Location
    Vandora Temple
    Posts
    5,488
    Country:
    I was looking at the ESR in the actor browser and wotgreal exporter trying to find a way to snatch it on a deco. -.- This was a few months ago.
    Gotta try again. Damn thing doesn't seem like it want to be easy where I can't find the color/texture of the ESR to change it.


    http://irc.lc/globalgamers/uscript for uscript discussion.

  6. #36
    Whicked Sick UT-Sniper-SJA94's Avatar
    Join Date
    Oct 2011
    Location
    What was England
    Posts
    4,427
    Country:
    This crap is some of the objects for my space invader game I made a month ago(not released).
    Code:
    player = {
        width: 40,
        height: 24,
        speed:8,
        lives: 5,
        shots: 0,
        kills: 0,
        x: 0,
        y: 600,
        shotX: 0,
        shotY: 0,
        bCanShoot: true,
        bDisplayShot: false,
        level: 1,
        score: 0
    };
    
    enemy = function (x,y,row,col)
    {
        this.x = x;
        this.y = y;
        this.bAlive = true;
        this.shotX = 0;
        this.shotY = 0;
        this.row = row;
        this.col = col;
    }
    
    
    house = function (pos)
    {
    
        this.width = 64;
        this.height = 40;
        this.x =  -75 + pos  * 150 + this.width; // :/
        this.y = canvas.height - 125;    
        this.bits = [];
    
       //This creates the pieces of the houses that can get destroyed when hit.
        for (var i = 0; i < (this.height / 8); i++) {
    
            this.bits[i] = [];
    
            for (var x = 0; x < (this.width / 8); x++){
    
                this.bits[i][x] = 0;
            }
        }
    
    }

  7. #37
    Whicked Sick UT-Sniper-SJA94's Avatar
    Join Date
    Oct 2011
    Location
    What was England
    Posts
    4,427
    Country:
    Made another basic game, naughts and crosses: Naughts and crosses


  8. #38
    Moderator TimTim's Avatar
    Join Date
    Aug 2013
    Posts
    1,804
    Country:
    I whipped together a little something to demonstrate composition (as opposed to inheritance).

    Demo: https://timbur.github.io/composition-example/
    Source: https://github.com/timbur/composition-example/

    Note that the only thing inherited throughout all of that is `React.Component`, which only exists to mount and render components within the page. The key design pattern is that each component is able to essentially exist on its own. This maximizes the separation of concerns (which should always be the goal when designing any large application) and overall makes everything super predictable and easier to work with. It also makes it insanely easy for multiple developers to enhance each other's work. For instance, the theme I included could be separated into its own package, and the weapons themselves could be separated into their own packages, and then when loading the game all you'd need to do is import those packages from wherever they originate (typically done via something along the lines of `npm install ut-weapon-shock-rifle`) and then pass them to the `Game` component when mounting the game.

    There are a handful of other concepts I won't really touch on just yet, but I will say this... When you have declarative components (i.e., they always output one predictable thing based on some inputs/properties) that are able to operate independently of one another and you combine that with data flowing in a single direction, a lot of really cool stuff becomes possible. For example, if UT was designed in this way, in a split second you could load the entire state of some game and instantly and efficiently go forwards and backwards to any point within some saved game without having to calculate anything in between. It also becomes trivial (easy) to add middleware to your app's flow of actions that would allow you to very easily develop and debug whatever you need.

    I might add some ammo, shock beams, combos, other example weapons, etc. at some point. But I'll definitely create an in-depth tutorial to help people get started with this particular workflow, probably based on the live-editing environment I'm working on.

    Let me know if you have any questions.

  9. #39
    Whicked Sick ~~D4RR3N~~'s Avatar
    Join Date
    Jul 2012
    Location
    Venezuela
    Posts
    1,614
    Country:
    I think see your point. If something is malfunctioning, this way is easier to debug it (Thinking of large projects here). But if you know what you want your class to do, and know you have a class with similar behaviour, wouldn't it be best practice to just sub-class it? I think it would be more efficient that way since you'd have less code to read (Less mambo-jambo and shit), also you wouldn't have code repeating(?) Pretty much throwing cents here.

    But as I' write this I can understand better what you mean. Finding among large files specific super class with a problem might be a pain in the ass...

    Ok, I'm havign mixed feeling right now everytime I try to write something good about inheritance a little "but hey" sound in the back of my head and says something "but that would be more annoying ". I'm pretty much having a nice discussion about practices with myself ty.

    I see your point and now I can't decide which is best i cri everytiem ;-;
    Quote Originally Posted by |uK|UNrealshots View Post
    You're playing a game that came out in 1999 in the year 2012 who is the fucking nerd here?
    All of us. Enjoy.

  10. #40
    Moderator TimTim's Avatar
    Join Date
    Aug 2013
    Posts
    1,804
    Country:
    Quote Originally Posted by ~~D4RR3N~~ View Post
    But if you know what you want your class to do, and know you have a class with similar behaviour, wouldn't it be best practice to just sub-class it? I think it would be more efficient that way since you'd have less code to read (Less mambo-jambo and shit), also you wouldn't have code repeating(?)
    Nope. Take a closer look at each component's code. I know it probably looks complicated at first but it's actually really, really minimal. There is no duplicate or unnecessary code. Any variable/constant/function that you see defined there would also have to be defined somewhere in subclasses if you used polymorphism.

    The difference is the overall design and explicitness (obviousness). Each component uses only exactly what it needs, and when you look at each component's `render` (function), it should be immediately obvious (if you know HTML and a little bit of JS) which properties it uses and what exactly gets generated and which types of events are handled. So when you look at it like that, there's no mystery to it, except for maybe the `SelectedWeapon` part, since that's actually a variable component, but even then it should be pretty obvious what's happening there. You don't get this same level of explicitness and obviousness with polymorphism (subclasses), and that's just one of many advantages that composition has over inheritance.

    Edit: Renamed `Weapon` to `Player` in the source, since that probably makes a bit more sense to some folks for now. Might make sense to switch it back to `Weapon` later on if/when I implement the real `Player` component.

    But anyway, @UT-Sniper-SJA94 sorry for hijacking your thread lol. I should probably make another for my own shit some day. I would just like to reiterate that you should look into building something with `React` and modern JS.
    Last edited by TimTim; 08-31-2015 at 02:38 AM.

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Similar Threads

  1. Another random game
    By UT-Sniper-SJA94 in forum Spam Section
    Replies: 79
    Last Post: 06-29-2015, 07:59 PM
  2. Random siege gif.
    By Chamberly in forum Screenshots
    Replies: 8
    Last Post: 01-05-2015, 04:17 AM
  3. Ben10 / Random / random Anime names
    By uenz in forum Reports/Complaints & Appeals
    Replies: 7
    Last Post: 08-30-2014, 02:43 PM
  4. Random bug
    By UT-Sniper-SJA94 in forum Spam Section
    Replies: 7
    Last Post: 03-13-2014, 11:22 AM
  5. Everybody random guy
    By |uK|B|aZe//. in forum Bans
    Replies: 0
    Last Post: 12-23-2011, 10:31 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •