Icy Tower
Author |
Message |
Mr. T
|
Posted: Sun Jun 26, 2005 7:26 pm Post subject: Icy Tower |
|
|
How can i make the blocks fall down in a continuous motion with a uniform interval in between each block.
code: |
View.Set ("graphics:500;600,nobuttonbar,offscreenonly")
colourback (black)
cls
type blockType :
record
x : int
y : int
length : int
end record
var block : array 1 .. 8 of blockType %Blocks
var blockOnScreen : array 1 .. 8 of boolean
Draw.FillBox (0, 0, 70, maxy, brightred)
Draw.FillBox (maxx, 0, maxx - 70, maxy, brightred)
loop
% Set the X position and length of 4 blocks
for i : 1 .. 8
randint (block (i).x, 70, maxx - 140)
randint (block (i).length, 30, 100)
block (i).y := maxy
blockOnScreen (i) := false
end for
loop
Draw.FillBox (0, 0, 70, maxy, brightred)
Draw.FillBox (maxx, 0, maxx - 70, maxy, brightred)
for blockNo : 1 .. 8
if blockOnScreen (blockNo) then
block (blockNo).y -= 2
Draw.FillBox (block (blockNo).x, block (blockNo).y, block (blockNo).x + block (blockNo).length, block (blockNo).y - 10, yellow)
delay (5)
end if
end for
if not blockOnScreen (1) then
blockOnScreen (1) := true
elsif not blockOnScreen (2) then
blockOnScreen (2) := true
elsif not blockOnScreen (3) then
blockOnScreen (3) := true
elsif not blockOnScreen (4) then
blockOnScreen (4) := true
elsif not blockOnScreen (5) then
blockOnScreen (5) := true
elsif not blockOnScreen (6) then
blockOnScreen (6) := true
elsif not blockOnScreen (7) then
blockOnScreen (7) := true
elsif not blockOnScreen (8) then
blockOnScreen (8) := true
end if
View.Update
cls
end loop
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Cervantes
|
Posted: Sun Jun 26, 2005 7:36 pm Post subject: (No subject) |
|
|
One way to do it would be to assign the y values of the blocks random values between maxy and maxy * 2 or times whatever you wish.
Another way to do it is only create a new block if the upper bounds of the blocks array is less than a certain value. Of course, this would spawn blocks in quick succession. You'd also have to put a time delay on it. This way will ensure that you get a block every so often, making it possible (given that you can jump the width of the tower). On the other hand, it's very regulated, perhaps too much so. This method will require flexible arrays. |
|
|
|
|
|
Mr. T
|
Posted: Sun Jun 26, 2005 7:53 pm Post subject: Alex's Opinion |
|
|
i dont understand, could u write up an examplke that applies to my code? |
|
|
|
|
|
Cervantes
|
Posted: Sun Jun 26, 2005 8:20 pm Post subject: (No subject) |
|
|
I suppose so.
Method 2:
Turing: |
View.Set ("graphics:500;500,nobuttonbar,offscreenonly")
colourback (black)
var block : flexible array 1 .. 0 of
record
x, y : real
width, height : int
end record
var lastCreatedBlock := 0
loop
%checking to add blocks
if upper (block ) < 5 & Time.Elapsed > lastCreatedBlock + 500 then
new block, upper (block ) + 1
block (upper (block )).width := Rand.Int (40, 70)
block (upper (block )).height := Rand.Int (3, 7)
block (upper (block )).x := Rand.Int (ceil (block (upper (block )).width / 2), floor (maxx - block (upper (block )).width ))
block (upper (block )).y := maxy + block (upper (block )).height / 2
lastCreatedBlock := Time.Elapsed
end if
%Checking to remove blocks
for i : 1 .. upper (block )
if ceil (block (i ).y + block (i ).height / 2) < 0 then
block (i ) := block (upper (block ))
new block, upper (block ) - 1
exit
end if
end for
%moving the blocks
for i : 1 .. upper (block )
block (i ).y - = 1
end for
%Drawing the environment
cls
for i : 1 .. upper (block )
Draw.FillBox (round (block (i ).x - block (i ).width / 2), round (block (i ).y - block (i ).height / 2),
round (block (i ).x + block (i ).width / 2), round (block (i ).y + block (i ).height / 2), 102)
end for
View.Update
delay (5)
end loop
|
Method 3 (better)
Turing: |
View.Set ("graphics:500;500,nobuttonbar,offscreenonly")
colourback (black)
var block : array 1 .. 10 of
record
x, y : real
width, height : int
end record
for i : 1 .. upper (block )
block (i ).width := Rand.Int (40, 70)
block (i ).height := Rand.Int (3, 7)
block (i ).x := Rand.Int (ceil (block (i ).width / 2), floor (maxx - block (i ).width ))
block (i ).y := maxy + (maxy / upper (block ) * i )
end for
var lastCreatedBlock := 0
loop
%Checking to remove blocks
for i : 1 .. upper (block )
if ceil (block (i ).y + block (i ).height / 2) < 0 then
block (i ).width := Rand.Int (40, 70)
block (i ).height := Rand.Int (3, 7)
block (i ).x := Rand.Int (ceil (block (i ).width / 2), floor (maxx - block (i ).width ))
block (i ).y := maxy + block (i ).height / 2
exit
end if
end for
%moving the blocks
for i : 1 .. upper (block )
block (i ).y - = 1
end for
%Drawing the environment
cls
for i : 1 .. upper (block )
Draw.FillBox (round (block (i ).x - block (i ).width / 2), round (block (i ).y - block (i ).height / 2),
round (block (i ).x + block (i ).width / 2), round (block (i ).y + block (i ).height / 2), 102)
end for
View.Update
delay (5)
end loop
|
The advantages of method 3 are that you don't have to worry about changing a hardcoded value for how many blocks you have on the screen, it'll do all the timings for you based on the number of blocks and the screen height. Second, you don't have to delete a block then add a block. In fact, you don't even need to use flexbile arrays for method 3. |
|
|
|
|
|
MysticVegeta
|
Posted: Sun Jun 26, 2005 9:53 pm Post subject: (No subject) |
|
|
Ontopic: Well its just like having the asteroid code of jamonathin except the movement here is vertical... Calling it in a procedure would be efficient, because i am assuming that it is in a game.
Offtopic: Wow cervantes, you finally made a program without flexible arrays |
|
|
|
|
|
|
|