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

0 Members and 1 Guest are viewing this topic.

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Asteroids-type Space Game
« on: June 19, 2018, 09: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.
* StarBlast_2018-6-19.zip (Filesize: 2.56 MB, Downloads: 301)
« Last Edit: June 19, 2018, 10:00:28 am by SirCrow »
I may not always finish what I've started....

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Asteroids-type Space Game
« Reply #1 on: June 19, 2018, 11:23:55 am »
Good work, SirCrow! The parallax effect is amazing!
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

FellippeHeitor

  • Guest
Re: Asteroids-type Space Game
« Reply #2 on: June 19, 2018, 11:49:03 am »
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: QB64: [Select]
  1.         K$ = INKEY$: IF INSTR("abcdefghijklmnopqrstuvwxyz", K$) THEN K$ = UCASE$(K$)
  2.  
  3.         IF _KEYDOWN(19200) THEN GOTO TurnLeft
  4.         IF _KEYDOWN(19712) THEN GOTO TurnRight
  5.         IF _KEYDOWN(18432) THEN GOTO Accelerate
  6.         IF _KEYDOWN(20480) THEN GOTO SlowDown
  7.  
  8.         SELECT CASE K$ '= = = = = = = = = = = = = = = = =  W H A T   K E Y  ?  = = = = = = = = = = = = = = = = = = =
  9.  
  10.             'Ship's Orientation...
  11.  
  12.             CASE "6"
  13.                 TurnLeft:
  14.                 Angle = Angle - 5: IF Angle < 5 THEN Angle = 360 'Anti-Clockwise
  15.  
  16.             CASE "4"
  17.                 TurnRight:
  18.                 Angle = Angle + 5: IF Angle > 360 THEN Angle = 5 'Clockwise
  19.  
  20.                 'CHR$(0) + CHR$(71)         [Home]               "G"
  21.                 'CHR$(0) + CHR$(72)         [Up Arrow]           "H"
  22.                 'CHR$(0) + CHR$(73)         [Page Up]            "I"
  23.                 'CHR$(0) + CHR$(75)         [Left Arrow]         "K"
  24.                 'CHR$(0) + CHR$(76)         [5 on NumPad]        "L" (NumLock off in QB64)
  25.                 'CHR$(0) + CHR$(77)         [Right Arrow]        "M"
  26.                 'CHR$(0) + CHR$(79)         [End]                "O"
  27.                 'CHR$(0) + CHR$(80)         [Down Arrow]         "P"
  28.                 'CHR$(0) + CHR$(81)         [Page Down]          "Q"
  29.                 'CHR$(0) + CHR$(82)         [Insert]             "R"
  30.                 'CHR$(0) + CHR$(83)         [Delete]             "S"
  31.  
  32.                 '(Jump (Ctrl-End) to BOTTOM for full version of list above.)
  33.  
  34.             CASE "8" 'Ship Accelerates
  35.                 Accelerate:
  36.                 IF Ang = Last.Ang THEN IF ABS(Step_X) = MaxSpeed OR ABS(Step_Y) = MaxSpeed GOTO Skip.Speed
  37.                 Last.Ang = Ang '* * * * WHERE to put this? * * * *
  38.  
  39.                 Inc = ABS(Inc): CALL Ship_Speed 'Accelerate
  40.                 'Above: Restore Inc to + in case MOUSE wheel has put Ship in reverse
  41.                 Skip.Speed:
  42.  
  43.             CASE "2" 'Ship Slows or Stops
  44.                 SlowDown:
  45.                 IF Step_X <> 0 OR Step_Y <> 0 THEN CALL Ship_Slow
  46.  
  47.             CASE "5", CHR$(0) + "L", CHR$(0) + "": Angle = 360 'Point Ship straight UP  (5, Ctrl-UP)
  48.  
  49.             CASE CHR$(0) + "s": Angle = 90 ' Point Ship LEFT   (Ctrl + Arrow)
  50.             CASE CHR$(0) + "t": Angle = 270 'Point Ship RIGHT
  51.             CASE CHR$(0) + "‘": Angle = 180 'Point Ship DOWN
  52.  
  53.             CASE "7": Angle = 45 'Point Ship UP-LEFT  (NumPad Corners)
  54.             CASE "9": Angle = 315 'UP-RIGHT
  55.             CASE "1": Angle = 135 'DOWN-LEFT
  56.             CASE "3": Angle = 225 'DOWN-RIGHT
  57.  
  58.             CASE CHR$(32), "X", "C": IF TIMER - LastProj > PRate THEN CALL Fire_Laser(PCnt, PX(), PY(), Dist()) 'Fire a LaserBall (but not too rapidly)
  59.  
  60.             CASE CHR$(0) + "?", "S", "D", "F", "G" 'F5 = Proximity Bomb   * * * *  Ctrl + "?" / CHR$(63)
  61.  
  62.                 'IF Energy  = 100 AND Shield.Up  = 5 THEN  * * * * THIS line or below? * * * *
  63.                 IF Energy >= 80 AND Shield.Up > 3 THEN
  64.                     CALL Check_Proximity
  65.  
  66.                     IF Objects.Hit THEN
  67.                         Energy = Energy - 10: FRad = ObRad + 20 'Initial size of Flash
  68.                         PB.Bonus = Objects.Hit * 100 * Objects.Hit:: Score = Score + PB.Bonus
  69.                     END IF
  70.                 END IF
  71.  
  72.             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?
  73.  
  74.             CASE CHR$(19): SWAP Snd, NoSnd: SOUND 222, 3: IF Snd THEN SOUND 333, 1 ELSE SOUND 111, 1
  75.             CASE CHR$(27): SYSTEM
  76.  
  77.         END SELECT 'What Key?  = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: Asteroids-type Space Game
« Reply #3 on: June 19, 2018, 12: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, 12:18:00 pm by SirCrow »
I may not always finish what I've started....

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Asteroids-type Space Game
« Reply #4 on: June 19, 2018, 12:22:37 pm »
Nice work, SirCrow! I will not disturb...

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: Asteroids-type Space Game
« Reply #5 on: June 19, 2018, 12:27:57 pm »
Nice work, SirCrow! I will not disturb...

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

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: Asteroids-type Space Game
« Reply #6 on: June 19, 2018, 12: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....

FellippeHeitor

  • Guest
Re: Asteroids-type Space Game
« Reply #7 on: June 19, 2018, 12: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, 01:01:47 pm by FellippeHeitor »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Asteroids-type Space Game
« Reply #8 on: June 20, 2018, 09: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 :-)
Programming isn't difficult, only it's  consuming time and coffee

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: Asteroids-type Space Game
« Reply #9 on: June 20, 2018, 06: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, 07:33:25 pm by SirCrow »
I may not always finish what I've started....

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: Asteroids-type Space Game
« Reply #10 on: June 20, 2018, 06: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....