begginer's lesson 9

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
sudhanva
Posts: 12
Joined: January 26th, 2015, 10:05 am

begginer's lesson 9

Post by sudhanva » March 21st, 2015, 4:52 pm

i could not do that box reducing home work and box colour homework please help me how to do in detail and include source code :shock:

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

Re: begginer's lesson 9

Post by albinopapa » March 22nd, 2015, 5:30 am

What help do you need? What part did you not understand?

Changing the box size is done by making the width and height variables and being able to change them based on some condition, like pressing the enter key.

something like if(enterispressed) { boxWidth = boxWidth + 1; boxHeight = boxHeight + 1;}
if you are referring to the cursor changing color while inside a box, you need to think about how the box is defined. It has a left, top, right and bottom edge. The cursor also has these boundaries. So you need to test whether the boundaries of the two objects overlap. Draw a picture in Paint of how two boxes might interact with each other and see if you can come up with a logical statement that matches your observations.

Sharing code isn't a problem here, it's giving someone the answers instead of helping them learn that is the problem. If you are still stuck, upload a cleaned solution (check the sticky on the main forum page to read how to do this) of what you have and someone will help you.
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

sudhanva
Posts: 12
Joined: January 26th, 2015, 10:05 am

Re: begginer's lesson 9

Post by sudhanva » March 22nd, 2015, 9:17 am

I did not understand the colouring one i tried making variables for r g b the if(kbd blablabla is pressed)
Then r= r+1 and same for other but it did not work blank screem apEared could please share colour box code :cry: :|

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: begginer's lesson 9

Post by cameron » March 23rd, 2015, 10:11 pm

1)Code may never be getting called( due to condition or other reasons )
2)You never initialized your color variables.
3)You are not using your color variables in putpixel.

Btw you can just say var += amount.
Computer too slow? Consider running a VM on your toaster.

sudhanva
Posts: 12
Joined: January 26th, 2015, 10:05 am

Re: begginer's lesson 9

Post by sudhanva » March 24th, 2015, 3:33 am

Did not understand what you have typed
But i habe intialised color variables tried using loops but no use please share source xode

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: begginer's lesson 9

Post by cameron » March 24th, 2015, 4:28 am

I did that 3 years ago. I no longer have that source code.
Should be something like:

Code: Select all

if(kbd.YourKeyIsPressed())
{
r = g = ++b;
}

if(kbd.OtherKeyIsressed())
{
r = g = --b;
}

for(int y = yPos, yEnd = yPos + height; y < yEnd; y++)
{
for(int x = xPos, xEnd = xPos + Width; x < xEnd; x++)
{
gfx.putpixel(x,y,r,g,b)
}
}

Just make sure all your vars are inited in ctor
Computer too slow? Consider running a VM on your toaster.

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

Re: begginer's lesson 9

Post by albinopapa » March 24th, 2015, 6:22 am

cameron wrote:I did that 3 years ago. I no longer have that source code.
Should be something like:

Code: Select all

if(kbd.YourKeyIsPressed())
{
r = g = ++b;
}

if(kbd.OtherKeyIsressed())
{
r = g = --b;
}

for(int y = yPos, yEnd = yPos + height; y < yEnd; y++)
{
for(int x = xPos, xEnd = xPos + Width; x < xEnd; x++)
{
gfx.putpixel(x,y,r,g,b)
}
}

Just make sure all your vars are inited in ctor

In case the lines:
r = g = ++b;
and
r = g = --b;
are unfamiliar to you, they say add or subtract from b then assign b to g then assign g to r.

The use of ++ or -- before and after the variable has different effects.

If cameron had written it as:
r = g = b++; then it would say, assign b to g then g to r then increment b by 1, so r and g would be less than be for each frame, or in the case of r = g = b--; r and g would be one more than be each frame.
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

sudhanva
Posts: 12
Joined: January 26th, 2015, 10:05 am

Re: begginer's lesson 9

Post by sudhanva » March 29th, 2015, 3:26 am

No use it did not work
It will become black to white when i use r=g=++b, or either case it of no use give me the correct code :cry: :evil: :| :( :?: :cry: :( :evil:

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

Re: begginer's lesson 9

Post by albinopapa » March 29th, 2015, 4:27 am

k, tell ya what. Upload your project as described in the sticky post from the main thread, and I will check to see what the problem is and post the correct code.

here is the link that tells how to clean and upload your project
http://www.planetchili.net/forum/viewtopic.php?f=3&t=2
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

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: begginer's lesson 9

Post by cameron » March 29th, 2015, 6:56 pm

You have to remember most of us did this years ago and don't want to watch 9 videos to get the exact code he has( when we know how to do it ). You could try implementing single key presses with a simple bool variable to check if key was pressed last frame, and do outofbound checks on the colors, it might be why color changes so rapidly. You should first try debugging, if you cant find the problem upload your solution as albino said.
Computer too slow? Consider running a VM on your toaster.

Post Reply