GM:S 1.4 Pool game using Box2d

Discussion in 'Tutorials' started by GMWolf, Aug 5, 2016.

  1. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,241
    GM Version: GameMaker:Studio v1.4.1690
    Target Platform: ALL
    Download: Starter Project
    Links: YouTube Video
    Summary:
    Learn how to add the basics of a pool game using the built in physics capabilities of GMStudio.

    Tutorial:
     
  2. GabberMan

    GabberMan Member

    Joined:
    Sep 22, 2016
    Posts:
    11
    Hello Fel666,

    I did this tutorial to see how the gameplay of pool work for an idea I have for a game but I can't make to change direction once it has begun to move the cue. I'd appreciate any help in this regard because I'm just starting and I'm a complete noob.

    Thank you so much!
     
  3. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,241
    You should be able to remove the if(pulling) else part such that you can always orbit around the queue. You will also need to change a couple other areas.
     
    GabberMan likes this.
  4. RealsLife

    RealsLife Member

    Joined:
    Jul 8, 2016
    Posts:
    154
    Woaaa the real GMWolf I'm subscribed 2 you for some time now :D! Btw I see you use a lot of local vars I never do that I always use instance variables is there a big difference in performance?
     
  5. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,241
    Its mostly a difference in memory.
    The variables only stick around for that script / event.

    Its also "more correct" as the variables do not belong to the instance, but to the script.
     
    Bentley and RealsLife like this.
  6. Cinos Rider

    Cinos Rider Member

    Joined:
    Dec 21, 2017
    Posts:
    34
    your download link is doing a 404...
     
  7. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,241
    Right. I should have fixed the one in the YouTube video d'inscription.
    I will fix that one when I get the time. Thanks for letting me know!
     
  8. Cinos Rider

    Cinos Rider Member

    Joined:
    Dec 21, 2017
    Posts:
    34
    your welcome
     
  9. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,033
    Treating the instance-scope-only habit as a performance problem is a myopic yet unfortunately common diagnosis. The lack of correctness is the main problem of the habit, and the bomb starts ticking once you start independent work.

    The most common unwanted interaction is between looping variables inside and outside a script. Compare this correct implementation of capturing the values of 50 rolls of two dice:
    Code:
    for (var i = 0; i < 50; i++) {
      rolls[i] = d6(2);
    }
    
    Code:
    ///d6(n)
    {
      var total = 0;
      for (var i = 0; i < argument0; i++) {
        total += irandom_range(1, 6);
      }
      return total;
    }

    With this incorrect implementation that just crashes flat-out, for no reason other than failing to use local variables:
    Code:
    for (i = 0; i < 50; i++) {
      rolls[i] = d6(2);
    }
    
    Code:
    ///d6(n)
    {
      total = 0;
      for (i = 0; i < argument0; i++) {
        total += irandom_range(1, 6);
      }
      return total;
    }

    Another problem with the instance-scope-only habit is its interaction with recursion. Here's an easy example:

    Correct:
    Code:
    ///factorial(n)
    // A correct recursive implementation of n!
    {
      var n = argument0;
      if (n == 1) return 1;
      return factorial(n-1) * n;
    }
    

    Incorrect:
    Code:
    ///factorial(n)
    // An incorrect recursive implementation of n! that always returns 1
    {
      n = argument0;
      if (n == 1) return 1;
      return factorial(n-1) * n;
    }

    And in case you think I'm creating these examples synthetically to prove a point, I'm telling you right now that they are based on actual posts I've responded to (loop counter conflict / recursion conflict). Real people have been bitten by the instance-scope-only bug, and it's not an old wives' tale. And thanks to this trend of incessant focus on performance, there is nearly zero awareness of it among rookies and intermediates.

    So please stop looking at local variables in terms of performance, and stop treating it as optional or a matter of taste. It is a matter of keeping code correct and conflict-free, which often matters more than performance.
     
    Last edited: Dec 21, 2017
  10. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,241
    This. Very much this.
    People often dismiss "correctness". But it's really important. Performance is something you can worry about when you have good software engineering covered.
     
  11. viking.potato

    viking.potato Member

    Joined:
    Aug 16, 2017
    Posts:
    7
    Do you plan to upload the final version on the marketplace?
     
  12. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    721
    @GMWolf Awesome tutorial. I was understanding everything until 22 minutes then...

    Dot product!!! I've heard of a dot product in matrices, but not in vectors. I'll have to pause here and take some time to understand the "what" and the "why".
     
    GMWolf likes this.
  13. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,241
    A quick google search should helpp you understand.

    But in essence, the dot product will find how much of a vector lies along the other vector. So if they are parallel, you get a high value, and when perpendicular, you get 0.
     
    Bentley likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice