Noob learns to code in 3 months

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 6th, 2017, 5:01 pm

Thought I'd add some type of homing missiles. Looke up rotation in episode 7 of advanced series but wasn't able to follow along.
Will try to figure it out later. This is what's left on the game:
- Game complete screen
- Missiles attack
- mp3 (saw chili came out with a new vid about it, would be nice to decrease the size of my massive project)
- Alpha blending
- level design

Not that much! But Most of these things I don't know how to do yet :p will prob do game over screen and watch the mp3 vid tonight. Then will have to start working on the stuff I don't understand yet.
Battlefrog wrote:
Yumtard wrote:W
Great fourm post.

;)

Joking aside, your progress is great. Cannot wait until a finished version is out :P
haha I missclicked and couldn't find the delete button :p
Thanks!

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 6th, 2017, 9:59 pm

Added credits when the game is complete. Very simple credits with just text scrolling and another song by my friend. This game has amazing music imo :)

gonna finish watching the mp3 video now (my game engine folder is 345 mb atm :O)

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Noob learns to code in 3 months

Post by albinopapa » March 6th, 2017, 11:38 pm

- Missiles attack
- mp3 (saw chili came out with a new vid about it, would be nice to decrease the size of my massive project)
- Alpha blending
  • Ok, so the rotation in the Advance tutorials deals with rasterizing triangles at different angles.
  • Mp3 support in the chili framework is coming via chili adding it to the Sound class, so unless you are wanting to know how he does it using the Media Foundation Class of the Win32 API, I'd just wait.
  • Alpha blending is pretty straight forward once you understand that it's all about balancing an equation.
For alpha blending, say you have two colors:

Code: Select all

Color white = { 255, 255, 255, 255 };
Color black = { 255, 0, 0, 0 };
// Note that the alpha channel of white is 255.  255 is the highest value you can use for a color 
// channel, which means that the resulting color after the alpha blend is going to be all white and no 
// black.
// Now say you have the following colors:
Color white = { 127, 255, 255, 255 };
Color black = { 255, 0, 0, 0 };
// Note this time the alpha channel of white is 127, which is half the max value of a color channel.  
// This means that the result will be half white and half black, producing a grey color.  
// Also, note that the second color's alpha value isn't used.  As stated, alpha blending is about balancing an equation.  You use the one color's alpha value ( 127 ) for source 1 and the remainder of ( 255 - 127 ) for source 2 alpha.

You also might be getting confused because chili's implementation uses integers which is a bit more difficult to understand. If you were using floats for instance and the range was from 0.0f to 1.0f, you'd notice right away that:

Code: Select all

// In this case, the alpha channel is 1.f, so there is no remainder.
Color white = { 1.f, 1.f, 1.f, 1.f };
Color black = { 1.f, 0.f, 0.f, 0.f };

// In this case, the alpha channel is 0.5f, so there is a remainder of .5f
Color white = { .5f, 1.f, 1.f, 1.f };
Color black = { 1.f, 0.f, 0.f, 0.f };

If we were to blend these two colors, you'd do something like

Code: Select all

Color result;
const float alpha1 = white.a;
const float alpha2 = 1.f - white.a;
result.a = 1.f
result.r = (alpha1 * white.r)  + (alpha2 * black.r );
result.g = (alpha1 * white.g) + (alpha2 * black.g );
result.b = (alpha1 * white.b) + (alpha2 * black.b );
Now, if you take into account, that the max value of a color channel is 255, that makes the range of values from 0 to 255 instead of 0.f to 1.f.

The reason I said integers might be the confusing part is because of the 255 max. When you multiply 255 by 127, you get a number way larger than 255. In order to bring it back into the 0 to 255 range, you have to divide the result by 255. Just to make sure it doesn't look pointless to do that, I'll use different numbers.

Code: Select all

Color colorA = { 64, 128, 0, 0 };
Color colorB = { 0, 0, 128 }; // left the alpha out since it doesn't play into the formula

int alphaA = colorA.a;
int alphaB = 255 - colorA.a;

Color result;
int ra = 255;
int rr = (64 * 128) + (191 * 0);    // =  8192 + 0
int rg = (64 * 0) + (191 * 0);       // =       0 + 0
int rb = (64 * 0) + (191 * 128);   // =        0 + 24448

result.a = ra;
result.r = 8192 / 255     // = 32
result.g = 0;
result.b = 24440 / 255  // = 95

// As you can see, 64 is about a quarter of 255, and so the result of 32 is a quarter of 128 and 191 is about 3/4 of 255 and 95 is about 3/4 of 128 so the blue channel contributes more to the final color than the red channel.  It's the ratio of alpha1 to alpha2.  In this case 1 part red and 3 parts blue.

If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Noob learns to code in 3 months

Post by albinopapa » March 6th, 2017, 11:40 pm

Dang, 345 mb, I'd almost say use a midi file for the background music and mp3 for the sound effects.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 6th, 2017, 11:55 pm

albinopapa wrote:Dang, 345 mb, I'd almost say use a midi file for the background music and mp3 for the sound effects.
I'm not sure I understand what a midi file is. Isn't it just another format like mp3 or wav and there's no support for it?

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 7th, 2017, 12:07 am

Great explanation of alpha blending papa. Thanks! Pretty sure I understand how it works. Just haven't figured out how to make it happen in the framework yet with all the stuff chili mentioned about buffers etc
chili wrote:Haha, it appears that I have lead you on a bit of a wild goose chase here. There was one thing that I was (wrongly) assuming. PutPixelAlpha has to be called on the destination surface. But for your screen buffer, you're still using Color* pSysBuffer; (in Graphics.h)

You want to replace Color* pSysbuffer with Surface sysBuffer. Then you need to change Putpixel to call putpixel on the surface, add a putpixelalpha in graphics.h, and you need to get rid of some code in graphics that allocates/deallocates the memory for pSysBuffer (Surface allocates it's own memory in its constructor; it's a strong independent woman that don't need no man).

If you do that, it should be simple :P But you might run into some snags converting graphics to use a Surface on the back end. If you get stumped, I can show you how with a pull request, but give it a shot anyways ;)

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 7th, 2017, 12:31 am

Looks like my game has roughly
165mb music
3.2mb sfx
27.5mb of pics

total size 195.7mb
so another 145 mb of other shit

57 of the 145mb is inside of release folder

73mb in x64 folder

either of these last 2 look odd?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Noob learns to code in 3 months

Post by albinopapa » March 7th, 2017, 12:32 am

Well, the easiest way I would imagine would be to use the 3D Fundamentals framework instead of the beginner framework or at least the Graphics.h/.cpp files then just copy over your custom draw functions to the new graphics files.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Noob learns to code in 3 months

Post by albinopapa » March 7th, 2017, 12:34 am

A midi file is basically a collection of notes and corresponding instruments. So it's like a script for playing music using synthesized sounds. Unfortunately, no it's not a part of the framework and you would have to watch one of the HUGS episodes to learn how to implement it. It was just a suggestion, nothing too important I suppose once you get the wav files converted to MP3.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 7th, 2017, 12:36 am

Alrighty, thanks again papa :)

Post Reply