March 2016
Beginner to intermediate
340 pages
6h 51m
English
Now, we are going to learn how to implement rectangular collision detection. It turns out that both Robo and our enemy (a water bottle) are very rectangular, making rectangular collision detection the best choice.
Let's introduce our Robo's enemy—a bottle of water to rust his gears. The code for this is included next.
Add the following sprite definition to RoboRacer2D:
Sprite* enemy;
Now, we will setup the sprite. Add the following code to LoadTextures:
enemy = new Sprite(1);
enemy->SetFrameSize(32.0f, 50.0f);
enemy->SetNumberOfFrames(1);
enemy->AddTexture("resources/water.png");
enemy->IsVisible(false);
enemy->IsActive(false);
enemy->SetValue(-50);
enemy->IsCollideable(true);This code is essentially ...
Read now
Unlock full access