I finished watching tutorial 9 and decided I wanted to make something similar to the poop game, but with different sprites. I re-extracted the framework to start from new and decided to do the pixel art first. It's basically the same thing, but the poops are bones and the dude is a dog.
I started with Game.h, and created void DrawDog(); and void DrawBone(); then defined them with the appropriate gfx.PutPixel
However, I realized that I wanted to be able to switch between a dog looking forward and a dog looking backward. I didn't want to completely rewrite the code as a flipped image, so I wondered if I could just change x+ to x- and y- to y+. This, of course, completely flipped the dog upside down. So I changed the y back to -.
(The (x,y) sprite is the bottom right-hand corner of the sprite looking forward; so just under the dog's tail.)
At this point, in Game.cpp I have:
Code: Select all
void Game::ComposeFrame()
{
DrawDogForward(400,300);
DrawBone(200,200);
DrawBone(500, 500);
}
just to make sure the sprites look fine, and to test that inputting those coordinates worked in creating multiple sprites by hand. They only have two int because I'm not interested in changing their colors.
Back to the flipping dog. I wrote the code so that if you press the left arrow key, it executes DrawDogBackward, otherwise DrawDogForward. If I press right, the first forward-facing dog will move to the right. If I pressed left, the first forward-facing dog would disappear as expected, producing a backward-facing dog. Two problems with this backward-facing dog: it would be created at (400,300) and would be attached to a second forward-facing dog at the tails.
I ended up fixing this by changing the code to:
Code: Select all
left = wnd.kbd.KeyIsPressed(VK_LEFT);
if (left)
{
DrawDogBackward(fx-1,fy);
bx = bx - 2;
fx = fx - 2;
}
else
{DrawDogForward(fx,fy);
}
*** fx/y = forward facing dog x/y; bx/y = backward facing dog x/y
This made it so the backward-facing dog would appear one pixel behind the forward-facing dog. I still don't understand why the second forward-facing dog was created, but I solved it by:
Code: Select all
void Game::ComposeFrame()
{
DrawBone(500, 500);
}
(getting rid of one of the bones had nothing to do with the creation of the second forward-facing dog, I was just experimenting with the bones)
So I'm thinking, okay, now I don't have a DrawDog function at all...will it still be created? CTRL+F5 and sure enough, a forward-facing dog is created at (400,300). So this is a very long story, basically wondering why the second forward-facing dog was attached to the backward-facing dog, and why the sprite is still able to be created at (400,300) despite not having a draw function in the ComposeFrame.