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

Yumtard wrote: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
That tutorial is on the basic math of rotation. How to rotate a single point in space. In order to properly rotate an entire sprite, as papa mentioned, you need to draw the sprite as textured geometry, and then rotate that geometry. It's an advanced topic for you right now, I say leave it.

You can use the point rotation to do rotational movement of sprite, but leave the sprites themselves in the same orientation. If you need rotation, create n sprite frames for each angle of rotation you want (maybe 16/32 frames will give you fairly fine-grained rotation).

In your next game in sfml, you can do rotation easy without understanding the underlying concepts. Leave the exercise of doing it yourself until you are a little more advanced. Did you at least understand the principle of rotating a point in space? :)
Chili

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

albinopapa wrote:

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.
Small issue, but I would name the buffer Surface in Graphics "sysBuffer", and not "pSysBuffer", since it is an embedded object, not a pointer.
Chili

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:22 am

doh
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, 1:51 am

omg alpha is working, feel like crying (manly) tears of joy.
Just tried it in the 3d repo, will try to implement it in the actual game tomorrow and also look more into this level data in text files voodoo.

Thanks guys

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, 2:43 am

chili wrote:
Yumtard wrote: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
That tutorial is on the basic math of rotation. How to rotate a single point in space. In order to properly rotate an entire sprite, as papa mentioned, you need to draw the sprite as textured geometry, and then rotate that geometry. It's an advanced topic for you right now, I say leave it.

You can use the point rotation to do rotational movement of sprite, but leave the sprites themselves in the same orientation. If you need rotation, create n sprite frames for each angle of rotation you want (maybe 16/32 frames will give you fairly fine-grained rotation).

In your next game in sfml, you can do rotation easy without understanding the underlying concepts. Leave the exercise of doing it yourself until you are a little more advanced. Did you at least understand the principle of rotating a point in space? :)
Alright im bailing on missiles. In that case all that's left after alpha is level design and potentially cleaning up the code.
I felt like i understood 75% of it while watching but now i dont really remember. Will def give it another watch at some point

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, 9:57 am

I reread what you said about the levels papa. I think I understand how you mean.

make a 2d array grid that covers the whole level.
Represent the grid in a textfile something like this

0010010020
0000000000
0000000000
0003000002

Where 0 in this case is nothing and >0 are different objects.

Then I'd have a level class in my game in which I will loop through the cells and read in the file and would have a switch statement something like

switch leveldata
case 0:
break;

case 1:
MineManager.SpawnMine();

case2:
obstacleManager.SpawnObstacle();

etcetc

the spawn() functions will just be something like this

void spawn(float x, float y)
{
bHole.emplace_back<BlackHole>(BlackHole{ x, y, bHoleAnim });
}

And I'd include level in world and run it in the constructor or something?


one annoying issue with this which I guess can be worked around is that unless all entities has the same speed then the level will just look the way it does in the textfile right at the beginning,
Say at the end of the level you have 2 mines and a black hole, and the mines move twice as fast as the black hole, then ones you reach the end the mines will be long gone

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

If we have any genius coders in here capable of making some sort of time machine. Please let me use it for a minute to travel back in time and punch myself in the face for not saving all the sprites and animation frames as alphas and for making changes to sprites without saving after I exported them

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

I would just skip the case 0 since you aren't doing anything in it, but other than that, yes, that's exactly what I mean.

As for your concern about speed of objects, one way I have done it in the past is instead of specifying individual objects, I made triggers that once the player reached a certain point in the level, the trigger was executed which in my case was spawning asteroids, groups of enemies and the level boss. Once you have the triggers in place in the level, you would check each trigger condition. Once the condition is met, you'd start spawning mines. I also made the triggers have stop conditions as well, because I had around 5 different enemy types that would appear at different points throughout the level and I only wanted to spawn ten units at a time. I also wanted to only have the boss at the end of the level without any asteroids or enemy ships. ( I miss that project, I should go back and polish it up with all the stuff I've learned since Cameron, Luis and I started about 2-3 years ago ).

Anyway, there are ways around your concern, just think of other games you've played and how they might have been able to do the same things.
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, 10:56 am

Oh man that's gotta suck. Well, live and learn, always save the originals and always as png or something capable of saving the alpha channel...ie 32 bit or higher.
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, 1:18 pm

Sounds like a good idea about triggers.

Copied graphics from 3d repo into my project and it's not working, getting tons of errors I don't understand
Lots of the errors seems like they have to do with chiliwin

inside graphics a couple things also gets errrors, I think because the surface classes are not the same.

Post Reply