Posted: Sat May 28, 2005 12:24 pm Post subject: How Do U Make A Box Go Up and Down
Hey...im new here...i was just wondering if anyone can help me asap....i want to know how can u get a box moving up and down...like a elevator for the CN tower...plz help....I REALLY NEED THIS ASAP!!!!!!!!!!!
Sponsor Sponsor
StarGateSG-1
Posted: Sat May 28, 2005 12:51 pm Post subject: (No subject)
I need more information, do you control the box?
for one. Second we do not right code for you here this is were you get help!
vi3t_4ever
Posted: Sat May 28, 2005 12:57 pm Post subject: (No subject)
ok...first...i need it to go up by it self...second...i know that...i just want to know wat code can can move the box up by itslef....u dont need to do it for me...and i just need something basic...not so difficult like the other ones....my teacher didnt teach me those
StarGateSG-1
Posted: Sat May 28, 2005 1:03 pm Post subject: (No subject)
Ok clear the box and redraw it in a loop.
Cervantes
Posted: Sat May 28, 2005 1:18 pm Post subject: (No subject)
If you want to move a box around, you cannot use hardcoded values for the x and y coordinates of the box. That is, code such as this,
code:
Draw.FillBox (100, 100, 200, 200, black)
will not move a box around, no matter how many times you draw it. So much should be self-evident.
To move the box, you need the x and y coordinates to change. Thus, we cannot hardcode integers such as 100, 100, 200, 200. Instead, we need variables.
code:
var x1 := 100 %same as var x : int := 100
var y2 := 100
var x2 := 200
var y2 := 200
Draw.FillBox (x1, y1, x2, y2, black)
This does the same as the code above. However, we could now change the variables, and thereby change the position of the box.
If we want to actually move the box, we need to draw the box in one position, then clear that image and draw it in another position, and repeat this process over and over. To do this, we use a loop.
code:
var x1 := 100 %same as var x : int := 100
var y2 := 100
var x2 := 200
var y2 := 200
loop
y1 += 1 %same as y1 := y1 + 1
y2 += 1
cls
Draw.FillBox (x1, y1, x2, y2, black)
delay (10)
end loop
Yay, the box moves up. Now, the thing is we probably don't want to have to incriment two variables just to move one box. Let's change the format of this a bit:
code:
var x := 100
var y := 100
var width := 100
var height := 100
loop
y += 1
cls
Draw.FillBox (x, y, x + width, y + height, black)
delay (10)
end loop
Now we only have to worry about one coordinate position, and with that the box will position itself.
Now, to make this look smoother, we need to use View.Update. Here's how:
code:
View.Set ("offscreenonly") %this must be typed exactly like this.
% Also, it must be placed before we do any View.Updating
var x := 100
var y := 100
var width := 100
var height := 100
loop
y += 1
cls
Draw.FillBox (x, y, x + width, y + height, black)
View.Update %flip everything from the back buffer to the fron buffer
%this gives the illusion of everything being drawn simotaneously, though really, everything
%is drawn in the back buffer at different times and then flipped onto the front buffer (the screen)
delay (10)
end loop
There are tutorials on these topics (View.Update, loops, variables, basic graphics) in the Turing Tutorials forum. Search for them if you wish.
axej
Posted: Wed Jun 08, 2005 5:45 pm Post subject: (No subject)
search is now my new best friend!
ok i agree this tread is old, but how do i make it stop at a certain height?
Cervantes
Posted: Wed Jun 08, 2005 5:57 pm Post subject: (No subject)
There are a few ways. The method you choose depends on what else is happening in your program.
This method I detest. If you want to do ANYTHING else at the same time as moving a box (such as moving a different box, drawing stuff, processing stuff, getting input, etc.) you should not use this method.
This method is much better. It allows the "object" to behave as its properties define, all while in a general loop. This allows other "objects" to be behaving as they should at the same time.
Method 3
Turing:
View.Set("offscreenonly") var x :=100 var y :=100 var vy :=1%velocity of the box in the y plane var width :=100 var height :=100 loop
This method is essentially the same as Method 2, except it does not force us to exit when the box reaches a certain point. This allows the loop to have some other means of exitting.
axej
Posted: Wed Jun 08, 2005 6:09 pm Post subject: (No subject)
thnx
method one is so easy! wow.
i think i'll use that so i won't have to explain everything to my teacher i don't need to do other stuff while the box moves. parallel put still works while that happens right?
btw: "offscreenonly" stops flickering right?
Sponsor Sponsor
Cervantes
Posted: Wed Jun 08, 2005 6:18 pm Post subject: (No subject)
axej wrote:
thnx
method one is so easy! wow.
i think i'll use that so i won't have to explain everything to my teacher i don't need to do other stuff while the box moves. parallel put still works while that happens right?
btw: "offscreenonly" stops flickering right?
parallelput will still work, but you'll have to code it directly into the for loop, which may or may not be so pleasent.
offscreenonly does not stop the flickering. To stop it, you need to set offscreenonly, then use View.Update (in the correct place, if you want to see what you intend to show).
axej
Posted: Wed Jun 08, 2005 8:24 pm Post subject: (No subject)
thnx
what do you think of my uber simple culminating that nobody in my class has started yet?
*Edit* if your wondering why the "%parallelput", its because the actual thingy im building isn't really wired yet. i still have to get that seven segment display working.
ok, second addition. the locate thingy is messed it doesn't do anything except end the program which its no tsupposed to do, any er suggestions?
the code looks noobish too i just realised that, but its easy to explain it to my teacher
Drakain Zeil
Posted: Wed Jun 08, 2005 9:53 pm Post subject: (No subject)
You can shorten that code by... I'd say about 4/5ths.
Use a for..next loop to increment that one number that you add 50 to each time.
Edit: Aslo, I think you only need to set the View.Set once.
Edit again!: I just took a real look into your code, and oh boy did you ever over-do it!.
Try this...
code:
put "Welcome to The Office Building where employees get stuffed into cubicles, please use the elevator since we have no stairs"
%We don't need delays here...
cls
var flr :int
loop
put"please select floor number (1-6)"
get flr
exit when flr =1 OR flr =2 OR flr =3 OR flr =4 OR flr =5 OR flr = 6
cls
%We don't need delays here...
locate (150,200: int)
put "Enter a number between 1 and 6."
%We don't need delays here...
cls
end loop
View.Set ("offscreenonly")
var x := 100
var width := 100
var height := 100
for y : 0 .. (flr*50) %Use math, it's good for you.
cls
Draw.FillBox (x, y, x + width, y + height, black)
View.Update
delay (20)
end for
axej
Posted: Wed Jun 08, 2005 9:56 pm Post subject: (No subject)
ok, how about the locate part?
[Gandalf]
Posted: Thu Jun 09, 2005 3:54 pm Post subject: (No subject)
It's alright.
code:
(150,200: int)
should be
code:
(150,200)
don't know why you have the :int...
axej
Posted: Thu Jun 09, 2005 4:02 pm Post subject: (No subject)
i figured that one out already thanks
axej
Posted: Thu Jun 09, 2005 4:22 pm Post subject: (No subject)
ok i have another problem i can't get my seven segment display to work can anyone help me?