
-----------------------------------
josh
Thu Nov 11, 2004 8:55 am

Breaking up an Immage
-----------------------------------
I am making a bttleship game in Compsci and we have been told to make a winning, losing, and intrdocutuins screen for it. I am trying to make this introduction where these 2 pics of battlehsihips bounce around the screen and then colide and one of the pics breaks up into a bunch of pieces that shoot off everywhere. So far the code I have allows me to  take the multiple pics from a picture posistionsed with left corner at 0,0 and make them fly off in different directions. 

But the part that makes a white box ontop of the picture where the piece comes from does not work and I can't figure out why. I also can't figure out how to start off each piece from flying from its oritginal positon in the pic, as u can see when u run it they all come from position 0,0.

thanx


setscreen ("graphics:1025;700,nocursor,offscreenonly")
%Declare Variables here
var b : array 1 .. 100 of int       %holds the pictures of the broken pieces
var x : array 1 .. 100 of int       %holds the starting x coordinate of the piece on the main picture
var y : array 1 .. 100 of int       %holds the strating y coordinate of the picee on the main picture
var num : array 1 .. 100 of int     %holds the random orders that the pieces will shoot out in
var flag : boolean                  %Flag to make sure 2 differnet pieces don't get the same order number
var x1, y1 : int                    %Holds the x and y coordinate of the current moving piece
var x1r, y1r : int                  %Holds the random increment for the X and Y of the current piece
var count : int                     %Counts how many pieces we have taken picture of so far
var xtrack : array 1 .. 100 of int  %Holds the x of where the piece came from so we can draw a box over it
var ytrack : array 1 .. 100 of int  %holds the y of where the piece came from so we can draw a box over it
var shipTrack : int                 %holds pic of ship with boxes

%Initialize Variables
x1 := 0
y1 := 0
count := 0
Pic.ScreenLoad ("battleship1.jpg", 0, 0, picCopy)


%takes all the pictures from the main pircture
for row : 1 .. 10
    y (row) := (26 * (row - 1))
    for col : 1 .. 10
        count += 1
        x (col) := (34 * (col - 1))

        b (count) := Pic.New (x (col), y (row), x (col) + 34, y (row) + 26)
        ytrack (count) := row - 1 * 26
        xtrack (count) := col - 1 * 34
    end for
end for

%assigne each picture a random number to define the order thaty they will fly out in
for i : 1 .. 100
    loop
        flag := false
        randint (num (i), 1, 100)
        for j : 1 .. i - 1
            if num (i) = num (j) then
                flag := true
            end if
        end for
        exit when flag = false
    end loop
end for

Pic.ScreenLoad ("battleship1.jpg", 0, 0, picCopy)
%makes each random picture move
for i : 1 .. 100
    randint (x1r, -50, 50)
    randint (y1r, -50, 50)
    x1 := 0
    y1 := 0
    Draw.FillBox (xtrack (num (i)), ytrack (num (i)), xtrack (num (i)) + 10, ytrack (num (i)) + 10, 0)
    View.Update
    shipTrack := Pic.New (0, 0, 340, 266)
    loop
        x1 += x1r
        y1 += y1r

        Pic.Draw (b (num (i)), x1, y1, picCopy)
        
        View.Update
        cls
        Pic.Draw (shipTrack, 0, 0, picCopy)
        exit when x1 >= 1025 or x1 + 10 = 700 or y1 + 10 