Homework #5 Help

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: Homework #5 Help

Post by albinopapa » February 18th, 2017, 6:56 pm

bool Game::collide(Rectangle A, Rectangle B)

See the bool at the beginning? That means the function needs to return a bool, either true or false. You return a value by preceding the value with the keyword return

return true;
or
return false;
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

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Homework #5 Help

Post by MrGodin » February 18th, 2017, 8:08 pm

Oh derp, you can change the bool to void. my bad ... I shouldn't really direct anyone lol. I often make mistakes
Sorry
Curiosity killed the cat, satisfaction brought him back

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Homework #5 Help

Post by Ziltwix » February 18th, 2017, 11:27 pm

Thank you albinopapa and MrGodin!
MrGodin! We're all in this together my friend!

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Homework #5 Help

Post by Ziltwix » February 19th, 2017, 4:46 pm

Hey there again gents! I'm sorry for making this an entire episode.

MrGodin, I'm sure you are familiar with my question earlier about why my reticle is not this navy blue color when I press control? Also, the reason why my moving box changes to the color red way before it touches the stationary box. (It changes color to red on the right side of the stationary box)

Code: Select all

gfx.PutPixel(-5 + x, -5 + y, rg,gb,gb);
		gfx.PutPixel(-5 + x, -4 + y, rg,gb,gb);
		gfx.PutPixel(-5 + x, -3 + y, rg,gb,gb);
		gfx.PutPixel(-4 + x, -5 + y, rg,gb,gb);
		gfx.PutPixel(-3 + x, -5 + y, rg,gb,gb);
		gfx.PutPixel(-5 + x, 5 + y,  rg,gb,gb);
		gfx.PutPixel(-5 + x, 4 + y,  rg,gb,gb);
		gfx.PutPixel(-5 + x, 3 + y,  rg,gb,gb);
		gfx.PutPixel(-4 + x, 5 + y,  rg,gb,gb);
		gfx.PutPixel(-3 + x, 5 + y,  rg,gb,gb);
		gfx.PutPixel(5 + x, -5 + y,  rg,gb,gb);
		gfx.PutPixel(5 + x, -4 + y,  rg,gb,gb);
		gfx.PutPixel(5 + x, -3 + y,  rg,gb,gb);
		gfx.PutPixel(4 + x, -5 + y,  rg,gb,gb);
		gfx.PutPixel(3 + x, -5 + y,  rg,gb,gb);
		gfx.PutPixel(5 + x, 5 + y,   rg,gb,gb);
		gfx.PutPixel(5 + x, 4 + y,   rg,gb,gb);
		gfx.PutPixel(5 + x, 3 + y,   rg,gb,gb);
		gfx.PutPixel(4 + x, 5 + y,   rg,gb,gb);
		gfx.PutPixel(3 + x, 5 + y,   rg,gb,gb);
I have tried changing the color schemes to different variables and things of that nature, but the box would be purple, black and sometimes no color at all.

I have attached my file again so you can see the error. Thank you guys!
Attachments
C++ Homework 5.zip
(2.93 KiB) Downloaded 123 times

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Homework #5 Help

Post by MrGodin » February 19th, 2017, 5:51 pm

Also, the reason why my moving box changes to the color red way before it touches the stationary box. (It changes color to red on the right side of the stationary box)
is because of this

Code: Select all

if (bx <= 200)
	{
		rb = 0;
	}
	else
	{
		rb = 255;
	}
It changes as soon as bx <= 200 :)
The color change on Control press

Code: Select all

if (wnd.kbd.KeyIsPressed(VK_CONTROL))
	{

		rg = 0;
	}
	else
	{
		rg = 255;
	}
is becaue the colors values blend together (rb,gb,gb in you putpixel calls) to make a color;
you blend colors RGB together. Each color value of r,g,b range from 0-255.
So if you go rb = 255, gb = 255, bb = 255 will equal white.
i noticed in you putpixel calls gfx.PutPixel(-5 + x, -5 + y, rg, gb, gb); the rg(red),gb(green),gb(blue) Your blue will be the same vale as green because they are both gb. Do you see ?:).
here you also had

Code: Select all

A.left = x + -5; A.right = x + 5; A.top = y - 5; A.bottom = y + 5;
	B.left = bx + -5; B.right = by + 5;<****ERROR***** B.top = by - 5; B.bottom = by + 5;
B.right = bx +5, not by +5 :)
Curiosity killed the cat, satisfaction brought him back

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: Homework #5 Help

Post by MrGodin » February 19th, 2017, 6:24 pm

I have updated your Game files
What i did in Game.h is relabeled you color values to red, green blue for the reticle
and box_red, box_blue,box_green for the Box.
In Game.cpp i removed the code that makes you reticle change to red when you don want it to
I also updated your putpixel calls with the appropriate color values
I did this to better follow colors so you can see how it is all working :)
You can now play around with the colors and get the ones you want, which i suggest you do for practice,
have fun :)
Attachments
Game.zip
(2.61 KiB) Downloaded 122 times
Curiosity killed the cat, satisfaction brought him back

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Homework #5 Help

Post by Ziltwix » February 20th, 2017, 3:21 pm

Wow! I am completely astonished! Everything we have learned from past videos are simply basic foundations in which we can build to make a whole lot better.

Thank you, MrGodin! I am very appreciative of your help and service to the community. I'm going to make note of these in my notebook and practice with them before I move on to the next tutorial. Thank you again, my friend!

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Homework #5 Help

Post by Ziltwix » February 20th, 2017, 3:25 pm

One last thing!

Is "void Game::collide" a class? I was wondering why and when we would declare this.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Homework #5 Help

Post by chili » February 20th, 2017, 3:26 pm

void Game::collide(...) is a function definition. it defines the body of a function that was declared inside the class Game.
Chili

Ziltwix
Posts: 39
Joined: January 3rd, 2017, 5:12 pm

Re: Homework #5 Help

Post by Ziltwix » February 20th, 2017, 3:54 pm

I see! So after "Game::" we define pretty much whatever we want? Like collide? Uppercut? Fart and such?

Post Reply