Oct
14
2012

Rampart Prototype

Basic “seed fill” is now working (see the link for some info). Idea is to make small Rampart style test game.

– Using alexzzz’s c# fast floodfill (see previous post comments section for source)
– Area is now checked everytime you paint a pixel, if closed areas are founded, set their color to green.

#Update:1
– Added script sample, added Image#3, Image#4, Webplayer v2.0

Done:
– Use 3D view instead  (see image#2 below) *done
– Add floodfill to that, for now: instantiate founded inside floor pieces as invidual blocks.. *done (later create single floor mesh by code?)
– Add diagonal fill? (not yet)
– Can place walls, cannons can be placed only on floor areas
– Flood gets added by flood fill
– Connect neighbour walls (change the mesh, when user adds new piece next to it) *See image#5 below
– Create object[] array? (for checking what object is at the specific grid cell..or just raycast?) : Now using object[] array.
– Destruction? How? And how to remove floor when piece of wall is destroyed? : Objects are in array, easier to keep track..
– Basic enemies (for testing) : v3.0, added random wall destruction, now if wall is destroyed, you lose castle area..
– Added: Cannon gets destroyed, if its not inside castle.


TODO:

– Cannons are not yet saved anywhere..(can place multiple at the same spot..)
– Optimization: Too many objects.. Each floor piece is invidual plane, walls are invidual blocks, build mesh instead?
– Resources? Have to mine ore / stone / gold?
– Better camera controls
– 3D grid? Could build higher walls..?
– More enemies (for testing, for example balls that roll toward your castle, you need to place cannons to destroy them)
– Cannons that shoot with physics or precalculated path?
.

Webplayer:
http://unitycoder.com/upload/demos/Rampart_prototype_unity/  (v1.0 : seedfill test)
http://unitycoder.com/upload/demos/Rampart_prototype2_unity/  (v2.0 : 3D scene test)
http://unitycoder.com/upload/demos/Rampart_prototype3/  (v3.0 : can build, area is calculated, random walls are destroyed..)

.
Purchase Current Version Source (same features as v3.0 webplayer)
1eur [digishop id=”7″]
*Note: Has bugs, not too many comments included (feel free to ask), not finished etc.
**Note: If the download link is broken, email me and I’ll send a new one :

Image#2: 3D view for placing the walls (current features: zoom in/out, rotate view, place walls)

Script #1: When user inserts a new wall, check neighbour cells (above-right-bottom-left) and then place a prefab that connects to neighbours (v1.0).. Seems bit complicated and its still missing the neighbour cell updates, to make them connect to the new piece also)

// get 'unique' value for all surrounding cells added together
var cells:int = walls[x,y+1];
cells += walls[x+1,y]*4;
cells += walls[x,y-1]*8;
cells += walls[x-1,y]*16;
var wallIndex:int=0; // default wall
switch (cells)
{
case 0: wallIndex = 9; break;
case 1: wallIndex = 13; break;
case 4: wallIndex = 14; break;
case 8: wallIndex = 15; break;
case 16: wallIndex = 12; break;
case 20: wallIndex = 10; break;
case 9: wallIndex = 11; break;
case 5: wallIndex = 6; break;
case 17: wallIndex = 4; break;
case 12: wallIndex = 8; break;
case 24: wallIndex = 2; break;
case 28: wallIndex = 1; break;
case 25: wallIndex = 3; break;
case 21: wallIndex = 5; break;
case 13: wallIndex = 7; break;
case 29: wallIndex = 0; break;
}
// create wall
Instantiate(wallPrefabs[wallIndex], gridPosition, wallPrefabs[wallIndex].rotation);
// TODO: change neighbour walls to connect this new wall
// all 0-4 neighbour walls should do the same as above, check neighbour cell values
// and then replace it with correct block that connects to all of them..?

Image#3: Values received from the script above, when use inserts a wall in the middle, based on that value we pick what prefab to use..
(# = wall, diagonal neighbours are not checked)

Image#4: Wall prefab wallIndex’es:

Image#5: Walls now connect to neighbour walls


10 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch Instagram

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.