Results 1 to 5 of 5

Thread: C# OpenGL game. Help on incrementing a score..

  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

    C# OpenGL game. Help on incrementing a score..

    Anybody here know C# well?

    Basically I'm using OpenGL and the TAO framework to create a game and I'm trying to increment a score simply by one. I'm making space invaders and when the bullet hits the enemy the score needs to go up by one. Now I simply can't increment the variable by 1 as the display method updates however many times a second and so the score ends up getting incremented 30 odd times mores instead of once.

    I've had a play about using booleans to create some kind of switch but this doesn't seem like the right thing to do. I have a feeling that using the system clock to only allow 1 to be incremented if a variable is used to measure a gap of 2 seconds between incrementing. This would stop it right?

    Just can't get my head around doing it.. anybody got an example for me?


    Thanks!

  2. #2
    Banhammer in peace PeterB kalniel's Avatar
    Join Date
    Aug 2005
    Posts
    31,023
    Thanks
    1,870
    Thanked
    3,381 times in 2,718 posts
    • kalniel's system
      • Motherboard:
      • Gigabyte Z390 Aorus Ultra
      • CPU:
      • Intel i9 9900k
      • Memory:
      • 32GB DDR4 3200 CL16
      • Storage:
      • 1TB Samsung 970Evo+ NVMe
      • Graphics card(s):
      • nVidia GTX 1060 6GB
      • PSU:
      • Seasonic 600W
      • Case:
      • Cooler Master HAF 912
      • Operating System:
      • Win 10 Pro x64
      • Monitor(s):
      • Dell S2721DGF
      • Internet:
      • rubbish

    Re: C# OpenGL game. Help on incrementing a score..

    No specific knowledge of c#, but why not only increment the score by one once, until some other condition like the bullet is no longer hitting the enemy or a new bullet is fired?

    eg (psuedo logic/code)

    Code:
    BulletHitsEnemy {
      if !alreadyHit { 
        score++;
        alreadyHit =1;
      }
    }
    BulletFired {
      alreadyHit =0;
    }
    Yes, I know you said you played with it, but why did it not seem like the way to go exactly?
    Last edited by kalniel; 16-11-2009 at 11:10 PM.

  3. #3
    Mostly Me Lucio's Avatar
    Join Date
    Mar 2007
    Location
    Tring
    Posts
    5,163
    Thanks
    443
    Thanked
    448 times in 351 posts
    • Lucio's system
      • Motherboard:
      • Gigabyte GA-970A-UD3P
      • CPU:
      • AMD FX-6350 with Cooler Master Seldon 240
      • Memory:
      • 2x4GB Corsair DDR3 Vengeance
      • Storage:
      • 128GB Toshiba, 2.5" SSD, 1TB WD Blue WD10EZEX, 500GB Seagate Baracuda 7200.11
      • Graphics card(s):
      • Sapphire R9 270X 4GB
      • PSU:
      • 600W Silverstone Strider SST-ST60F
      • Case:
      • Cooler Master HAF XB
      • Operating System:
      • Windows 8.1 64Bit
      • Monitor(s):
      • Samsung 2032BW, 1680 x 1050
      • Internet:
      • 16Mb Plusnet

    Re: C# OpenGL game. Help on incrementing a score..

    The flaw to kalniel's pseudo-code is it assumes only one bullet will be in play at any one time.

    To my mind the logical point to put your scoring code is in the response to the bullet's impact. Presumably a shot hits an enemy, and it either takes damage or is destroyed outright. In either case, those are the points to tag on the scoring system. Since the damage/destroyed response can only occur once, your score should only increment once.

    (\___/) (\___/) (\___/) (\___/) (\___/) (\___/) (\___/)
    (='.'=) (='.'=) (='.'=) (='.'=) (='.'=) (='.'=) (='.'=)
    (")_(") (")_(") (")_(") (")_(") (")_(") (")_(") (")_(")


    This is bunny and friends. He is fed up waiting for everyone to help him out, and decided to help himself instead!

  4. #4
    Banhammer in peace PeterB kalniel's Avatar
    Join Date
    Aug 2005
    Posts
    31,023
    Thanks
    1,870
    Thanked
    3,381 times in 2,718 posts
    • kalniel's system
      • Motherboard:
      • Gigabyte Z390 Aorus Ultra
      • CPU:
      • Intel i9 9900k
      • Memory:
      • 32GB DDR4 3200 CL16
      • Storage:
      • 1TB Samsung 970Evo+ NVMe
      • Graphics card(s):
      • nVidia GTX 1060 6GB
      • PSU:
      • Seasonic 600W
      • Case:
      • Cooler Master HAF 912
      • Operating System:
      • Win 10 Pro x64
      • Monitor(s):
      • Dell S2721DGF
      • Internet:
      • rubbish

    Re: C# OpenGL game. Help on incrementing a score..

    Quote Originally Posted by Lucio View Post
    The flaw to kalniel's pseudo-code is it assumes only one bullet will be in play at any one time.
    Just like early space invaders

    But it was just an example. There are other other conditions you could check like damage/destroyed, or start being fancy and assigning an ID from a pool of IDs equal to the number of bullets you can have in play at a time to each bullet such that each bullet can only score once.

    Or you could speed up your response so that in the same cycle that a bullet hit is detected the bullet is removed, and/or the invader object is removed and relaced with a non-interactive dying animation etc.

    Or take your hit calculation out of the display stuff.

  5. #5
    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: C# OpenGL game. Help on incrementing a score..

    Cheers guys will have another play about with it. I will only be shooting one bullet at a time, just like the original.

    The bullet travels through the enemy at the moment and once that is detected I will be running another method to set the score, reset the start positions etc. I think where I'm going wrong is the bullet keeps travelling through the enemy so keeps on incrementing the score. If I make the bullet disappear as soon as it detects the collision then hopefully it should only increment once... so I'll take your ideas into account and have a play about with it and let you know how I get on

    Cheers!

    Edit: Yep, sorted already.. obviously was at it too long yesterday and got my mind all confuddled.
    Code:
            static public void ResetPlayers()
            {
                bulletY = 0;
                bulletShot = false;
                playerScore++;
            }
    This is just very basic sample code, not looking for criticism
    Last edited by XA04; 17-11-2009 at 06:26 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 22
    Last Post: 07-11-2005, 10:16 AM
  2. Chronicles of Riddick PC
    By Ferral in forum Reader Reviews
    Replies: 32
    Last Post: 15-06-2005, 11:30 PM
  3. Deer Hunter 2005 Season (Atari PC Game)
    By Zak33 in forum Reader Reviews
    Replies: 15
    Last Post: 22-04-2005, 12:06 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
  •