moving a square using a procedure
Author |
Message |
DanceMacabre
|
Posted: Sun Apr 30, 2006 9:22 pm Post subject: moving a square using a procedure |
|
|
ive got a square here, and i have a procedure to move it, but everytime it moves, it also grows and makes itself bigger. when you try and move the square back to its original position, it keeps the shape that it has taken. whats wrong? how do i fix this? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
|
|
|
 |
DanceMacabre
|
Posted: Sun Apr 30, 2006 10:12 pm Post subject: (No subject) |
|
|
heres my code
code: |
var gridx : int := 0
var gridy : int := maxy
var space : int := Pic.FileNew ("space.jpg")
var paranoids : int := Pic.FileNew ("paranoids.jpg")
var x : int := 52
var y : int := 42
var charpress : array char of boolean
procedure movered (var x : int, var y : int)
Input.KeyDown (charpress)
if charpress (KEY_UP_ARROW) then
y := y + 1
end if
if charpress (KEY_DOWN_ARROW) then
y := y - 1
end if
if charpress (KEY_RIGHT_ARROW) then
x := x + 1
end if
if charpress (KEY_LEFT_ARROW) then
x := x - 1
end if
end movered
drawfillbox (0, 0, maxx, maxy, black)
loop
delay (50)
drawfillbox (gridx, 0, gridx - 1, maxy, brightblue)
gridx := gridx + 25
exit when gridx > maxx
end loop
gridx := 0
loop
delay (50)
drawfillbox (0, gridy, maxx, gridy - 1, brightblue)
gridy := gridy - 25
exit when gridy < 0
end loop
loop
drawfillbox (0, 0, 10, maxy, white)
delay (1000)
drawfillbox (maxx - 10, 0, maxx, maxy, white)
delay (1000)
drawfillbox (0, maxy, maxx, maxy - 5, white)
delay (1000)
drawfillbox (0, 5, maxx, 0, white)
delay (1000)
Pic.Draw (space, 11, maxy - 47, picMerge)
delay (1000)
Pic.Draw (paranoids, 11, maxy - 88, picMerge)
end loop
%*************************************************%
%++++++++++++++draw the characters++++++++++++++++%
%*************************************************%
loop
movered (x, y)
drawfillbox (x, y, 50, 50, red)
View.Update
end loop
|
see, this last loop here is supposed to be what moves the red square, but its not working properly. Know whats wrong? |
|
|
|
|
 |
wtd
|
Posted: Sun Apr 30, 2006 10:25 pm Post subject: (No subject) |
|
|
I spy, with my little eye...
... an infinite loop.
code: | loop
drawfillbox (0, 0, 10, maxy, white)
delay (1000)
drawfillbox (maxx - 10, 0, maxx, maxy, white)
delay (1000)
drawfillbox (0, maxy, maxx, maxy - 5, white)
delay (1000)
drawfillbox (0, 5, maxx, 0, white)
delay (1000)
Pic.Draw (space, 11, maxy - 47, picMerge)
delay (1000)
Pic.Draw (paranoids, 11, maxy - 88, picMerge)
end loop |
|
|
|
|
|
 |
DanceMacabre
|
Posted: Sun Apr 30, 2006 11:10 pm Post subject: (No subject) |
|
|
lol..k i got rid of the infinate loop, but it still doesnt help my red box problem. I want to be able to control the red box, move it around and stuff. but instead, it keeps re-sizing itself! what should I do!? |
|
|
|
|
 |
Delos

|
Posted: Sun Apr 30, 2006 11:20 pm Post subject: (No subject) |
|
|
I spy, with my slighty-red-from-the-pollen-in-the-air-from-all-those-bloody-dandilions-eye, a little mistake:
code: |
drawfillbox (x, y, 50, 50, red)
|
Notice how you change the values of x any y in your movered proc, yet the values of (50, 50) remain constant. Hence, any time the object is moved, the (x, y) coords change, but they are always drawn to the (50, 50) coords. My advice would be to change it to something like:
code: |
drawfillbox (x, y, x + 50, y + 50, red)
% Or better yet:
drawfillbox (x, y, x + boxSize, y + boxSize, red)
% Where boxSize would be a parameter allowing you to have multiple boxes of different sizes.
|
|
|
|
|
|
 |
Clayton

|
Posted: Mon May 01, 2006 12:41 pm Post subject: (No subject) |
|
|
also when you are moving your box, you arent actually making it look like a box, but more like a paint application where it "colors" where was, to fix that just make a cls before you draw another box on top of the one you just drew (making it look like a solid painty thing) instead do something like this
try that in your program and see if you can get it to work  |
|
|
|
|
 |
|
|