Sign in to follow this  

Rebuilding My Project

This topic is 2959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been having issues with communication between objects. I am using Model, Behavior, Movement method. I have the structure planned out as well as what each Entity(?) will need to know/send. The main problem I have been having is the Grid system which is going to go through a rigorous re-planing process. I will need help in order to complete this and get it working. Details of the Grid: Contains a vector list of Nodes that can be accessed using the [] operator. GridObject[NodeIndex]->X; The Nodes on the Grid are 16x16. The Grid and Node layout is shown below.
//Has been tested & still incomplete
#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <SDL.h>
#include <SDL_Image.h>

struct Node
{
	//State
	enum nType {isDEAD, isNOTHING, isBUILDING, isFOLIAGE, isPERSON};
	bool Empty;
	nType Type;
	//Location
	bool OnScreen;
	int x, y;
	//Animation Details
	short int TotalImages;
	short int OnImage;
	std::vector<SDL_Surface*> ImageList;
	SDL_Surface* ShowMe;
	//Constructor
	Node(void)
	{
		Empty = true;
		Type = isNOTHING;
		x = 0;
		y = 0;
		ShowMe = NULL;
		TotalImages = 0;
		OnImage = 0;
		ImageList.clear();
	}
	//Update function
	bool Update()
	{
		if(ImageList.size()-1 == TotalImages)
		{
			if(ShowMe != NULL)
				SDL_FreeSurface(ShowMe);
			ShowMe = NULL;
			ShowMe = SDL_DisplayFormat(ImageList[OnImage]);
			OnImage++;
			if(ShowMe != NULL)
			{
				return false;
			}
			if(OnImage >= TotalImages)
			{
				OnImage = 0;
			}
			return true;
		}
		else
			return false;
	}
	//ImageList Cleaner
	bool Kill()
	{
		if(Type == isDEAD)
		{
			while(!ImageList.empty())
			{
				SDL_Surface* Temp = NULL;
				Temp = SDL_DisplayFormat(ImageList.front());
				ImageList.erase(ImageList.begin());
				if(Temp != NULL)
					SDL_FreeSurface(Temp);
			}
			ImageList.clear();
			return true;
		}
		return false;
	}
	//Deconstructor
	~Node(void)
	{
		Type = isDEAD;
		Kill();
	}
};

class GGrid
{
private:
	//Node vector
	std::vector<Node*> NodeList;
	//Grid Details
	bool TimeToKill;
	unsigned short int Gw, Gh;
	//Grid Positioning
	int offsetx, offsety;
public:
	GGrid(void);
	bool OpenFile(std::string filename);
	bool SaveFile(std::string filename);
	void KeyPressed(const int &Key);
	void KeyReleased(const int &Key);
	bool Kill(void);
	~GGrid(void);
	Node* operator[] (unsigned int num)
	{
		if(num < NodeList.size())
		{
			return NodeList[num];
		}
		return NULL;
	}
};

GGrid::GGrid(void)
{
	TimeToKill = false;
	Gw = 0;
	Gh = 0;
	offsetx = 0;
	offsety = 0;
}
bool GGrid::OpenFile(std::string filename)
{
	NodeList.push_back(new Node);
	return false;
}
bool GGrid::SaveFile(std::string filename)
{
	return false;
}
void GGrid::KeyPressed(const int &Key)
{
	if(Key == SDLK_LEFT) {
		offsetx = -5;
	}
	else if(Key == SDLK_RIGHT) {
		offsetx = 5;
	}
	if(Key == SDLK_UP) {
		offsety = -5;
	}
	else if(Key == SDLK_DOWN) {
		offsety = 5;
	}
}
void GGrid::KeyReleased(const int &Key)
{
	if(Key == SDLK_LEFT) {
		offsetx = 0;
	}
	else if(Key == SDLK_RIGHT) {
		offsetx = 0;
	}
	if(Key == SDLK_UP) {
		offsety = 0;
	}
	else if(Key == SDLK_DOWN) {
		offsety = 0;
	}
}
bool GGrid::Kill(void)
{
	//Check for errors in the Grid
	if(!TimeToKill)
	{
		std::vector<Node*>::iterator NodeIt = NodeList.begin();
		while(!TimeToKill && NodeIt != NodeList.end())
		{
			Node* Temp = *NodeIt;
			TimeToKill = Temp->Kill();
			NodeIt++;
		}
	}
	//Destroy the Grid
	if(TimeToKill)
	{
		while(!NodeList.empty())
		{
			Node* Temp = NodeList.front();
			Temp->Type = Node::isDEAD;
			TimeToKill = Temp->Kill();
			NodeList.erase(NodeList.begin());
			delete Temp;
		}
		NodeList.clear();
	}
	//return any errors
	return TimeToKill;
}
GGrid::~GGrid(void)
{
	TimeToKill = true;
	Kill();
}


Here is what I need the Grid system to accomplish: Note: Numbers marked with * can be or have been accomplished. Lines with a Roman numeral at the end are described below the heading it is under. Loading/Saving: 1*. Load/Save Grid terrain files and place the textures on the right node index. 2. Load/Save building location, type, statistics, and the buildings file.(I) 3*. Load/Save people location, details, and the person's file.(II) I. Buildings have separate files that define the shape of the building. The file contains the name of the image file, clipping, and animating instructions. Some building might have a custom shape or have custom animations(such as a waterfall or windmill). The shape of the building is the issue. I'm unsure how to handle this. There will be areas of a building that will 'hangover' people and that can be walked on. There will be empty areas of a building that can also be walked on. Most buildings will contain an entrance tile that people will have to walk to and 'disappear' into. Some buildings will have a removable cart that can be pushed by the workers of that building(Farmers) or of another(Teamsters). Buildings will also need to have a 'reserved' area for upgrades(such as carts). II. People have a .anm file that holds the name of the image file, clipping and animating instruction. The Grid system will have to Load/Save the Grid index location of the person's house and job location as well as the location of the person itself. Updating: 1. The player will need to be able to add buildings to the Grid. The buildings will only be placed if there are 2 layers of empty nodes around the building.(I) 2*. The Grid will need to be able to move when arrow keys are pressed or if the mouse is held and dragged. (I)This issue was discussed in the previous heading. Rendering: 1*. The terrain of the Grid should not be drawn unless the node is in the view of the player. 2*. Grid lines will need to be drawn if the feature is turned on. This is all that I can think of so far. Do you have any advice on how to achieve the setting of the buildings? Or Any advice as to how I should/could be handling the Grid System? Thanks [Edited by - rpg gamer 17 on November 5, 2009 9:39:05 PM]

Share this post


Link to post
Share on other sites

This topic is 2959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this