Game Idea in mind..some questions

BlitzMax Forums/BlitzMax Programming/Game Idea in mind..some questions

ckob(Posted 2007) [#1]
Ok so I have a game idea I want to try and create....recreate anyway, What are the quickest ways to do the following:

1:) In the game players build their own castle walls I need to snap each castle piece to the previously placed piece or closest wall.

2:) The players will get scored based on speed of repairs and ability to close off their castle walls so I need a way to determine if the castle is completely enclosed. I was thinking the easiest way might be to create a list of all the created castle blocks and go through each block making sure they are colliding with two of the other blocks.

Any help or examples would be much appreciated I am planning on using MiniB3d but its been a couple months since I've really got back into coding.


Gavin Beard(Posted 2007) [#2]
i guess for number 1) u could have some kind of grid system snapping each piece to a cell on the grid, then u can check the grid of the neighbors of the piece u have just placed, but keeping the layout of the grid in a 2d array you could then solve point 2) by scanning thru the array, when u get to a block in the grid checking the array around that block e.g if you get to element 2,2 of the array and it contains a piece of wall check check 2,1 - 2,3 - 1,2 - 3,2 to see if they contain a connected piece, thus you'll know if the wall is complete or not. hope this makes sense or helps


ckob(Posted 2007) [#3]
yeah it helps thanks a ton just needed a clear picture :)


Gavin Beard(Posted 2007) [#4]
glad to help, must be the first time ever hehehe, what game u making a remake of, sounds like .....erm think it was called rampart...if so......yay


ckob(Posted 2007) [#5]
yeah rampart :) I don't know if I have the time to do it but I started it ages ago with a friend in Blitz3d and never finished it so I figured I would revisit it and try it out in blitzmax.


Gavin Beard(Posted 2007) [#6]
u should def. go for it, i love playing rampart on my psp


FlameDuck(Posted 2007) [#7]
Rampart rocked!


*(Posted 2007) [#8]
agreed, it was like Tetris with castles and cannons :)


ckob(Posted 2007) [#9]
well I have a pretty long list of failed projects...mainly because of time but I figure maybe this will be something I can work on when I have the few hours a day.


Curtastic(Posted 2007) [#10]
Reaserch up on flood-fills to check if the castle is enclosed. Checking if each tile is touching 2 others won't cut it.

And I loved 2-player rampart on snes. So make it!


ckob(Posted 2007) [#11]
Right I have been working on the design (on paper) and the bricks touching each other method of checking isn't going to work because it wont know if the castle is enclosed. I tried searching up on 3d flood fill but could only find some 2d flood fill stuff so if anyone has any ideas by all means share them.


Jake L.(Posted 2007) [#12]
Isn't 2D-Floodfill all you need? If you start at your castle and a floodfill can reach a point outside the visible area (a invisible line/row out of the battlefield will do it), then your walls are not closed.

Ok, this would be a bruteforce approach, but assuming a grid like 20x20 or so it would be fast anyway.

Maybe I don't understand fully what you want to do. I played rampart ages ago...


FlameDuck(Posted 2007) [#13]
You could use a union-find type algorithm. If each wall segment represented an edge on a grid, you would know that an area is enclosed for all edges in a given set if they share any vertices.

Right?


slenkar(Posted 2007) [#14]
why dont you just do pathfinding, to see if a path can find its way out of the castle?


LarsG(Posted 2007) [#15]
assuming you can represent as a 2D grid (array);
make a list if the castle walls when the user places them.
work through the list from start to finish, checking each wall part is a "legal" one next the the last.
then when you to the last entry, check to see if itīs next to the first one.. if it is, the caste is closed.


Paul "Taiphoz"(Posted 2007) [#16]
cKob I finished ramparts off I might still have the code on one of my slave drives, if I find it, it will be winging its way to you.


Paul "Taiphoz"(Posted 2007) [#17]
Nope don't have it any more, I just upgraded to a AMD duel core and some other neat stuff and iv lost a lot :(

I can tell you what I did tho in the end.

First of all I setup a tilemap, I think mine was 32*32. I then made my sprites 52*32 to give a little hight and the illusion of depth.

The walls were fun to code, I started out by simply setting a tile to 1, each time I placed a part of a wall a function called linkwalls was called.

link walls scanned 6 tiles. top left to bottom right, row by row.

Tile 1 looked like this.

A#==
##==

=====
=###
=#A#
=###

# - shows the tiles being looked at by the link walls function and the A is the centre tile.

in the linkwalls function I simply checked of the tiles I was looking at, which had wall parts, and if any were touching, I would change the tile value to represent the proper wall part.

Man I feel so sick and I'll right now so I hope this make seance to you and I hope it does not just come out as verbal puke.


ckob(Posted 2007) [#18]
ill have to reread it later right now it doesn't make sense :P thanks though for offering some advice.