
-----------------------------------
chrispminis
Sun Dec 18, 2005 11:49 pm

Multiple Falling.
-----------------------------------
Hey, I need some help. I'm trying to get "coins" to fall from the air. So far I have this.

var mx, my, mb : int
var totalcoins : int
var fallspeed  : int := 5

View.Set ("graphics:offscreenonly:300;600")

get totalcoins
var coins : array 1 .. totalcoins of int


loop
    Mouse.Where (mx, my, mb)

    for coinx : 1 .. totalcoins
        coins (coinx) := Rand.Int (1, maxx)
    end for

    for coinx : 1 .. totalcoins
        for decreasing coiny : maxy .. 1
            Draw.FillOval (coins (coinx), coiny, 5, 5, 14)
            delay (fallspeed)
            View.Update
            cls
        end for
    end for
end loop



1. Why doesn't the View.Set have any effect?

2. How would I get it to drop multiple coins at a time instead of just one (I'm trying to get it so that totalcoins is the amount of coins is the max amount of coins on screen)?

3. How would I get the coins to drop at different times (preferably at a manipulatable rate)?

You don't have to do the work, but some sample source code so I could see the logic would be great. I can't think of how to do it, although i have been looking through the sources from other programs.

-----------------------------------
Carino
Mon Dec 19, 2005 3:20 am


-----------------------------------
I got bored, hope this helps.


var mx, my, mb : int
var totalcoins : int
var fallspeed : int := 5

View.Set ("graphics:offscreenonly:300;600")

type attrib :
    record
        speed : int
        x : int
        pos : int
    end record

get totalcoins
var coins : array 1 .. totalcoins of attrib

for i : 1 .. totalcoins
    coins (i).speed := Rand.Int (1, 5)
    coins (i).x := Rand.Int (1, maxx)
    coins (i).pos := maxy
end for

loop
    %Mouse.Where (mx, my, mb)

    for i : 1 .. totalcoins
        coins (i).pos -= coins (i).speed
        Draw.FillOval (coins (i).x, coins (i).pos, 5, 5, 14)

        if coins (i).pos < 0 then
            coins (i).speed := Rand.Int (1, 5)
            coins (i).x := Rand.Int (1, maxx)
            coins (i).pos := maxy
        end if
    end for

    View.Update
    delay (10)
    cls
end loop


-----------------------------------
Albrecd
Mon Dec 19, 2005 9:44 am


-----------------------------------
The View.Set has no effect because it has errors, instead it should be:

View.Set ("graphics:300;600,offscreenonly)

In order to have multiple coins at one time, you will need multiple X and Y variables: one for each coin.  If you want them to fall at different times, you could do something like:

var WhenCoinFall : array 1 .. 3 of int     %however many you want, we shall say 3
var counter := 0    %automatically set as an integer
var CoinFalling : array 1 .. 3 of boolean

for i : 1 .. 3
    CoinFalling (i) := false
end for

for i : 1 .. 3
    randint (WhenCoinFall (i), 1, 5)   % min and max can be whatever, we shall say 1 and 5
end for

loop
counter += 1
for i : 1 .. 3
    if WhenCoinFall (i) = counter then
        CoinFalling (i) := true
    end if
end for
for i : 1 .. 3
    if CoinFalling (i) = true then
        %Put your Y -= or whatever here
    end if
end for
end loop

-----------------------------------
Albrecd
Mon Dec 19, 2005 9:47 am


-----------------------------------
Note: the two for loops in the loop in my example could really be one... Why is there no edit button???

-----------------------------------
do_pete
Mon Dec 19, 2005 11:59 am


-----------------------------------
try something like this:
type Coin :
    record
        X : int
        Y : int
        Speed : int
    end record

const RADIUS := 5
const AMOUNT := 20
var Coins : array 1 .. AMOUNT of Coin

for i : lower (Coins) .. upper (Coins)
    Coins (i).Y := Rand.Int (maxy + RADIUS, maxy * 2)
    Coins (i).X := Rand.Int (RADIUS, maxx - RADIUS)
    Coins (i).Speed := Rand.Int (1, 5)
end for

View.Set ("offscreenonly")

loop
    for i : lower (Coins) .. upper (Coins)
        if Coins (i).Y 