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

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




PostPosted: Wed Jun 07, 2006 4:06 pm   Post subject: Bricks

Im making a paddle (Brick ) game, and i hav a problem. I am using an array for my bircks,

but i want them not to go at random so i do this:
[code
for i : 1 .. 6
Draw.Box (Brick (i).Brickx - 30 + i * 61, Brick (i).Bricky + 20, Brick (i).Brickx + 30 + i * 60, Brick (i).Bricky, 2)

end for
[/code]

when the ball hits them it bounces the right weay, my problem is when it hits it, i want only one of the block to disapear (Brick(i).Bricky:=1000, jsut to get otu of the screen) but the problem is that the whole row will go or even all 3 rows. thanks
Sponsor
Sponsor
Sponsor
sponsor
upthescale




PostPosted: Wed Jun 07, 2006 4:17 pm   Post subject: (No subject)

Sorry i am using whatdtcolor, that is why they all move!
Clayton




PostPosted: Wed Jun 07, 2006 4:25 pm   Post subject: (No subject)

i am assuming that you are using records, so just have a flag for each block and when that block is hit change it to false, refresh the blocks with their flag set to true and voila !
upthescale




PostPosted: Wed Jun 07, 2006 4:40 pm   Post subject: (No subject)

flag? wut u meen?
Delos




PostPosted: Wed Jun 07, 2006 4:47 pm   Post subject: (No subject)

Add another field to your record to determine whether or not to draw the object. For instance:
code:

type brick :
  record
    xPos, yPos : int
    xSize, ySize : int
    visible : boolean
  end record


The last field will allow you to determine whether or not to draw the object - and may also be incorporated in your collision detection. Alternately you could use:

code:

type brick :
  record
    xPos, yPos : int
    xSize, ySize : int
    drawState : int
  end record


By having the flag more than a binary variable, you can have various states - for instance, 0 == invisible, 1 == visible, 2 == visible and unbreakable, etc.

Now, upthescale, I must ask. Is your keyboard broken? No, really, does it have missing letters or something else otherworldly? The extent to which your posts are obfuscated is quite irritating. Perhaps use the 'Preview' button a little more frequently eh?
_justin_




PostPosted: Thu Jun 08, 2006 7:02 am   Post subject: (No subject)

what you can do is have a boolean var

code:
var showing : array 1 .. 3, 1 .. 10 of boolean


what the 1..3 does is says their will be 3 rows of bricks and then the 1..10 mean that their will be ten bricks across

then i drew all the bricks in a for loop
code:
for row : 1 .. 3                                                                                     
    boxY := maxy - 20 * row - 10                                                                     
    for i : 1 .. 10                                                                                   
        ColorB (row, i) := Rand.Int (1, 10)                                                           
        showing (row, i) := true                                                                     
        Draw.FillBox (307 + (i - 1) * 70, boxY, 362 + (i - 1) * 70, boxY + 15, ColorB (row, i))       
    end for                                                                                         
end for


and then i used this for my collision dection

code:
for i : 1 .. 10                                                                                         
    if 307 + (i - 1) * 70 <= x and x <= 362 + (i - 1) * 70 then                                         
        for row : 1 .. 3                                                                               
            boxY := maxy - 20 * row - 10                                                               
            if y >= boxY and showing (row, i) = true then                                               
                showing (row, i) := false                                                               
                Draw.FillBox (307 + (i - 1) * 70, boxY, 362 + (i - 1) * 70, boxY + 15, white)           
                ys := -ys                                                                               
            end if                                                                                     
        end for                                                                                         
    end if                                                                                             
end for



what that does is checks to see if the ball hit a brick and what location is and turns "showing" to false and then draws a white brick over top of it
h
hope that helps
Clayton




PostPosted: Thu Jun 08, 2006 7:36 am   Post subject: (No subject)

_justin_ dont just give him the code Sad give him help or ideas on how to solve the problem, you just gave him the answer straight up Sad
_justin_




PostPosted: Thu Jun 08, 2006 10:27 am   Post subject: (No subject)

Confused sry i was just puting out one way that i did it

hmm now i can't edit my post
Sponsor
Sponsor
Sponsor
sponsor
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: