Author Topic: StarBlast Game: Shadow Not Translucent  (Read 6132 times)

0 Members and 1 Guest are viewing this topic.

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
StarBlast Game: Shadow Not Translucent
« on: August 07, 2018, 05:17:53 pm »
I still haven't been able to figure out why my SHIP's shadow is just black and not at all transparent.  All the asteroids have perfect shadows, but not the ship.  Please examine the source and find the image handle Ship_Shade& in lines such as _SETALPHA 120, , Ship_Shade&.  The shadow is drawn onto that 49 x 49 image, which is then placed using _PUTIMAGE.   Alt-S can be used to switch between my orig. version of the ship's shadow and the one in Ship_Shade& -- make sure it's the fully black, unchanging shadow that's currently active (a descending tone should indicate the correct mode).  Oh, and make sure to start the game using F8 on the intro screen.

I'd like to fix the shadow issue and upload the latest version of the game;  but for now, please use the last uploaded version:
https://www.qb64.org/forum/index.php?action=dlattach;topic=347.0;attach=830

If you have the time, please help if you can.  Thank you.
I may not always finish what I've started....

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: StarBlast Game: Shadow Not Translucent
« Reply #1 on: August 07, 2018, 07:45:18 pm »
Might not be easy to fix. Normally I would suggest using a rotate procedure. That would probably be easier than rotating a 'drawn' image. I do not know how to rotate images using QB64. In the meantime, may I suggest, a lighter shadow? Black tends to make it 'stand out'. Perhaps anywhere between _RGB32(64,64,64) and _RGB32(192,192,192)? Just a thought...

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: StarBlast Game: Shadow Not Translucent
« Reply #2 on: August 07, 2018, 08:35:53 pm »
I don't understand the problem. I run F8 from start and use Alt+S to toggle between a transparent shadow on surface and a solid black one. So it seems you can draw a transparent shadow, so???

Is this the sub code in question?
Code: QB64: [Select]
  1. SUB Ship_Shadow
  2.  
  3.     _DEST Ship_Shade& 'DRAW onto our small Ship Shadow BG image
  4.  
  5.     ShX = 24: ShY = 24
  6.  
  7.     PRESET (ShX, ShY) 'Place graphics cursor in centre of Shadow image ---------
  8.  
  9.     ShadClr& = _RGBA(0, 0, 0, 255) '_RGB(R - SD, G - SD, B - SD) 'Assign colour to Ship's shadow on Planet's surface
  10.  
  11.     CLS , _RGBA(255, 255, 255, 0)
  12.  
  13.     '@@@@@@@@@@@@@@@@@@@@@@@@@@@
  14.     DRAW "TA=" + VARPTR$(Angle) 'Set the angle based on Ship's Angle
  15.     '@@@@@@@@@@@@@@@@@@@@@@@@@@@
  16.  
  17.     PRESET (ShX, ShY) 'Set to draw Ship's SHADOW -------------------------------
  18.  
  19.     DRAW "C" + STR$(ShadClr&) 'Shadow Color                             Actual Ship size:
  20.  
  21.     DRAW "bU2 L3 H3 G14 D6 E3 R3 E3 R21" 'LEFT half (wing) of Shadow Ship  --  "BU3 L5 H4 G20 D9 E5 R5 E4 R29"
  22.  
  23.     PSET (ShX, ShY), _RGB(255, 255, 255) 'Must be diff. from ShadClr
  24.     DRAW "C" + STR$(ShadClr&) 'Back to Shadow color
  25.     DRAW "bU2 R3 E3 F14 D6 H3 L3 H3 " 'RIGHT half of Shadow (most of it)        "BU3 R5 E4 F20 D9 H5 L5 H4 "
  26.  
  27.     PAINT (ShX, ShY), ShadClr&, ShadClr&
  28.  
  29.     PRESET (ShX, ShY) 'Reset for Ship's Sphere ---------------------------------
  30.     DRAW "C" + STR$(ShadClr&) 'Back to Shadow color
  31.     'Draw a HINT of the Sphere, then reset for Engine bottom...
  32.     DRAW "bU3 bL2 R4  bL3 bU1 R2  bL4 bD14 " 'Merely a 4-pixel line & a 2-pixel line in lieu of CIRCLE
  33.     DRAW "R6 bD1 L6" 'Bare bottom of Engine
  34.  
  35.     _PUTIMAGE (Ship.X - 104, Ship.Y + 56), Ship_Shade&, Scr& '(80+24, 80-24) ...24 being about 1/2 of Ship_Shade image's width or height
  36.     'LINE (Ship.X - 104, Ship.Y + 104)-(Ship.X - 55, Ship.Y + 153), _RGB(255, 255, 255), B
  37.  
  38.     CLS: _DEST Scr&
  39.  
  40.  
  41.  
  42.  

This line does not make sense if you want transparent, yet when I try less than 255, I get light colored squares drawn.
ShadClr& = _RGBA(0, 0, 0, 255)

Does the Draw "C" command allow for ALPHA colors? The wiki says only _rgb().
« Last Edit: August 07, 2018, 08:42:18 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: StarBlast Game: Shadow Not Translucent
« Reply #3 on: August 07, 2018, 08:57:42 pm »
OK this has nice effect!

Code: QB64: [Select]
  1.  
  2. SUB Ship_Shadow
  3.  
  4.     _DEST Ship_Shade& 'DRAW onto our small Ship Shadow BG image
  5.  
  6.     ShX = 24: ShY = 24
  7.  
  8.     PRESET (ShX, ShY) 'Place graphics cursor in centre of Shadow image ---------
  9.  
  10.     ShadClr& = _RGBA(0, 0, 0, 255) '_RGB(R - SD, G - SD, B - SD) 'Assign colour to Ship's shadow on Planet's surface
  11.  
  12.     CLS , _RGBA(255, 255, 255, 0)
  13.  
  14.     '@@@@@@@@@@@@@@@@@@@@@@@@@@@
  15.     DRAW "TA=" + VARPTR$(Angle) 'Set the angle based on Ship's Angle
  16.     '@@@@@@@@@@@@@@@@@@@@@@@@@@@
  17.  
  18.     PRESET (ShX, ShY) 'Set to draw Ship's SHADOW -------------------------------
  19.  
  20.     DRAW "C" + STR$(ShadClr&) 'Shadow Color                             Actual Ship size:
  21.  
  22.     DRAW "bU2 L3 H3 G14 D6 E3 R3 E3 R21" 'LEFT half (wing) of Shadow Ship  --  "BU3 L5 H4 G20 D9 E5 R5 E4 R29"
  23.  
  24.     PSET (ShX, ShY), _RGB(255, 255, 255) 'Must be diff. from ShadClr
  25.     DRAW "C" + STR$(ShadClr&) 'Back to Shadow color
  26.     DRAW "bU2 R3 E3 F14 D6 H3 L3 H3 " 'RIGHT half of Shadow (most of it)        "BU3 R5 E4 F20 D9 H5 L5 H4 "
  27.  
  28.     PAINT (ShX, ShY), ShadClr&, ShadClr&
  29.  
  30.     PRESET (ShX, ShY) 'Reset for Ship's Sphere ---------------------------------
  31.     DRAW "C" + STR$(ShadClr&) 'Back to Shadow color
  32.     'Draw a HINT of the Sphere, then reset for Engine bottom...
  33.     DRAW "bU3 bL2 R4  bL3 bU1 R2  bL4 bD14 " 'Merely a 4-pixel line & a 2-pixel line in lieu of CIRCLE
  34.     DRAW "R6 bD1 L6" 'Bare bottom of Engine
  35.  
  36.     _SETALPHA 50, _RGB32(0, 0, 0) '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< this has nice effect!!!!!!!!
  37.  
  38.     _PUTIMAGE (Ship.X - 104, Ship.Y + 56), Ship_Shade&, Scr& '(80+24, 80-24) ...24 being about 1/2 of Ship_Shade image's width or height
  39.     'LINE (Ship.X - 104, Ship.Y + 104)-(Ship.X - 55, Ship.Y + 153), _RGB(255, 255, 255), B
  40.  
  41.     CLS: _DEST Scr&
  42.  
  43.  
  44.  
  45.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: StarBlast Game: Shadow Not Translucent
« Reply #4 on: August 07, 2018, 09:04:20 pm »
BTW those are really nice graphics, I hadn't seen the program for awhile, it's coming along nicely!

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: StarBlast Game: Shadow Not Translucent
« Reply #5 on: August 07, 2018, 09:13:36 pm »
BTW those are really nice graphics, I hadn't seen the program for awhile, it's coming along nicely!

I'm very glad you like it.  Hey, thanks!  You've solved it!  It simply hadn't occurred to me to put that there.
The only change I've made to your line is this, to match it with all the asteroids' shadows:

 _SETALPHA 120, _RGB32(0, 0, 0)

By the way, the transparent shadow you saw while using Alt-S is not quite as it appears.  It's really a solid shade that changes with the ground under or around it by sampling pixels with POINT(), and averaging values and stuff like that.  You can see that it's different from the shadows of the floating rocks.  It took some work to get it that way, and I like it, but I most wanted the ship to have the same shadow as the asteroids.  And now it does.  Thanks again!
I may not always finish what I've started....

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: StarBlast Game: Shadow Not Translucent
« Reply #6 on: August 07, 2018, 09:19:10 pm »
Might not be easy to fix. Normally I would suggest using a rotate procedure. That would probably be easier than rotating a 'drawn' image. I do not know how to rotate images using QB64. In the meantime, may I suggest, a lighter shadow? Black tends to make it 'stand out'. Perhaps anywhere between _RGB32(64,64,64) and _RGB32(192,192,192)? Just a thought...

Thanks, Johnno.  But it seems that the all-elusive solution has been found by bplus.  As I'd expected, something simple that I just didn't see.Anyway, I've added more cool features to the game and I hope to upload it soon.  And I think I'll have to employ those reduced images you've prepared for me.  Thanks.
J
I may not always finish what I've started....

FellippeHeitor

  • Guest
Re: StarBlast Game: Shadow Not Translucent
« Reply #7 on: August 07, 2018, 09:37:19 pm »
If you still need to rotate an image here's a routine (and helper routines) alongside a sample code showing usage to rotate any image by the provided amount of degrees: https://github.com/FellippeHeitor/Snippets/blob/master/rotateImage.bas

Code: QB64: [Select]
  1.  
  2. TYPE vertex
  3.     x AS SINGLE
  4.     y AS SINGLE
  5.  
  6. SCREEN _NEWIMAGE(800, 600, 32)
  7. DIM bee AS LONG
  8. bee = _LOADIMAGE("bee-12.jpg")
  9.  
  10.     CLS
  11.     i = map(_MOUSEX, 0, _WIDTH - 1, -90, 90)
  12.     IF _KEYDOWN(100306) THEN i = INT(i)
  13.     PRINT "rotation angle:"; i
  14.     putImage _WIDTH / 2 - _WIDTH(bee) / 2, _HEIGHT / 2 - _HEIGHT(bee) / 2, bee, i
  15.     _DISPLAY
  16.     _LIMIT 30
  17.  
  18. SUB putImage (__x AS SINGLE, __y AS SINGLE, image AS LONG, angleDegrees AS SINGLE)
  19.     DIM i AS LONG
  20.  
  21.     DIM center AS vertex
  22.     DIM corner(1 TO 4) AS vertex
  23.  
  24.     center.x = __x + _WIDTH(image) / 2
  25.     center.y = __y + _HEIGHT(image) / 2
  26.  
  27.     FOR i = 1 TO 4
  28.         SELECT CASE i
  29.             CASE 1
  30.                 corner(i).x = __x
  31.                 corner(i).y = __y
  32.             CASE 2
  33.                 corner(i).x = __x
  34.                 corner(i).y = (__y + _HEIGHT(image) - 1)
  35.             CASE 3
  36.                 corner(i).x = (__x + _WIDTH(image) - 1)
  37.                 corner(i).y = __y
  38.             CASE 4
  39.                 corner(i).x = (__x + _WIDTH(image) - 1)
  40.                 corner(i).y = (__y + _HEIGHT(image) - 1)
  41.         END SELECT
  42.  
  43.         rotate corner(i), center, angleDegrees
  44.     NEXT
  45.  
  46.     _MAPTRIANGLE (0, 0)-(0, _HEIGHT(image) - 1)-(_WIDTH(image) - 1, 0), image TO(corner(1).x, corner(1).y)-(corner(2).x, corner(2).y)-(corner(3).x, corner(3).y)
  47.     _MAPTRIANGLE (0, _HEIGHT(image) - 1)-(_WIDTH(image) - 1, 0)-(_WIDTH(image) - 1, _HEIGHT(image) - 1), image TO(corner(2).x, corner(2).y)-(corner(3).x, corner(3).y)-(corner(4).x, corner(4).y)
  48.  
  49. SUB rotate (p AS vertex, center AS vertex, angleDegrees AS SINGLE)
  50.     'as seen on https://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d
  51.     DIM s AS SINGLE, c AS SINGLE
  52.     DIM newP AS vertex
  53.     DIM angle AS SINGLE
  54.  
  55.     angle = _D2R(angleDegrees)
  56.  
  57.     s = SIN(angle)
  58.     c = COS(angle)
  59.  
  60.     p.x = p.x - center.x
  61.     p.y = p.y - center.y
  62.  
  63.     newP.x = p.x * c - p.y * s
  64.     newP.y = p.x * s + p.y * c
  65.  
  66.     p.x = newP.x + center.x
  67.     p.y = newP.y + center.y
  68.  
  69. FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  70.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  71.  

Offline SirCrow

  • Forum Regular
  • Posts: 144
    • View Profile
Re: StarBlast Game: Shadow Not Translucent
« Reply #8 on: August 10, 2018, 05:11:40 pm »
Thanks, Fellippe.  I may have use for that in the near future.
I may not always finish what I've started....