Results 1 to 8 of 8

Thread: Need the logic of a general programmer or mathematician..

  1. #1
    Senior Member
    Join Date
    Aug 2004
    Location
    W Yorkshire
    Posts
    5,691
    Thanks
    85
    Thanked
    15 times in 13 posts
    • XA04's system
      • Motherboard:
      • MSI X570-A Pro
      • CPU:
      • AMD Ryzen 5 3600
      • Memory:
      • Corsair 2x 8gb DDR 4 3200
      • Storage:
      • 1TB Serpent M.2 SSD & 4TB HDD
      • Graphics card(s):
      • Palit RTX 2060
      • PSU:
      • Antec Truepower 650W
      • Case:
      • Fractcal Meshify C
      • Operating System:
      • Windows 10
      • Monitor(s):
      • iiyama 34" Curved UWQHD
      • Internet:
      • Virgin 100mb Fibre

    Need the logic of a general programmer or mathematician..

    For a game I'm programming I need the level to increase everytime the player gets a score that is a multiple of 5. E.g. Level 1 = Score 0. Level 2 = Score 5. Level 3 = Score 10, etc.

    This is the kind of code I have already:
    Code:
                    if (playerScore == 5)
                    {
                        playerLevel++;
    
                        //Difficulty modifiers
                        bulletSpeed /= (float)playerLevel;
    
                        goodieSpeed /= (float)playerLevel;
    
                        bombSpeed *= (float)playerLevel;
    
                    }
    But instead of using many many if statements, is there something else like an equation I could use?

    Basically I'm wanting to check if playerScore is a mutliple of 5...



    Thanks

  2. #2
    jim
    jim is offline
    HEXUS.clueless jim's Avatar
    Join Date
    Sep 2008
    Location
    Location: Location:
    Posts
    11,466
    Thanks
    614
    Thanked
    1,649 times in 1,310 posts
    • jim's system
      • Motherboard:
      • Asus Maximus IV Gene-Z
      • CPU:
      • i5 2500K @ 4.5GHz
      • Memory:
      • 8GB Corsair Vengeance LP
      • Storage:
      • 1TB Sandisk SSD
      • Graphics card(s):
      • ASUS GTX 970
      • PSU:
      • Corsair AX650
      • Case:
      • Silverstone Fortress FT03
      • Operating System:
      • 8.1 Pro
      • Monitor(s):
      • Dell S2716DG
      • Internet:
      • 10 Mbps ADSL

    Re: Need the logic of a general programmer or mathematician..

    I know virtually nothing about programming, but is it not possible to divide playerScore by 5 and check whether the result is an integer?

    Admittedly that wouldn't work "as is" - if you just checked that as an if statement then presumably it would happen an infinite number of times when playerScore=multiple of 5. Sorry I can't help with programming, I absolutely despise it . If I'm on the wrong track then sorry!

  3. #3
    Banned
    Join Date
    Jun 2008
    Posts
    2,129
    Thanks
    13
    Thanked
    189 times in 160 posts

    Re: Need the logic of a general programmer or mathematician..


  4. #4
    Registered+
    Join Date
    Aug 2009
    Posts
    53
    Thanks
    1
    Thanked
    3 times in 3 posts

    Re: Need the logic of a general programmer or mathematician..

    Code:
    if(playerScore%5 == 0)
    {
              //Write code here
    }

  5. #5
    Get in the van. Fraz's Avatar
    Join Date
    Aug 2007
    Location
    Bristol
    Posts
    2,919
    Thanks
    283
    Thanked
    396 times in 230 posts
    • Fraz's system
      • Motherboard:
      • Gigabyte X58A-UD5
      • CPU:
      • Watercooled i7-980X @ 4.2 GHz
      • Memory:
      • 24GB Crucial DDR3-1333
      • Storage:
      • 240 GB Vertex2E + 2 TB of Disk
      • Graphics card(s):
      • Water-cooled Sapphire 7970 @ 1175/1625
      • PSU:
      • Enermax Modu87+
      • Case:
      • Corsair 700D
      • Operating System:
      • Linux Mint 12 / Windows 7
      • Monitor(s):
      • Dell 30" 3008WFP and two Dell 24" 2412M
      • Internet:
      • Virgin Media 60 Mbps

    Re: Need the logic of a general programmer or mathematician..

    Code:
    unsigned level = 0;
    unsigned score = 0;
    const unsigned levelFactor = 5;
    
    //  Stuff happens, score gets increased
    
    // Check to see if we have moved up a level
    unsigned newLevel = score/levelFactor;   // Use properties of integer division
    if(level < newLevel)
    {
      level = newLevel
      bulletSpeed /= (float)playerLevel;
      goodieSpeed /= (float)playerLevel;
      bombSpeed *= (float)playerLevel;
    }

  6. #6
    Get in the van. Fraz's Avatar
    Join Date
    Aug 2007
    Location
    Bristol
    Posts
    2,919
    Thanks
    283
    Thanked
    396 times in 230 posts
    • Fraz's system
      • Motherboard:
      • Gigabyte X58A-UD5
      • CPU:
      • Watercooled i7-980X @ 4.2 GHz
      • Memory:
      • 24GB Crucial DDR3-1333
      • Storage:
      • 240 GB Vertex2E + 2 TB of Disk
      • Graphics card(s):
      • Water-cooled Sapphire 7970 @ 1175/1625
      • PSU:
      • Enermax Modu87+
      • Case:
      • Corsair 700D
      • Operating System:
      • Linux Mint 12 / Windows 7
      • Monitor(s):
      • Dell 30" 3008WFP and two Dell 24" 2412M
      • Internet:
      • Virgin Media 60 Mbps

    Re: Need the logic of a general programmer or mathematician..

    Quote Originally Posted by jimbo90210us View Post
    Code:
    if(playerScore%5 == 0)
    {
              //Write code here
    }

    Modulus operator is definitely a useful thing to know about here, although not all that useful if you are regularly checking to see if the score/level has increased, as if your score is stuck on a multiple of 5, you'll regularly increase the difficulty level.

  7. #7
    Get in the van. Fraz's Avatar
    Join Date
    Aug 2007
    Location
    Bristol
    Posts
    2,919
    Thanks
    283
    Thanked
    396 times in 230 posts
    • Fraz's system
      • Motherboard:
      • Gigabyte X58A-UD5
      • CPU:
      • Watercooled i7-980X @ 4.2 GHz
      • Memory:
      • 24GB Crucial DDR3-1333
      • Storage:
      • 240 GB Vertex2E + 2 TB of Disk
      • Graphics card(s):
      • Water-cooled Sapphire 7970 @ 1175/1625
      • PSU:
      • Enermax Modu87+
      • Case:
      • Corsair 700D
      • Operating System:
      • Linux Mint 12 / Windows 7
      • Monitor(s):
      • Dell 30" 3008WFP and two Dell 24" 2412M
      • Internet:
      • Virgin Media 60 Mbps

    Re: Need the logic of a general programmer or mathematician..

    Another point... you're going to end up with a very short game if you're constantly dividing/multiplying some kind of speed by the current level.

    Say bulletSpeed starts at 1000. Every time the level increases, you will be dividing by the new level number. This is a factorial division, and the denominator will get large VERY quickly.

    So... say the bulletSpeed starts at 1000. By level 9, you will have done:

    1000/(1*2*3*4*5*6*7*8*9) = 0.0028

  8. #8
    Senior Member
    Join Date
    Aug 2004
    Location
    W Yorkshire
    Posts
    5,691
    Thanks
    85
    Thanked
    15 times in 13 posts
    • XA04's system
      • Motherboard:
      • MSI X570-A Pro
      • CPU:
      • AMD Ryzen 5 3600
      • Memory:
      • Corsair 2x 8gb DDR 4 3200
      • Storage:
      • 1TB Serpent M.2 SSD & 4TB HDD
      • Graphics card(s):
      • Palit RTX 2060
      • PSU:
      • Antec Truepower 650W
      • Case:
      • Fractcal Meshify C
      • Operating System:
      • Windows 10
      • Monitor(s):
      • iiyama 34" Curved UWQHD
      • Internet:
      • Virgin 100mb Fibre

    Re: Need the logic of a general programmer or mathematician..

    Quote Originally Posted by jimbo90210us View Post
    Code:
    if(playerScore%5 == 0)
    {
              //Write code here
    }
    Perfect. Thankyou.

    Quote Originally Posted by Fraz View Post
    Another point... you're going to end up with a very short game if you're constantly dividing/multiplying some kind of speed by the current level.

    Say bulletSpeed starts at 1000. Every time the level increases, you will be dividing by the new level number. This is a factorial division, and the denominator will get large VERY quickly.

    So... say the bulletSpeed starts at 1000. By level 9, you will have done:

    1000/(1*2*3*4*5*6*7*8*9) = 0.0028
    Very true. I was just messing with the code there really trying to get something basic to work. Will sort something properly out now

    Thanks everyone!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. PIC programming
    By explicitlyrics in forum Software
    Replies: 12
    Last Post: 19-10-2008, 02:21 PM
  2. Switching between Silent & General profile, on Nokia N73
    By James Payne in forum Smartphones and Tablets
    Replies: 0
    Last Post: 17-08-2006, 07:46 PM
  3. Marine Corp's General Reinwald was interviewed
    By XA04 in forum General Discussion
    Replies: 2
    Last Post: 20-08-2005, 11:00 AM
  4. C Programming Resources
    By Anders in forum Software
    Replies: 2
    Last Post: 08-05-2004, 09:08 PM

Posting Permissions

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