Author Topic: Little space background for games  (Read 5467 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Little space background for games
« on: October 01, 2021, 08:21:54 pm »
Sharing a small way to make a space looking background for simple games.  Shows Stars and a little plasma space gas floating around.  Not much really, just thought I'd post something tonight.

- Dav

Code: QB64: [Select]
  1.  
  2. SCREEN _NEWIMAGE(640, 640, 32)
  3.  
  4.  
  5. FOR x = 1 TO 100000
  6.     PSET (RND * 640, RND * 640), _RGBA(0, 0, RND * 255, RND * 255)
  7.  
  8. 'faded boxes
  9. FOR i = 1 TO 5000
  10.     x = RND * 640: y = RND * 640
  11.     LINE (x, y)-(x + RND * 100, y + RND * 50), _RGBA(0, 0, RND * 128, RND * 25), BF
  12.  
  13. 'add a few stars
  14. FOR i = 1 TO 1000
  15.     x = RND * 640: y = RND * 640
  16.     LINE (x, y)-(x + RND * 3, y + RND * 3), _RGBA(192, 192, 255, RND * 150), BF
  17.  
  18.  
  19.  
  20.     '=== add space plasma =========
  21.     t = TIMER
  22.     FOR x = 0 TO _WIDTH STEP 3
  23.         FOR y = 0 TO _HEIGHT STEP 3
  24.             b = SIN(x / (_WIDTH / 2) + t + y / (_HEIGHT / 2))
  25.             b = b * (SIN(1.1 * t) * (_HEIGHT / 2) - y + (_HEIGHT / 2))
  26.             PSET (x, y), _RGBA(b / 3, 0, b, RND * 25)
  27.         NEXT: t = t + .04
  28.     NEXT
  29.     '===============================
  30.  
  31.     _DISPLAY
  32.     _LIMIT 15
  33.  
  34.  
  35.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Little space background for games
« Reply #1 on: October 02, 2021, 01:24:13 am »
Nice foggy night sky effect. Let's see, how could I possibly use this. Oh, I've got it!

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 700, 32)
  2. _SCREENMOVE 300, 20
  3. swt& = _NEWIMAGE(320, 512, 32)
  4. _DEST swt&
  5.  
  6.  
  7. FOR x = 1 TO 100000
  8.     PSET (RND * 640, RND * 640), _RGBA(0, 0, RND * 255, RND * 255)
  9.  
  10. 'faded boxes
  11. FOR i = 1 TO 5000
  12.     x = RND * 640: y = RND * 640
  13.     LINE (x, y)-(x + RND * 100, y + RND * 50), _RGBA(0, 0, RND * 128, RND * 25), BF
  14.  
  15. 'add a few stars
  16. FOR i = 1 TO 1000
  17.     x = RND * 640: y = RND * 640
  18.     LINE (x, y)-(x + RND * 3, y + RND * 3), _RGBA(192, 192, 255, RND * 150), BF
  19.  
  20. COLOR _RGBA32(0, 180, 0, 255)
  21. nl$ = CHR$(10)
  22. sw$ = "     Oh the bitch... Oh the bitch...    " + nl$
  23. sw$ = sw$ + nl$
  24. sw$ = sw$ + "  Oh the bitch is back. He took Dav's  " + nl$
  25. sw$ = sw$ + nl$
  26. sw$ = sw$ + "  and Mark's code and created a hack.  " + nl$
  27. sw$ = sw$ + nl$
  28. sw$ = sw$ + "  I'm a bitch I'm a bitch 'cause I'm   " + nl$
  29. sw$ = sw$ + nl$
  30. sw$ = sw$ + " better than you. It's the way that I  " + nl$
  31. sw$ = sw$ + nl$
  32. sw$ = sw$ + " code and the way I WOOOHOOO! da da da."
  33. LOCATE 20, 1
  34. PRINT sw$
  35.  
  36.  
  37. cx = _WIDTH / 2
  38. power = 1024 'TO 1 STEP -1
  39. x = (_HEIGHT - 20) ^ (1 / power)
  40. dy = 1 '256 pixel height / 50 blocks across
  41. FOR y = -840 TO -270
  42.     CLS
  43.     FOR i = 0 TO power - 1
  44.         _PUTIMAGE (cx - .75 * x ^ i, 10 + x ^ i)-(cx + .75 * x ^ i, 10 + x ^ (i + 1)), swt&, 0, (0, y + dy * i)-(319, y + dy * (i + 1))
  45.     NEXT
  46.     _DISPLAY
  47.     _LIMIT 15
  48. COLOR 0, 0
  49.  
  50. SUB TriCopy
  51.     FOR i%% = 0 TO 100
  52.         _MAPTRIANGLE (0 + i%% * 2, 0)-(0 + i%% * 2, 400)-(1 + i%% * 2, 400)TO(500, 0)-(400 + i%% * 2, 400)-(401 + i%% * 2, 400)
  53.     NEXT i%%
  54.  

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Little space background for games
« Reply #2 on: October 02, 2021, 01:29:33 am »
🤣👠

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: Little space background for games
« Reply #3 on: October 02, 2021, 05:30:05 am »
@Pete  Tee-hee!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Little space background for games
« Reply #4 on: October 02, 2021, 07:59:31 am »
Hey @Pete, I can see what that should do, but for some reason it won't run on my PC. As soon as it starts it crashes everytime.  I don't see a reason for it in the code.  I guess Marvin did it?

- Dav

 
spacecrash.jpg

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Little space background for games
« Reply #5 on: October 02, 2021, 08:03:17 am »
Ok, it appears my PC doesn't like line #49:

Code: QB64: [Select]
  1.  _PUTIMAGE (cx - .75 * x ^ i, 10 + x ^ i)-(cx + .75 * x ^ i, 10 + x ^ (i + 1)), swt&, 0, (0, y + dy * i)-(319, y + dy * (i + 1))

Don't feel bad, my PC doesn't like me sometimes either.  I'll tinker around later today with it when I get back picking apples.

- Dav

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Little space background for games
« Reply #6 on: October 02, 2021, 08:28:21 am »
Dav,

Cool background. Nicely done!

J
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Little space background for games
« Reply #7 on: October 02, 2021, 08:37:11 am »
Pete,

Did not work for me either... But I did fix it... for me anyway... Problem with line #49. My machine did not like ".75"... Changed it to "0.75" and it ran like a charm... Fascinating... Seems to be a parody of an Elton John song... Not a fan... The effect is quite good. Nicely done!

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Little space background for games
« Reply #8 on: October 02, 2021, 09:36:14 am »
Modified
Code: QB64: [Select]
  1. Screen _NewImage(800, 700, 32)
  2. _ScreenMove 300, 20
  3.  
  4. swt& = _NewImage(320, 500, 32)
  5. _Dest swt&
  6. Color _RGB32(0, 180, 0), 0
  7. nl$ = Chr$(10)
  8. sw$ = "     Oh the bitch... Oh the bitch...    " + nl$
  9. sw$ = sw$ + nl$
  10. sw$ = sw$ + "  Oh the bitch is back. He took Dav's  " + nl$
  11. sw$ = sw$ + nl$
  12. sw$ = sw$ + "  and Mark's code and created a hack.  " + nl$
  13. sw$ = sw$ + nl$
  14. sw$ = sw$ + "  I'm a bitch I'm a bitch 'cause I'm   " + nl$
  15. sw$ = sw$ + nl$
  16. sw$ = sw$ + " better than you. It's the way that I  " + nl$
  17. sw$ = sw$ + nl$
  18. sw$ = sw$ + " code and the way I WOOOHOOO! da da da."
  19. Locate 20, 1
  20. Print sw$
  21.  
  22. bg& = _NewImage(800, 700, 32)
  23. _Dest bg&
  24.  
  25. For x = 1 To 100000
  26.     PSet (Rnd * 800, Rnd * 700), _RGBA(0, 0, Rnd * 255, Rnd * 255)
  27.  
  28. 'faded boxes
  29. For i = 1 To 5000
  30.     x = Rnd * 800: y = Rnd * 700
  31.     Line (x, y)-(x + Rnd * 100, y + Rnd * 50), _RGBA(0, 0, Rnd * 128, Rnd * 25), BF
  32.  
  33. 'add a few stars
  34. For i = 1 To 1000
  35.     x = Rnd * 800: y = Rnd * 700
  36.     Line (x, y)-(x + Rnd * 3, y + Rnd * 3), _RGBA(192, 192, 255, Rnd * 150), BF
  37.  
  38.  
  39. cx = _Width / 2
  40. power = 1024 'TO 1 STEP -1
  41. x = (_Height - 20) ^ (1 / power)
  42. dy = 1 '256 pixel height / 50 blocks across
  43. t = 1
  44. For y = -840 To -270
  45.     Cls
  46.     _PutImage , bg&, 0
  47.  
  48.  
  49.     '=== add space plasma =========
  50.  
  51.     For xx = 0 To _Width Step 3
  52.         For yy = 0 To _Height Step 3
  53.             b = Sin(xx / (_Width / 2) + t + yy / (_Height / 2))
  54.             b = b * (Sin(1.1 * t) * (_Height / 2) - yy + (_Height / 2))
  55.             PSet (xx, yy), _RGB32(b / 3, 0, b, Rnd * 85 + 30)
  56.         Next: t = t + .004
  57.     Next
  58.     '===============================
  59.  
  60.  
  61.  
  62.  
  63.     For i = 0 To power - 1
  64.         _PutImage (cx - 0.75 * x ^ i, 10 + x ^ i)-(cx + 0.75 * x ^ i, 10 + x ^ (i + 1)), swt&, 0, (0, y + dy * i)-(319, y + dy * (i + 1))
  65.     Next
  66.     _Display
  67.     _Limit 15
  68. Color 0, 0
  69.  
  70. Sub TriCopy
  71.     For i%% = 0 To 100
  72.         _MapTriangle (0 + i%% * 2, 0)-(0 + i%% * 2, 400)-(1 + i%% * 2, 400)To(500, 0)-(400 + i%% * 2, 400)-(401 + i%% * 2, 400)
  73.     Next i%%
  74.  
  75.  
  76.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Little space background for games
« Reply #9 on: October 02, 2021, 10:17:31 am »
Cool...
Logic is the beginning of wisdom.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Little space background for games
« Reply #10 on: October 02, 2021, 12:24:36 pm »
Pete,

Did not work for me either... But I did fix it... for me anyway... Problem with line #49. My machine did not like ".75"... Changed it to "0.75" and it ran like a charm... Fascinating... Seems to be a parody of an Elton John song... Not a fan... The effect is quite good. Nicely done!

J

@johnno56 The Star Wars lettering effect is Mark's (bplus's) code, and I may have used an earlier release of it, which he probably modified later. I then merged Dav's and Mark's code, together, with just a couple of minor modifications, and substituted with my lyrics. You'd have to been in another thread to get the inside joke about the parody. Anyway, I had a couple of crashes when I was working with it, too, but I couldn't pin them down. By the time I was finished and posted, it ran flawlessly, several times on my Win-10 64-bit laptop. I read some fixes here, your change .75 to 0.75 one, and I see Mark also posted an update, so maybe it is stable now.

I thought when Mark created this effect I made some Star Trek parody of it, but I can't seem to find it on the forum. Maybe I posted it on QBF and saved it on another computer. Honestly, Mark's Star Wars finished version was amazing. It looked every bit as good as the movie intro, without having to suffer through the movie. Can you tell I'm a Trekkie?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Little space background for games
« Reply #11 on: October 02, 2021, 01:08:56 pm »
Modified

Mark, that one crashes on my system near the end. It almost makes it to the end of the for/next loop, and then locks up while displaying the windows spinning lag indicator, and then crashes, meaning it just vanishes from the screen.

WOW though. That's what I was envisioning, but I couldn't figure out the transparent lettering background or how to get Dav's code to take up the whole screen. Since in comedy, timing is everything, I didn't have the luxury of taking a crash course in graphics last night. Very cool to see what I would have wanted was possible!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Little space background for games
« Reply #12 on: October 02, 2021, 04:24:31 pm »
Wish I could see it run - crashes at the beginning for me still.  I'm trying to get it going...

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Little space background for games
« Reply #13 on: October 02, 2021, 04:51:06 pm »
Mark, that one crashes on my system near the end. It almost makes it to the end of the for/next loop, and then locks up while displaying the windows spinning lag indicator, and then crashes, meaning it just vanishes from the screen.

WOW though. That's what I was envisioning, but I couldn't figure out the transparent lettering background or how to get Dav's code to take up the whole screen. Since in comedy, timing is everything, I didn't have the luxury of taking a crash course in graphics last night. Very cool to see what I would have wanted was possible!

Pete

Ah I see, just at the end, fixed?: (probably not for Dav)

Code: QB64: [Select]
  1. Screen _NewImage(800, 700, 32)
  2. _ScreenMove 300, 20
  3.  
  4. swt& = _NewImage(320, 700, 32)
  5. _Dest swt&
  6. Color _RGB32(0, 180, 0), 0
  7. nl$ = Chr$(10)
  8. sw$ = "     Oh the bitch... Oh the bitch...    " + nl$
  9. sw$ = sw$ + nl$
  10. sw$ = sw$ + "  Oh the bitch is back. He took Dav's  " + nl$
  11. sw$ = sw$ + nl$
  12. sw$ = sw$ + "  and Mark's code and created a hack.  " + nl$
  13. sw$ = sw$ + nl$
  14. sw$ = sw$ + "  I'm a bitch I'm a bitch 'cause I'm   " + nl$
  15. sw$ = sw$ + nl$
  16. sw$ = sw$ + " better than you. It's the way that I  " + nl$
  17. sw$ = sw$ + nl$
  18. sw$ = sw$ + " code and the way I WOOOHOOO! da da da."
  19. Locate 20, 1
  20. Print sw$
  21.  
  22. bg& = _NewImage(800, 700, 32)
  23. _Dest bg&
  24.  
  25. For x = 1 To 100000
  26.     PSet (Rnd * 800, Rnd * 700), _RGBA(0, 0, Rnd * 255, Rnd * 255)
  27.  
  28. 'faded boxes
  29. For i = 1 To 5000
  30.     x = Rnd * 800: y = Rnd * 700
  31.     Line (x, y)-(x + Rnd * 100, y + Rnd * 50), _RGBA(0, 0, Rnd * 128, Rnd * 25), BF
  32.  
  33. 'add a few stars
  34. For i = 1 To 1000
  35.     x = Rnd * 800: y = Rnd * 700
  36.     Line (x, y)-(x + Rnd * 3, y + Rnd * 3), _RGBA(192, 192, 255, Rnd * 150), BF
  37.  
  38.  
  39. cx = _Width / 2
  40. power = 1024 'TO 1 STEP -1
  41. x = (_Height - 20) ^ (1 / power)
  42. dy = 1 '256 pixel height / 50 blocks across
  43. t = 1
  44. For y = -840 To -270
  45.     Cls
  46.     _PutImage , bg&, 0
  47.  
  48.  
  49.     '=== add space plasma =========
  50.  
  51.     For xx = 0 To _Width Step 3
  52.         For yy = 0 To _Height Step 3
  53.             b = Sin(xx / (_Width / 2) + t + yy / (_Height / 2))
  54.             b = b * (Sin(1.1 * t) * (_Height / 2) - yy + (_Height / 2))
  55.             PSet (xx, yy), _RGB32(b / 3, 0, b, Rnd * 85 + 30)
  56.         Next: t = t + .004
  57.     Next
  58.     '===============================
  59.  
  60.  
  61.  
  62.  
  63.     For i = 0 To power - 1
  64.         _PutImage (cx - 0.75 * x ^ i, 10 + x ^ i)-(cx + 0.75 * x ^ i, 10 + x ^ (i + 1)), swt&, 0, (0, y + dy * i)-(319, y + dy * (i + 1))
  65.     Next
  66.     _Display
  67.     _Limit 15
  68. Color 0, 0
  69.  
  70. Sub TriCopy
  71.     For i%% = 0 To 100
  72.         _MapTriangle (0 + i%% * 2, 0)-(0 + i%% * 2, 400)-(1 + i%% * 2, 400)To(500, 0)-(400 + i%% * 2, 400)-(401 + i%% * 2, 400)
  73.     Next i%%
  74.  
  75.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Little space background for games
« Reply #14 on: October 02, 2021, 04:53:41 pm »
The blackout at the end is crappy too, should just Sleep after _Delay but not going to modify.