SFML community forums

General => SFML projects => Topic started by: Jallen on December 24, 2010, 05:08:51 pm

Title: It's Raining Snow! - A retro-arcade style Christmas game!
Post by: Jallen on December 24, 2010, 05:08:51 pm
Hey guys, I just finished this little christmas game. It took only about 7 hours but I'm really happy with how it turned out.

(http://jallenbah.co.uk/content_img/rainingsnow/1.png)

Thanks!

There's a video, info, pics and download at my site, here:
http://jallenbah.co.uk/rainingsnow.php
Title: It's Raining Snow! - A retro-arcade style Christmas game!
Post by: Spodi on December 24, 2010, 06:38:40 pm
Nice little game. Could use a little more, like an increase in difficulty over time, but still good for just a little 7 hour project. Gave up around 250k+ points. :P
Title: It's Raining Snow! - A retro-arcade style Christmas game!
Post by: AdventWolf on December 24, 2010, 07:11:09 pm
Cool game, I'd definitely add some more to it.
Title: It's Raining Snow! - A retro-arcade style Christmas game!
Post by: David2010 on December 24, 2010, 08:13:22 pm
Nice. I couldn't play it because I was missing a couple DLL's but I saw the video of it.

The snow... It burns.
Title: It's Raining Snow! - A retro-arcade style Christmas game!
Post by: Jallen on December 25, 2010, 02:25:41 pm
It requires the VC++ 2010 redist.

Thanks for the responses :)
Title: It's Raining Snow! - A retro-arcade style Christmas game!
Post by: Hugo on December 26, 2010, 12:34:50 am
Doesn't work on Linux
Title: It's Raining Snow! - A retro-arcade style Christmas game!
Post by: Jallen on December 26, 2010, 01:11:49 pm
Quote from: "Hugo"
Doesn't work on Linux


Do you mean in Wine? The only non-sfml win32 stuff I used was WinMain and ShellExecuteW for the website link on the game-over screen, so I would be surprised if it wouldn't work in Wine.
Title: It's Raining Snow! - A retro-arcade style Christmas game!
Post by: CJ_COIMBRA on January 13, 2011, 05:52:00 pm
It´s a nice and fun game!

By the way, did you wrote your own font system to use those graphics as font? If so, could you just outline how you did it?

Thanks and congratulations!
Title: It's Raining Snow! - A retro-arcade style Christmas game!
Post by: Jallen on January 13, 2011, 10:26:07 pm
Thanks. I did the font system myself, yes. I first loaded all of the character images into a std::Vector of a struct containing a character which represents that image and the sf::Image itself, so it was like

Code: [Select]
struct CharImg
{
    char cha;
    sf::Image img;
};

(using integer ascii codes is useful for this so you can loop-load them)

Then I made a function which gets a desired character image pointer, like so:
Code: [Select]

sf::Image* Font::GetCharImage(char character)
{
for(int i = 0; i < chars.size(); i++)
{
if(chars[i]->cha == character)
return &chars[i]->img;
   }

return 0;
}


Then for the font drawing, I do something like this:
Code: [Select]
void Font::DrawText(std::string string, sf::Vector2f position, sf::Vector2f scale, sf::RenderWindow* rwindow)
{
std::vector<sf::Sprite> spriteVector;
sf::Vector2f nextpos(position);

for(int i = 0; i < string.length(); i++)
{
if(string[i] == '\n')
nextpos = sf::Vector2f(position.x, nextpos.y + (10 * scale.y));
else if(string[i] == ' ')
nextpos.x += (7 * scale.x);
else
{
spriteVector.push_back(sf::Sprite(*GetCharImage(string[i]), nextpos, scale));
nextpos.x += (7 * scale.x);
}
}

for(int i = 0; i < spriteVector.size(); i++)
{
rwindow->Draw(spriteVector[i]);
}
}

So not super efficient, creating a vector of the sprites each time I want to draw the text, but I wasn't concerned with that at the time since I was on a time limit for a small competition on another forum.

As you can see, for a newline I take the initial position and add some Y to it, that will put me below the first char in the text. For a space I simply advance the X position and for any other char I display the image and advance the X position.

Hope this helped!