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

Username:   Password: 
 RegisterRegister   
 erasing picture
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MyPistolsIn3D




PostPosted: Sat May 01, 2004 4:40 pm   Post subject: erasing picture

Ok, I want to erase the picture thats drawn when its hit by bullet fire in my game, but there is multiple pictures on the screen all in one array. how do I do it?
code:


type planes :
    record
        x : int
        y : int
    end record
var planey : array 1 .. 10 of planes

for i : 1 .. 10
    planey (i).x := Rand.Int (0, maxx)
    planey (i).y := Rand.Int (maxy, maxy + 800)
end for

loop
    Mouse.Where (x, y, button)
    plane -> Move (x - 50, y - 60)
    for i : 1 .. 10
        planey (i).y -= 2
        Pic.Draw (picID2, planey (i).x, planey (i).y, picMerge) %PICTURE
    end for
    if button = 1 then
        fork gunfire
    end if
    View.Update
end loop
[/code]
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sat May 01, 2004 4:52 pm   Post subject: (No subject)

You could:

- have a boolean operator that decides whether the pic is drawn or not - once hit by the fire, it turns off (false), thus in your next redrawing of the screen, the pic is omitted

- draw the bg over it. If you have a single colour, cls could work

- if you have a limited number of colours being used, PicXOR could work...
MyPistolsIn3D




PostPosted: Sat May 01, 2004 5:22 pm   Post subject: (No subject)

yea, I've tried doing all those but I cant incorporate it into the array right...
Tony




PostPosted: Sat May 01, 2004 5:28 pm   Post subject: (No subject)

you could keep images in a flexable array, and when you want to delete an image, you swap image to be deleted with the last element, then resize array down one point, effectivly eliminating the image.

though you'd have to run your forloops using Upper(arrayName) so you dont get out of range error
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
MyPistolsIn3D




PostPosted: Sat May 01, 2004 5:40 pm   Post subject: (No subject)

Ok, i get what you mean tony, but how would i go about doing that? Could you give me an example or sumthing? thx.
Tony




PostPosted: Sat May 01, 2004 8:55 pm   Post subject: (No subject)

sure
code:

var word : flexible array 1 .. 5 of int

put "original array:"

for i : 1 .. upper (word)
    word (i) := Rand.Int (1, 100)
    put word (i)
end for

%removing 3rd element
word (3) := word (upper (word)) %replace 3rd element with last
new word, upper (word) - 1 %drop last element

put "array without 3rd element"
for i : 1 .. upper (word)
    put word (i)
end for
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
MyPistolsIn3D




PostPosted: Sun May 02, 2004 10:42 am   Post subject: (No subject)

thank you very much
MyPistolsIn3D




PostPosted: Sun May 02, 2004 5:41 pm   Post subject: (No subject)

Sad I cant get it to work, i've been working on it all day.... any other ideas? or should I do it another way?
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  [ 8 Posts ]
Jump to:   


Style:  
Search: