Author Topic: Asteroids-type Space Game  (Read 258 times)

Asteroids-type Space Game
« on: June 19, 2018, 10:41:04 AM »
Firstly, I chose the name StarBlast before I knew about any existing game by the same name.  So there.
Anyway, as the title implies, my game is based on the classic arcade game Asteroids.  As in that game, your objective is to zap a bunch of free-floating objects (currently just pretty circles) until you've cleared the area of them.  Then comes the Super Orb!  And it's protected by a pesky Bug!  Oh, yeah!

This game is a work in progress, and I have lots of things in mind that I will be adding soon, not the least of which is actual SPACE ROCKS to zap, rather than just a lot of concentric circles, pretty as they may be.

Read the .DOC file for help with controls and such.  Hope you'll enjoy!

NOTE: Among the things that crash this prog. are any references to .mp3 files.  So my sound options were limited.  I'm using Linux/Ubuntu, and I don't know how to correct the .mp3 problem.
« Last Edit: June 19, 2018, 11:00:28 AM by SirCrow »
I may not always finish what I've started....

Offline Ashish

  • The joy of coding is endless.
Re: Asteroids-type Space Game
« Reply #1 on: June 19, 2018, 12:23:55 PM »
Good work, SirCrow! The parallax effect is amazing!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


aKFrameWork - http://bit.ly/aKFrameWork
Menu System - http://bit.ly/guiMenuBar
p5.js in QB64 - http://bit.ly/p5jsbas

@KingOfCoders

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Asteroids-type Space Game
« Reply #2 on: June 19, 2018, 12:49:03 PM »
Looking really good, SirCrow!

If I'm allowed one suggestion: please consider using _KEYDOWN for arrow movement. Using INKEY$ doesn't allow natural movement as a key only starts repeating in the buffer after a few milliseconds, which causes the ship to bump in the desired direction once and only then actually start accelerating or rotating.

It doesn't have to be like this, but here's my suggested change, for natural movement (may feel a bit too fast since you're used to the current approach):
Code: [Select]
        K$ = INKEY$: IF INSTR("abcdefghijklmnopqrstuvwxyz", K$) THEN K$ = UCASE$(K$)

        IF _KEYDOWN(19200) THEN GOTO TurnLeft
        IF _KEYDOWN(19712) THEN GOTO TurnRight
        IF _KEYDOWN(18432) THEN GOTO Accelerate
        IF _KEYDOWN(20480) THEN GOTO SlowDown

        SELECT CASE K$ '= = = = = = = = = = = = = = = = =  W H A T   K E Y  ?  = = = = = = = = = = = = = = = = = = =

            'Ship's Orientation...

            CASE "6"
                TurnLeft:
                Angle = Angle - 5: IF Angle < 5 THEN Angle = 360 'Anti-Clockwise

            CASE "4"
                TurnRight:
                Angle = Angle + 5: IF Angle > 360 THEN Angle = 5 'Clockwise

                'CHR$(0) + CHR$(71)         [Home]               "G"
                'CHR$(0) + CHR$(72)         [Up Arrow]           "H"
                'CHR$(0) + CHR$(73)         [Page Up]            "I"
                'CHR$(0) + CHR$(75)         [Left Arrow]         "K"
                'CHR$(0) + CHR$(76)         [5 on NumPad]        "L" (NumLock off in QB64)
                'CHR$(0) + CHR$(77)         [Right Arrow]        "M"
                'CHR$(0) + CHR$(79)         [End]                "O"
                'CHR$(0) + CHR$(80)         [Down Arrow]         "P"
                'CHR$(0) + CHR$(81)         [Page Down]          "Q"
                'CHR$(0) + CHR$(82)         [Insert]             "R"
                'CHR$(0) + CHR$(83)         [Delete]             "S"

                '(Jump (Ctrl-End) to BOTTOM for full version of list above.)

            CASE "8" 'Ship Accelerates
                Accelerate:
                IF Ang = Last.Ang THEN IF ABS(Step_X) = MaxSpeed OR ABS(Step_Y) = MaxSpeed GOTO Skip.Speed
                Last.Ang = Ang '* * * * WHERE to put this? * * * *

                Inc = ABS(Inc): CALL Ship_Speed 'Accelerate
                'Above: Restore Inc to + in case MOUSE wheel has put Ship in reverse
                Skip.Speed:

            CASE "2" 'Ship Slows or Stops
                SlowDown:
                IF Step_X <> 0 OR Step_Y <> 0 THEN CALL Ship_Slow

            CASE "5", CHR$(0) + "L", CHR$(0) + "": Angle = 360 'Point Ship straight UP  (5, Ctrl-UP)

            CASE CHR$(0) + "s": Angle = 90 ' Point Ship LEFT   (Ctrl + Arrow)
            CASE CHR$(0) + "t": Angle = 270 'Point Ship RIGHT
            CASE CHR$(0) + "‘": Angle = 180 'Point Ship DOWN

            CASE "7": Angle = 45 'Point Ship UP-LEFT  (NumPad Corners)
            CASE "9": Angle = 315 'UP-RIGHT
            CASE "1": Angle = 135 'DOWN-LEFT
            CASE "3": Angle = 225 'DOWN-RIGHT

            CASE CHR$(32), "X", "C": IF TIMER - LastProj > PRate THEN CALL Fire_Laser(PCnt, PX(), PY(), Dist()) 'Fire a LaserBall (but not too rapidly)

            CASE CHR$(0) + "?", "S", "D", "F", "G" 'F5 = Proximity Bomb   * * * *  Ctrl + "?" / CHR$(63)

                'IF Energy  = 100 AND Shield.Up  = 5 THEN  * * * * THIS line or below? * * * *
                IF Energy >= 80 AND Shield.Up > 3 THEN
                    CALL Check_Proximity

                    IF Objects.Hit THEN
                        Energy = Energy - 10: FRad = ObRad + 20 'Initial size of Flash
                        PB.Bonus = Objects.Hit * 100 * Objects.Hit:: Score = Score + PB.Bonus
                    END IF
                END IF

            CASE CHR$(13): IF NOT Super.Obj THEN CALL Jump_Ship(XX, YY, Ship.Vanished) ' Ship.Vanished = -1:: SOUND 3333, .5 '* * * * DELETE Vanished or not?

            CASE CHR$(19): SWAP Snd, NoSnd: SOUND 222, 3: IF Snd THEN SOUND 333, 1 ELSE SOUND 111, 1
            CASE CHR$(27): SYSTEM

        END SELECT 'What Key?  = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Re: Asteroids-type Space Game
« Reply #3 on: June 19, 2018, 01:12:49 PM »
To be honest, I've been afraid of, or at least intimidated by _KEYDOWN. I look at those numbers  (e.g. 19712) and have no idea what that's all about.  But yes, I would like it to work better, so I think I'll give it a go.  Thanks, Fellippe!

One more thing:  I've been using the mouse to move and turn the ship;  I like it because then I can turn and fire simultaneously.  Would that be possible with just the keyboard?
« Last Edit: June 19, 2018, 01:18:00 PM by SirCrow »
I may not always finish what I've started....

Offline Petr

  • I am instructed.
Re: Asteroids-type Space Game
« Reply #4 on: June 19, 2018, 01:22:37 PM »
Nice work, SirCrow! I will not disturb...

Re: Asteroids-type Space Game
« Reply #5 on: June 19, 2018, 01:27:57 PM »
Nice work, SirCrow! I will not disturb...

Thanks, I really appreciate it. 
I may not always finish what I've started....

Re: Asteroids-type Space Game
« Reply #6 on: June 19, 2018, 01:29:22 PM »
Good work, SirCrow! The parallax effect is amazing!

I'll take that as a compliment. ;)
Really, I am very pleased that you liked it so much.  I'm glad I was able to make the stars move independently of the nebular clouds.  Even for me, it was pretty simple.  It's not exactly realistic, but somehow, I don't care.
I may not always finish what I've started....

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: Asteroids-type Space Game
« Reply #7 on: June 19, 2018, 01:44:53 PM »
To be honest, I've been afraid of, or at least intimidated by _KEYDOWN. I look at those numbers  (e.g. 19712) and have no idea what that's all about.  But yes, I would like it to work better, so I think I'll give it a go.  Thanks, Fellippe!

One more thing:  I've been using the mouse to move and turn the ship;  I like it because then I can turn and fire simultaneously.  Would that be possible with just the keyboard?

If you don’t want to use the codes directly, use the constants. Both of which can be found in the wiki page for KEYDOWN: http://www.qb64.org/wiki/KEYDOWN (the codes are the same for _KEYHIT btw).

Your second question is also answered with: _KEYDOWN. You can check the state of multiple keys at once.
« Last Edit: June 19, 2018, 02:01:47 PM by FellippeHeitor »

Re: Asteroids-type Space Game
« Reply #8 on: June 20, 2018, 10:04:23 AM »
Hi SirCrow

I can say "Very Funny"
today version are keyboard controls  adjourned to the _KEYDOWN?

I'll look for next evolutions :-)

Re: Asteroids-type Space Game
« Reply #9 on: June 20, 2018, 07:10:58 PM »
Your second question is also answered with: _KEYDOWN. You can check the state of multiple keys at once.

Thanks, that's good to know.  I'd love to have it recognise multiple keys at once.  Frankly, I get overwhelmed by all the things I never learned about BASIC, especially QB64.  And having limited math skills certainly doesn't help.  Sine, cosine, etc....what is all that?!  And I find it difficult to concentrate these days.  Truly amazing, then, that I can even make something like my Pac-Man or Asteroids game.  It's good to have forum members to help us.
« Last Edit: June 20, 2018, 08:33:25 PM by SirCrow »
I may not always finish what I've started....

Re: Asteroids-type Space Game
« Reply #10 on: June 20, 2018, 07:15:06 PM »
Hi SirCrow

I can say "Very Funny"
today version are keyboard controls  adjourned to the _KEYDOWN?

I'll look for next evolutions :-)

Thank you for your interest.  In the near future, in addition to keyboard and mouse right now, I hope I will get the game to work with a joystick.  If I can, I suspect that'll become my fave way to play it.  Although, using multiple simultaneous keys would be a big help, too.
I may not always finish what I've started....