Making breakable blocks in a game
Author |
Message |
SAValkyrie
|
Posted: Mon Jan 07, 2013 8:39 pm Post subject: 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..
Description: |
|
Download |
Filename: |
BOMBERMAN_CPT HANDIN.zip |
Filesize: |
2.55 MB |
Downloaded: |
66 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Zren
|
Posted: Mon Jan 07, 2013 9:03 pm Post subject: RE:Making breakable blocks in a game |
|
|
code: |
% ---------------------------- KEYBOARD ------------------------------------
Input.KeyDown (chars)
% ---------------------------- PAUSE ---------------------------------------
Input.KeyDown (chars)
|
Why call the method twice there?
Also, why not create a third state your map cells can be? Similar to how state=0 is air/walkable, state=1 is wall/unwalkable. State=2 is breakable block/unwalkable.
A bomb exploding would change the state from 2 -> 0.
I suggest a function for checking you collisions similar to:
code: |
fcn isTileWalkable(tileX, tileY) :boolean
result ...
end
|
That way you only have to change one spot when adding a new tile state rather than in all 8 if statements.
I'd also suggest you do a procedure for drawing a single tile.
code: |
proc drawTile(tileX, tileY, x,y)
|
Basically, if you find yourself repeating or copying code, you should analyse the changes you're making in the copied code. Since you've established that the parts you are changing are var-i-a-ble, you could pretty much write a function to wrap that code with a parameter that represents that variableness.
Example: What is the difference your tile states have, and what is common amongst them?
Turing: |
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
|
Posted: Tue Jan 08, 2013 7:30 pm Post subject: 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,
Turing: |
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 ...[/url][/list]
|
|
|
|
|
|
Zren
|
Posted: Wed Jan 09, 2013 10:36 am Post subject: 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 ____: <-- HINT HINT
...
else if tileState equals ____:
...
...
else:
... <-- Backup for reading a state that can't be parsed by this version of the program
|
|
|
|
|
|
|
SAValkyrie
|
Posted: Wed Jan 09, 2013 6:01 pm Post subject: Re: Making breakable blocks in a game |
|
|
Oh I see..
Also for the collision with the bomb and the block, would it be better to use the distance between the two points? (e.g. rectangle vs rectangle or center of a circle vs center of a circle etc.)
Or the whatdotcolor?
whatdotcolor seems pretty good but the problem is that there are limitations in the colors that turing can support....
If I am going to use whatdotcolor, is there a way to find out RGB numbers of a turing color that I am going to be using? Also maybe a hex number?
Just need some good advice from a person who actually knows well about turing lol
|
|
|
|
|
|
SAValkyrie
|
Posted: Wed Jan 09, 2013 8:29 pm Post subject: Re: Making breakable blocks in a game |
|
|
Sorry for asking too much questions but one more appeared when I was doing my coding for the main game.... I hope you don't mind answering that too.
So that coding is a part of my key input for dropping the bomb down on the screen where the character currently is. However when I press 'z' keyboard button, the picture of the bomb just appears on my character and it doesnt stay on the spot when the character moves. Also the bomb picture disappears when I press the button. I tried putting in the delay too but I could not figure out how to do this. So if you also have a solution for fix this, I will be very grateful to get an advice on this problem
Thanks.
|
|
|
|
|
|
SAValkyrie
|
Posted: Thu Jan 10, 2013 7:42 pm Post subject: Re: Making breakable blocks in a game |
|
|
We were supposed to submit our beta version of the game today however we weren't able to because of this problem again
I am not blaming or doing anything. I am just saying this problem has been very big to us.
Making a bomberman game but when I press 'z' button to put down the bomb, the picture of a bomb just appears on a character and it doesnt stay in the same spot then the character moves.
Our group has been stuck on this part for a long time, we are getting really desperate... If anyone can please answer this problem for us I will be so thankful
|
|
|
|
|
|
Zren
|
Posted: Thu Jan 10, 2013 10:45 pm Post subject: RE:Making breakable blocks in a game |
|
|
Well first off. The bomb shouldn't be drawn relative to the player. You can initialize the bombs coordinates to the current coordinates of the player, but always making them relative to the player basically means they'll move when the player moves.
I'm going to assume you want to be able to place more than one bomb at a time.
Why does placing a bomb (in the actual bomberman game) always center on a tile? It is never placed half on one tile, and half on another. What system that's already in place could you use to store when a bomb is on a particular tile?
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
SAValkyrie
|
Posted: Fri Jan 11, 2013 10:10 am Post subject: Re: Making breakable blocks in a game |
|
|
Quote:
Well first off. The bomb shouldn't be drawn relative to the player. You can initialize the bombs coordinates to the current coordinates of the player, but always making them relative to the player basically means they'll move when the player moves.
I thought of that, but I really have no clue how to it. Do I have to use locate? I do not know how to find a current location of a character and make the bomb drop on that coordinates. I guess our group chose something too har.d.
|
|
|
|
|
|
Insectoid
|
Posted: Fri Jan 11, 2013 12:38 pm Post subject: RE:Making breakable blocks in a game |
|
|
Give the bomb its own set of coordinates instead of using the character's coordinates.
|
|
|
|
|
|
SAValkyrie
|
Posted: Fri Jan 11, 2013 2:51 pm Post subject: Re: Making breakable blocks in a game |
|
|
I was finally able to fix this problem!!!!!!!!!!!!!
Thank you for all the help I really appreciate it
|
|
|
|
|
|
|
|