Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Nausea

Member Since 25 Nov 2012
Offline Last Active May 20 2013 10:05 AM
-----

Topics I've Started

UI: move-able windows (z-order)

29 March 2013 - 06:19 AM

Hey!

 

I've run into a problem with my noobish UI setup. I have a Vector that stores all my windows. When the mouse is clicked I go through the windows vector and check if the mouse is inside any of the windows. If it is i move that window relative to the mouse position.

 

Now my problem is: How do I order the window selected to be in front? and since the mouse can be inside 2 windows during my check the last window it's inside will always be the one selected. 

 

I know I should probably be using a z-order of some kind, but I just can't work out where to set it for a window and how to adjust the other accordingly.

 

I'll just post some code of the way I check if the mouse is inside a window.

void CGame::OnLButtonDown(int _mousex, int _mousey)
{
	

	for(unsigned int i=0; i < WindowList.size(); i++)
	{
	
		if(!WindowList[i]->GetShow()) //dont do any checks if the window is hidden.
		{
		
			continue;
		
		}

		if(_mousex >= WindowList[i]->GetX() && _mousex <= (WindowList[i]->GetX() + WindowList[i]->GetW() ))
		{
		
			if(_mousey >= WindowList[i]->GetY() && _mousey <= (WindowList[i]->GetY() + WindowList[i]->GetH()))
			{


				CurrentWindow = i;
				WindowList[i]->SetMouseDown(true);
				WindowList[i]->SetDifference(_mousex - WindowList[i]->GetX(), _mousey - WindowList[i]->GetY());

				
				for(unsigned int itemnum = 0; itemnum < WindowList[i]->WindowItemList.size(); itemnum++)
				{
				
					if(_mousex >= WindowList[i]->WindowItemList[itemnum]->GetX() && _mousex <= (WindowList[i]->WindowItemList[itemnum]->GetX() + WindowList[i]->WindowItemList[itemnum]->GetW()))
					{
					
						if(_mousey >= WindowList[i]->WindowItemList[itemnum]->GetY() && _mousey <= (WindowList[i]->WindowItemList[itemnum]->GetY() + WindowList[i]->WindowItemList[itemnum]->GetH()))
						{
							
								if(!WindowList[i]->WindowItemList[itemnum]->GetActive()) //if the item is not an active item (such as a divider), don't do any checks for it.
								{
									continue;
								}
								else
								{
									
									OverActiveItem = true;

									if(WindowList[i]->WindowItemList[itemnum]->GetType() == ITEM_TYPE_CHECKBOX)
									{
										WindowList[i]->WindowItemList[itemnum]->Toggle();
									}

								
								
								}
								

						
						}
					
					}

				
				}

				

			}
		
		}
		
	}


}


 

 


Game: Health regeneration?

01 March 2013 - 04:31 PM

Hey!

So I've been working on a health bar which shrinks and grows according to how much health your character has.

The problem is I don't know how to add a smooth increment to health regen. 

Say if I want to gain 600 life over 4 seconds, how would I go about achieving this? Will I have to use float numbers, and in what way? The health bar checks how many pixels the bar should shrink and grow depending on the health value.

 

This is my code right now.

CHealthBart.cpp

void CHealthBar::OnRender(SDL_Surface* _destination)
{

	SDL_FillRect(_destination, &BarBackground, SDL_MapRGB(_destination->format, 0, 0, 0));

	if( (float)Owner->GetCurrentHealth() / Owner->GetMaxHealth() > 0.6f )
	{
		SDL_FillRect(_destination, &Bar, SDL_MapRGB(_destination->format, HighHealth.r, HighHealth.g, HighHealth.b));
	}
	if ( (float)Owner->GetCurrentHealth() / Owner->GetMaxHealth() <= 0.6f && Owner->GetCurrentHealth() / Owner->GetMaxHealth() < 0.25f )
	{
		SDL_FillRect(_destination, &Bar, SDL_MapRGB(_destination->format, AverageHealth.r, AverageHealth.g, AverageHealth.b)); 
	}
	if( (float)Owner->GetCurrentHealth() / Owner->GetMaxHealth() <= 0.25f)
	{
		SDL_FillRect(_destination, &Bar, SDL_MapRGB(_destination->format, LowHealth.r, LowHealth.g, LowHealth.b)); 
	}
	
}

void CHealthBar::OnLoop()
{

	BarBackground.x = Owner->GetX();
	BarBackground.y = ( Owner->GetY() - 5 ); 

	Bar.x = ( Owner->GetX() + 1 );
	Bar.y = ( Owner->GetY() - 4 );

	float tempw = (float)Owner->GetCurrentHealth() / Owner->GetMaxHealth();
	Bar.w = MaxBarLength * tempw;

}

 

Would be great if someone could give a good answer on this.


Classes that need to know each other..

01 March 2013 - 09:17 AM

Hey, so since I am a noob I found myself stuck on a small problem. And the problem is that I have a Entity class that contains a Healthbar instance and I need the healthbar to contain a pointer to its owner (the entity). And this is where I got stuck.

 

CEntity class:

#ifndef _CENTITY_H_
#define _CENTITY_H_

#include "SDL.h"

class CEntity
{

	public:
		CEntity();
		~CEntity();

	public:
		bool OnInit();
		void OnRender(SDL_Surface* destination);
		void OnLoop();

		int GetX();
		int GetY();

		int GetW();
		int GetH();

		int GetMaxHealth();
		int GetCurrentHealth();

	private:
		SDL_Rect Image;
		
		CHealthBar HealthBar;
		int MaxHealth;
		int CurrentHealth;

		int LastHurtTime;

};

#endif

 

CHealthBar class:

#ifndef _CHEALTHBAR_H_
#define _CHEALTHBAR_H_

#include "SDL.h"

class CHealthBar 
{
	
	public:
		CHealthBar();
		~CHealthBar();

	public:
		bool OnInit();
		void OnRender(SDL_Surface* _destination);
		void OnLoop();

		void SetOwner(CEntity* _owner);

	private:
		CEntity* Owner;

		SDL_Rect BarBackground;
		SDL_Rect Bar;

		int MaxBarLenght;

		SDL_Color HighHealth;
		SDL_Color AverageHealth;
		SDL_Color LowHealth;

};

#endif

 

 

The compiler complains about this to no end, what should I do about this? Is this not a good way to handle the way a healthbar is connected to an entity? I've tried to include them here and there to no success, even tried to forward declare and still not getting it to work.

 

Thanks


Animated tiles, need some input

10 January 2013 - 12:00 PM

Hey,

So I was thinking of how I would go about creating tiles which will be animated. I think I have a pretty good idea, but I just wanted to see what some more well versed people think about it.

My thought is to have a Tileframe class that will just have X/Y coordinate for where from the image the picture will be drawn. The tile class will then have a list (vector) of tileframes that animation will loop over. The map class will then have a list of tiles. The map will handle all the saving and loading of map information to and from a binary file.

Does this sound like a good approach?

For map editing will I have to have one of each available tile hardcoded into the game that a new placed tile will copy it´s information from (animation etc) ?

Would be great to have some input, and maybe some alternative ways. And if this would be bad for performance in any way or if it´s a bad idea to save so much for a pretty simple tile map.

Thanks

Namespaces good for anything else?

03 December 2012 - 05:16 PM

Hi.

So I been wondering if namespaces is good for anything else but preventing name collisions?
For example: Using a namespace to make it clearer what belongs to a game engine.

If you can tell me any other uses, please do.

Thanks

PARTNERS