Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Breaking up an Immage
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
josh




PostPosted: Thu Nov 11, 2004 8:55 am   Post subject: 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

code:

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 <= 0 or y1 >= 700 or y1 + 10 <= 0
    end loop
end for



*Note: I did have help from my compsci teacher with this but neither of us can figure it out now.

Here is the immage so u can run the program.

[img]
http://tinypic.com/l86kx
[/img]
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Thu Nov 11, 2004 10:42 am   Post subject: (No subject)

From glancing over your code you way want to try a few things:
- use records instead of a bunch of arrays. Right now you have arrays flying around everywhere...leading to some confusion, what goes where, what does what...&c &c.

- the whole white boxes thing...I'm not sure why but the boxes are not being drawn on the screen. Try changing the colour of the box drawn to red or something and track down where it is that it is that it is being drawn.

- as for the (0, 0) problem, perhaps the reseting of x1 and y1 for each counted loop has something to do with it?
josh




PostPosted: Thu Nov 11, 2004 10:55 am   Post subject: (No subject)

I actually have no idea what records are, I am trying a few things with the X and Y like using xtrack(i) and ytrack(i) instead.
Delos




PostPosted: Thu Nov 11, 2004 6:53 pm   Post subject: (No subject)

Dude! Records are to arrays what, umm...guitars are to drums! Sure one is good on its own, but together they totally rock.

Read all about them here:
Records by Dodge

Quick example:
code:

type ball :
    record
        x : int
        y : int
        col : int
    end record


var bucket : array 1 .. 50 of ball

for i : 1 .. upper (bucket)
    bucket (i).x := Rand.Int (0, maxx)
    bucket (i).y := Rand.Int (0, maxy)
    bucket (i).col := Rand.Int (0, 255)
end for

for i : 2 .. upper (bucket)
    drawline (bucket (i).x, bucket (i).y,
        bucket (i - 1).x, bucket (i - 1).y, bucket (i).col)
    drawfilloval (bucket (i).x, bucket (i).y, Rand.Int (1, 5),
        Rand.Int (1, 5), bucket (i).col)
end for


This shows how records can be used to put a whole bunch of characteristics common to some objects in a little container.
Cervantes




PostPosted: Thu Nov 11, 2004 6:58 pm   Post subject: (No subject)

I think this is the link you meant to post.
josh




PostPosted: Thu Nov 11, 2004 7:11 pm   Post subject: (No subject)

thanks for the link, I will see about converting that. I guess I can use a record to store every piece of info about the broken off piece..
Delos




PostPosted: Thu Nov 11, 2004 8:33 pm   Post subject: (No subject)

Good call Cervantes...nooo, my records are off! Must...update...done.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: