Computer Science Canada Animation Help Please |
Author: | jakey140 [ Tue Dec 19, 2006 6:43 pm ] | ||
Post subject: | Animation Help Please | ||
The following code is what I have came up with in regards to moving a sqaure using the arrow keys... Can somebody please help me modify the program so hat the box doesnt go outside the size of the screen or distort???
|
Author: | neufelni [ Tue Dec 19, 2006 7:23 pm ] | ||||
Post subject: | |||||
Well I don't have Turing on my computer anymore so I can't run your program, but I think I can see why it is being distorted(I'm assuming you mean it is changing sizes). First off, there are many little things that you should change in your code. The first thing is all the setscreens. You can replace them all with just one:
Next, you only need two variables for the position, an x and a y, as long as you want to keep the box the same size. And for drawing the boxes, you should use Draw.FillBox rather than drawfillbox. You can also simplify your if statements. For the right and left arrows, you only need to change your x variables, and for the up ans down arrows you only change the y variables. You may also want to check out Input.KeyDown for your input. So here is your improved code. If you have any questions about it feel free to ask. And as I mentioned earlier, I don't have Turing so there may be some problems with this code.
EDIT: I forgot about keeping the box from going off the screen. All you need is add another condition to each of your if statements so that the box won't move if it will go off the screen. The updated code is above. |
Author: | uberwalla [ Tue Dec 19, 2006 7:32 pm ] | ||
Post subject: | |||
ok first of all why use Draw.FillBox instead of drawfillbox? theres nothing wrong with it. anyways to help improve your code id recomend not using getch to move your box. it pauses to get the certain character after every hit so it moves very slow. i'd recomend Input.KeyDown. heres an a different version of the revised version nick made, which makes it faster. and it will make it also much easier to tell which key u use instead of using keystroke codes. some people may get annoyed having to look them up to test yar code (like me ![]()
|
Author: | ericfourfour [ Tue Dec 19, 2006 7:49 pm ] |
Post subject: | |
uberwalla wrote: ok first of all why use Draw.FillBox instead of drawfillbox? theres nothing wrong with it.
You are right, there is nothing wrong with it. However, Draw.FillBox is better because it teaches you more about modules. When I enter Draw., I know the function/procedure will come from the draw module. drawfillbox on the other hand looks like a procedure that just draws a full box. It does not tell me anything about where it comes from. |
Author: | uberwalla [ Tue Dec 19, 2006 7:59 pm ] |
Post subject: | |
ahh ok. anyways talking about modules brings me to another question ![]() does making a class or module make a difference? arent they basically the same? like they both store code that you can input ![]() because im going to make a module to put in the predefs and hopefully itll work ![]() ![]() |