Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Nausea

Member Since 25 Nov 2012
Offline Last Active Oct 26 2014 06:12 PM

Topics I've Started

SFML 2.0 Bitmap font with different colors?

28 November 2013 - 08:19 PM

Hey!

 

So, I've worked on creating a little application with bitmap fonts. I can add color on top of the text without any issue.

However, I would like to know how I would go about being able to change the color for different parts of the text.

 

For example:

"Testing ^4this ^2thing", where ^4 would tell the application that the font after it should be red, and the ^2 being say yellow.

 

I thought about it and it feels like I would need to split the string up at those points and then create a new sprite for the following text. Does this sound like a good idea? Because I felt like this would be very bad if the original string was very large.

 

Any advice would be great.

Thanks

 

 

edit:

So I tried going about it in another way and I'm getting a strange behavior. I'm checking if the current letter is a '^' and if so, is the next letter a '1'. 

If it is, set the color to blue. It does this but somehow the letter before '^' also gets the blue color, I'm at a loss here. Can't figure out why.

else if(Text[show] == '^')
{			
	if(Text[show+1] == '1')
	{
	   sf::Color BlueColor(0,0,255);
	   FontSprite.setColor(BlueColor);
	   show = (show + 1);					
	}
}

[SDL] map with animated tiles. performance question.

24 June 2013 - 06:27 PM

Hi!

 

I've tried to get animated tiles to work on my tile map and I've run into what may be a problem going forward.

I'll try to explain how I have it constructed in my code.

 

First:

My map class stores two vectors, one with tiles (one of each kind) and one vector stores "tile slots".

It also holds a tile sheet.

 

Second:

My tile class handles updating the sprite animation, only changes coordinates for the target sprite. 

Handles frame rate etc.

 

It also holds an ID to connect this with a tile slot ID.

 

Third:

My tile slot class holds ID, type, and x/y for where to draw them on the map.

ID is used to link it to a tile during rendering.

 

....

I did it like this because it was the only way I could think of, this way I could make it so that I only need to update the animation once per tile.

However, when I need to draw the tile slots for where the animated tile will be drawn I run into the problem of having to go through all tile slots and then go through all tiles to draw the correct tile at the correct place.

I can cut down on some of it by checking if the tile slot is inside of the camera, but this still leads to going through the entire tile slot vector.

 

My worry is that this will be very taxing on the computer when I get to the point of making a full fledged map. Not to mention when I will have to in some way check for collisions with the tile slots.

 

I wish that someone could maybe give some input on this.

 

Thank you!


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


PARTNERS