Noob learns to code in 3 months

The Partridge Family were neither partridges nor a family. Discuss.
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 » January 30th, 2017, 4:11 am

for now, make a new function called PutPixelClipped in the Graphics class. Determine if the object (mine) is completely on screen or partially on screen. If partially on screen, call the clipped version, if it's completely on screen, then draw the more efficient non clipped version of PutPixel.

Code: Select all

void Graphics::PutPixelClipped(int x, int y, Color c)
{
     if( x >= 0 && x < ScreenWidth &&
         y <= 0 && y < ScreenHeight )
     {
          PutPixel(x,y,c);
     }
}
Later when you get to loading in images and creating sprites, you'll be able to calculate where to start drawing the sprite so that you won't need the PutPixelClipped version at all...well, maybe in some cases, but with the massive PutPixel calls of the current project this might be your only option.
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
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 » January 30th, 2017, 1:47 pm

I just played space balls. Lookin good bro! Music really adds something to a demo. I gotta work on that .ogg file support in the framework sometime soonish.

Do the balls you shoot have any effect as of yet? :D

As for your question, we won't be able to do clipping WELL for a little while yet. Once we are able to load sprite pixels into arrays from .bmp files, then we can do proper sprite BitBltting (Bit Block Transferring). And when we do that, we can adjust the start/end points of the x and y loops to only draw the pixels that will appear inside the screen region.

However, to load bitmaps we need to know about pointers, strings, file access, 2D array organization, so were still a few episode away from that.

As papa says, for now you can do per-pixel testing for any sprites that may be partly off the screen. It is very slow, but it should be fine for a moderate amount of smallish sprites. If you need a better performance boost, you can make 2 versions of the draw function. A clipping version and a non-clipping version. Then you do a rect test to see if the sprite is completely in the window. If so, call non-clipping draw. Otherwise, call clipping draw.
Chili

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 » January 30th, 2017, 3:08 pm

Thanks papa! Seems like a bit too much of a hassle for now
chili wrote:I just played space balls. Lookin good bro! Music really adds something to a demo. I gotta work on that .ogg file support in the framework sometime soonish.

Do the balls you shoot have any effect as of yet? :D

As for your question, we won't be able to do clipping WELL for a little while yet. Once we are able to load sprite pixels into arrays from .bmp files, then we can do proper sprite BitBltting (Bit Block Transferring). And when we do that, we can adjust the start/end points of the x and y loops to only draw the pixels that will appear inside the screen region.

However, to load bitmaps we need to know about pointers, strings, file access, 2D array organization, so were still a few episode away from that.

As papa says, for now you can do per-pixel testing for any sprites that may be partly off the screen. It is very slow, but it should be fine for a moderate amount of smallish sprites. If you need a better performance boost, you can make 2 versions of the draw function. A clipping version and a non-clipping version. Then you do a rect test to see if the sprite is completely in the window. If so, call non-clipping draw. Otherwise, call clipping draw.
Awesome :) The bullets aren't doing anything yet. I plan on having them disappear when they hit the mines but haven't decided if they're going to effect the mines.
I will then add in enemy space ship which they will be used on :)
Alright! Once we're there I'm assuming I should be able to just change my current code to the new sprites. so I'll just leave it as it is for now and deal with it once we get there :)

Pointers, constructors and deconstructors are topics I want to "master" as of now i understand what they are but am unsure how and when to actually use them in practice

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 » January 30th, 2017, 9:31 pm

I forgot about the massive putpixel calls and changing them all over to use either or would be a pain, sorry.
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 » January 30th, 2017, 11:29 pm

albinopapa wrote:I forgot about the massive putpixel calls and changing them all over to use either or would be a pain, sorry.
No don't say sorry :D
Was an interesting solution. Actually ended up using it for the mines.
Because I was getting errors when a mine exploded near the end of the screen since the explosion is bigger than the actual mines, so needed to add PutPixelClipped for the explosion and while I was at it I also added it for the mines to make the glide in and out of screen smoothly

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 » January 30th, 2017, 11:30 pm

Oh, sweet.
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
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 » January 31st, 2017, 1:16 am

Yumtard wrote:
albinopapa wrote:I forgot about the massive putpixel calls and changing them all over to use either or would be a pain, sorry.
No don't say sorry :D
Was an interesting solution. Actually ended up using it for the mines.
Because I was getting errors when a mine exploded near the end of the screen since the explosion is bigger than the actual mines, so needed to add PutPixelClipped for the explosion and while I was at it I also added it for the mines to make the glide in and out of screen smoothly
It's not a hassle at all.
1) Collapse mass PP function
2) Select entire function
3) Find & replace that mother PutPixel -> PutPixelClipped
4) ???
5) Profit!
Chili

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 » January 31st, 2017, 1:21 am

^ yep!

I'm starting to get crazy. Was gonna quickly make it so the bullets disappear if they hit an object like the mines. I can't for the life of me figure out how to get it done! It seems much harder to get done than detecting if the ships hit a mine.
In the mine class I have a function for detectcollision which takes a reference to ship as argument and decides if they are colliding. thought I'd do something similar for bullets but the bullets are stored in an array in the ship class and mines are stores in an array in minemanager. All other objects will also be stored in arrays. No idea how this works

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 » January 31st, 2017, 1:24 am

Yumtard wrote: Pointers, constructors and deconstructors are topics I want to "master" as of now i understand what they are but am unsure how and when to actually use them in practice
Raw pointers are used not-so-often in modern C++ because in most cases they can be replaced with the safer-and-sexier-syntaxed &reference, or when we need a pointer, we wrap it up in a smart pointer container. I use more pointer-like objects (smart pointers, iterators) than I do actual pointers. They still have their uses though, and a lot of APIs and like to return handles to objects as raw pointers (Box2D, Unreal Engine for instance).

Deconstructors aren't used much either because we like to use things that deconstruct themselves automatically. That being said, I will be going over them in the beginning of Intermediate.

Beginner will run up to T24 and then we will start Intermediate, diving balls deep into pointers :)
Chili

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 » January 31st, 2017, 2:10 am

Today I kinda felt stupid when trying to program.
Didn't figure out a way to get the bullet collisions done so gave up on it for now.

This is what I did today:
Watched episode 17 and 18. 18 was interesting but felt like something I don't need to put too much effort into understanding right now.
Did the homework for 17 but on my spaceballs game instead of snek game.
Then changed a shitload of ints to floats.

Since I felt stooopid today I focused on doing something easy after failing with the bullets
Made an EnergyBoost class and manager class. So now you can pick up hearts to restore health. Basically just copy pastad almost everything from the mine class and slightly modified it.
Then I made a DrawAnnulus function in graphics which I'm gonna use to draw a shield.
Started these classes:
Shield
ShieldManager
ShieldMeter
But got a bit tired so I gave up for now and gonna finish the classes tomorrow.
Basically I want to make it so you can pick up a shield which draws a circle around the ship and makes you invincible until it runs out and have a meter pop up and display time left with shield.
chili wrote:
Yumtard wrote: Pointers, constructors and deconstructors are topics I want to "master" as of now i understand what they are but am unsure how and when to actually use them in practice
Raw pointers are used not-so-often in modern C++ because in most cases they can be replaced with the safer-and-sexier-syntaxed &reference, or when we need a pointer, we wrap it up in a smart pointer container. I use more pointer-like objects (smart pointers, iterators) than I do actual pointers. They still have their uses though, and a lot of APIs and like to return handles to objects as raw pointers (Box2D, Unreal Engine for instance).

Deconstructors aren't used much either because we like to use things that deconstruct themselves automatically. That being said, I will be going over them in the beginning of Intermediate.

Beginner will run up to T24 and then we will start Intermediate, diving balls deep into pointers :)
Sounds awesome :)
I'll do my best to be ready for intermediate when you start releasing them!

Post Reply