
-----------------------------------
SAValkyrie
Mon Jan 07, 2013 8:39 pm

Making breakable blocks in a game
-----------------------------------
What is it you are trying to achieve?
Our group is making a bomberman game, we are trying to add breakable blocks when it is inside the bomb explosion radius.


What is the problem you are having?
We are using text based 2D tile map, but we could not figure out how to add blocks via using a text file, and changing their colour and setting them as breakable. 


Describe what you have tried to solve this problem
I tried searching in compsci forums, but i couldnt get the right answer.


Please specify what version of Turing you are using
4.1.1

Please look at my coding too..

-----------------------------------
Zren
Mon Jan 07, 2013 9:03 pm

RE:Making breakable blocks in a game
-----------------------------------

            if tiles (x, y) = 1 then
                Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, red)
            else
                Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, black)
            end if


-----------------------------------
SAValkyrie
Tue Jan 08, 2013 7:30 pm

Re: Making breakable blocks in a game
-----------------------------------
That repeating Input.Keydown was a mistake I guess. I realized there's no need to state it again. 
 But drawing each tiles, I am not quite sure what is the difference from what I did, 


body procedure reDraw
% Setting different states of a tile.
% Number 0 state in a textfile is a walkable background tiles.
    for x : 0 .. 69
        for y : 0 .. 69
            if tiles (x, y) = 1 then    % Number 1 state is not walkable tiles and breakable tiles.
                Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, red)
            else
                Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, black)
            end if
            
            if tiles (x, y) = 2 then    % Number 2 state is not walkable tiles and breakable ones that does not have items.
                Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, blue)
            else
                Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, black)
            end if
            
            if tiles (x, y) = 3 then    % Number 3 state is not walkable tiles and breakable tiles that has items in it.
                Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, blue)
            else
                Draw.FillBox (x * 10, y * 10, x * 10 + 10, y * 10 + 10, black)
            end if
            
        end for
    end for
end reDraw

Doesnt this procedure draws each tile according to the number based on a tile file based map?  
Also for the last example, I do not understand quite understand how to wrap them under a function together or do something etc. 
Our group is not so good at turing, trying to learn while we do this program ...[/list]

-----------------------------------
Zren
Wed Jan 09, 2013 10:36 am

RE:Making breakable blocks in a game
-----------------------------------
> But drawing each tiles, I am not quite sure what is the difference from what I did, 

You end up breaking larger problems/routines into smaller ones.

~

What is the outcome of those if statements? Run through it in your head. What happens when in a single iteration of those loops (which represents a single tile) if tiles(x,y) is equal to 1? Now if it were 2? 3?

I think the whole if; else if; else if; ...; else; pattern slipped your mind there.

~

The difference is that for each tile state, only the colour is variable. The things that are the same are the x1, y1, x2, y2 coordinates that specify the position of the tiles. Well, for a single tile, they don't change/move from frame to frame.

Which means you could break it up into something like:

[code]
draw():
    for each tile:
        drawTile(tileX, tileY)
        
drawTile(tileX, tileY):
    tileState = ...
    Draw.Box(x1, ..., getTileColour(tileState))
    
getTileColour(tileState):
    if tileState equals ____:
        result ____
    else if tileState equals ____: 