Noob learns to code in 3 months

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Noob learns to code in 3 months

Post by chili » March 7th, 2017, 3:25 am

Yumtard wrote: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?
that's cuz of the building intermediate files, you don't distribute those so just ignore them. Check out the framework repo for the final code for loading mp3s ;)
Chili

Byteraver
Posts: 60
Joined: May 19th, 2016, 6:48 am
Location: Belgium, Europe

Re: Noob learns to code in 3 months

Post by Byteraver » March 7th, 2017, 8:32 am

Dude, you're a machine. To make that in a few weeks from scratch, just wow. You're an inspiration for everybody here, if you can do it, others might just as well.
About the music: it is great music, sounds a bit like oldskool chip tunes. Now these have very small samples, so if you could just replay the instruments based on the partiture, the music would not take more than a megabyte or two. I would not recommend writing replay routines yourself, (it would take months) but you can probably find a library somewhere. All depends on how the music was made.
MIDI works the same way, except you are constrained to a standard 128-piece instrument set. So no cool robot voices.
These days mp3 is probably the way to go. If not, you can reduce the wav files size drastically by making them 22 kHz 8 bit Mono. Quality will suffer but it should be bearable.

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, 10:15 am

Thanks chili! Great work :) Converted the wavs to 128 kbit/s mp3 and decreased the size of the game with 150mb :D music now takes 11.9mb instead of like 161mb

Today I'm gonna try again to make missiles. Browsed the wiki page and realized I was watching the wrong tutorial for rotation (started watching ep 7 but looks like I should tr ep 3 instead). Will give it a shot and see if I can understand it better.
Byteraver wrote:Dude, you're a machine. To make that in a few weeks from scratch, just wow. You're an inspiration for everybody here, if you can do it, others might just as well.
About the music: it is great music, sounds a bit like oldskool chip tunes. Now these have very small samples, so if you could just replay the instruments based on the partiture, the music would not take more than a megabyte or two. I would not recommend writing replay routines yourself, (it would take months) but you can probably find a library somewhere. All depends on how the music was made.
MIDI works the same way, except you are constrained to a standard 128-piece instrument set. So no cool robot voices.
These days mp3 is probably the way to go. If not, you can reduce the wav files size drastically by making them 22 kHz 8 bit Mono. Quality will suffer but it should be bearable.
Thanks :D

There's still a bunch of c++ shit I don't understand at all and often when I google something and get to some c++ forum all the posts just makes me go "wat?" and ofc I've had a bunch of help with the game from chili and albinopapa. But I'm still very happy with the progress since about 2 months ago I assumed it was more or less impossible to make a game on your own unless you were some kind of wizard.
If I can do it then other for sure can too. I don't think I'm gifted in any ways, I'm just putting in a decent amount of hours.

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, 1:13 pm

Nope wasn't able to figure out how to implement rotation. The code used in the video has a bunch of other stuff, polyclosed and other ways to draw.
So couldn't figure out how to use
Vec2 Vec2::Rotation(const float angle) const
{
Vec2 result;
float cosine = cosf(angle);
float sine = sinf(angle);
result.x = x * cosine - y * sine;
result.y = x * sine + y * cosine;

return result;
}

to actually rotate my sprites.
My feeble brain also had some trouble following the maths, would probably need another watch to understand it all.

Anyways gonna take a break and then figure out what else I can do instead

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, 8:19 pm

Drawing complete blanks on all 3 remaining things for the game.

Can anyone point me in a direction for designing the level (number of different obstacles and positions). When I google for level design and level editors I just find unity stuff etc

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, 9:58 pm

I mean I guess in the constructors of the managers I could ditch the for loops and go like this

bHole.emplace_back<BlackHole>(BlackHole{ 15.0f, bHoleAnim });
bHole.emplace_back<BlackHole>(BlackHole{ 15.0f, bHoleAnim });
bHole.emplace_back<BlackHole>(BlackHole{ 15.0f, bHoleAnim });
bHole.emplace_back<BlackHole>(BlackHole{ 350.0f, bHoleAnim });

just seems like kind of a dumb way, esp for mines which have like a 100 of them. Might have to settle for this though.

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, 11:43 pm

For level design
This is going to depend on how you want to create each level. The simplest way to visually create levels would probably be using a text file. Give each entity type an identifier like: M = mine, B = bhole, E = Enemy or EnemySpawnPoint and so on blank spaces would not be assigned anything. As you read in your text file, you would have a switch statement with a case for each identifier. Each time the case is selected, you add a new entity of that type to their respective manager.

You could also use an enum to give each entity type an id and generate random positions for each entity to generate a binary file with the identifier and position of each entity. Each level would have it's own seed value for the random generators. For loading in the entities, you'd do the same as with the previous suggestion except you would use the enum id instead of the char.

You could do something similar to the text file, but instead of text you could create a bitmap and have assigned colors for different entity types; blue = Mine, Red = Enemy, Orange = Boss and so on. You would check each pixel in the bitmap and use a switch statement as before.

NOTE: In the first and third suggestions, you'd have levels broken up into cells of a fixed width and height. For instance, 32x32 and each char or pixel represents a block. If your window is 800x600 your level would be something like 800x3200 pixels or 25x100 cells. Aside from being able to use the previous suggestions for level design, you'd also be able to cut down on the number of collision detections by determining if there are any collideable objects near the same cell the player's ship.

For rotation
The way chili implements rotation is by converting the sprite image into a pair of textured triangles with each point of the triangle being a vertex. You should probably watch the old advanced tuts and as companion tutorials, the new 3D fundamentals tutorials. I don't think I'd be able to explain clearly how to do it, there are a lot of steps.

I'm guessing the third is the alpha blending
I've already given my thoughts on the matter, just replace the Graphics.h and Graphics.cpp files that you have with the ones from the 3D Fundamentals framework which already uses the Surface class. Copy over your custom drawing functions to the new graphics class. From there, you probably just need to add a PutPixelAlpha function to the Graphics class.
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 8th, 2017, 12:27 am

Thanks. That way of designing the level sounds interesting. Will have to look into it more.

Looking at the graphics now. I'm just not getting the putpixelalpha function. The colors confuses me.
If I were to just copy paste the putpixel alpha from the surface class.

Code: Select all

void Surface::PutPixelAlpha( unsigned int x,unsigned int y,Color c )
{
	assert( x >= 0 );
	assert( y >= 0 );
	assert( x < width );
	assert( y < height );
	// load source pixel
	const Color d = GetPixel( x,y );

	// blend channels
	const unsigned char rsltRed = (c.GetR() * c.GetA() + d.GetR() * (255u - c.GetA())) / 256u;
	const unsigned char rsltGreen = (c.GetG() * c.GetA() + d.GetG() * (255u - c.GetA())) / 256u;
	const unsigned char rsltBlue = (c.GetB() * c.GetA() + d.GetB() * (255u - c.GetA())) / 256u;

	// pack channels back into pixel and fire pixel onto surface
	PutPixel( x,y,{ rsltRed,rsltGreen,rsltBlue } );
}
seems to me like the color c that gets passes to the function would be the background color and color d would be the color from the surface. How would I be able to get and pass the background color?

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 8th, 2017, 1:01 am

Actually, if the pSysBuffer of Graphics is the surface that gets drawn to, then you would be passing in the pixel from the texture. So Color c is the texture color, Color d is the pSysBuffer color at GetPixel(x, y).
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 8th, 2017, 1:06 am

Code: Select all

void Graphics::DrawSurfaceAlpha(int X, int Y, const Surface &Surf)
{
     // Do clipping calculations
     ...
     // Run through each pixel in Surf that is on screen
     for(int y = yStart; y < yEnd; ++y)
     {
          for(int x = xStart; x < xEnd; ++x)
          {
               pSysBuffer.PutPixelAlpha(x + X, y + Y, Surf.GetPixel(x, y));
          }
     }
}
Something like that.
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

Post Reply