Removing a drawn pixel

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Noon22
Posts: 3
Joined: March 3rd, 2013, 10:10 am

Removing a drawn pixel

Post by Noon22 » March 3rd, 2013, 10:15 am

Hey, I'm quite new to DirectX and I've found Chili's Framework very helpful. I've made just a simple Space Invaders game to test myself, and I feel I've done OK. However I'd like to know how to remove a certain pixel if a condition is met. (In my case, if the Enemy reaches the player or the missile reaches the Enemy/Top of screen). I'm using the PutPixel command, so I'd be grateful if anyone could tell me how to achieve this.

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: Removing a drawn pixel

Post by Musi » March 3rd, 2013, 5:48 pm

Sounds like you mean collision detection. The simplest way is to make a box around the enemy and then test every frame to see if the pixel is inside the box. Also, to see if the pixel has gone past the top of the screen you just have to test if the Y coordinate is less than 0.
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

Noon22
Posts: 3
Joined: March 3rd, 2013, 10:10 am

Re: Removing a drawn pixel

Post by Noon22 » March 3rd, 2013, 6:06 pm

Alright, thanks I fixed my previous issue with your help, however I would like to know how to have it so when I press space once, it places a pixel above X, (and doesn't keep updating its x position) and keep moving upwards. I made a Boolean which sets itself to true once space is pressed, however then when I store the X position of the player into another variable, it keeps updating, because the Boolean is set to true. Any idea how to go about solving this?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Removing a drawn pixel

Post by albinopapa » March 4th, 2013, 11:08 pm

There are two states for the keys pressed and released so maybe you could use an if statement that;

Code: Select all

if(SpaceIsPressed)
{
     PutPixel (?,?,?,?,?);
}
That way the PutPixel line will be skipped if the spacebar is not pressed.
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

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: Removing a drawn pixel

Post by Musi » March 5th, 2013, 7:32 am

Hmm, can't say why the new X variable is updating without seeing the code. If i have to guess, id say you're making the pixels X coordinate = players X coordinate every frame when it should only be done once when its created.
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

Noon22
Posts: 3
Joined: March 3rd, 2013, 10:10 am

Re: Removing a drawn pixel

Post by Noon22 » March 5th, 2013, 4:31 pm

Thanks, I fixed it by initializing it outside of the Loop with your help.

Post Reply