Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 05 Mar 2012
Offline Last Active Jun 25 2014 02:29 PM

Topics I've Started

Help with implementing smooth mario movement

24 June 2014 - 01:26 PM

Hey there people,


I'm creating a very simple Mario clone for myself and i'm trying to create a smooth movement for Mario, I'm using C++ and SFML for this project,

This is the code I have at the moment

void State::KeyboardEvent(sf::Event event)
	if (state == GameStates::GS_Level1)
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
			//Set move right to true
			Characters.at(0).UpdateMovement(2, 0);
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
			//Set move left to true
			Characters.at(0).UpdateMovement(-2, 0);

This works but not smoothly at all, when the D or A key is pressed down, Mario will move once, then he will continue after about a second delay, it's like holding key down on your keyboard, it will type a letter, but if you keep it held down it will repeat that character, I'm thinking the best way is to maybe set a state, so if A key is pressed set mario state to moving left, and when a is released change the state to stopmoving and once speed is 0 set state to not moving, but i can't really find a good site explaining this and was hoping for some help from your guys,


Any idea on how I should implement this?

How to structure a SFML game?

19 June 2014 - 07:44 AM

Hello there fellow programmers,

This is going to be a big question so get ready. First off I have attempted to create quite a few games with C++ and SFML, programming the functionality isn't to hard, but after a few weeks, or months or even days my structure does always seem to mess up, what I mean by that is, due to something I did way back means i have to amend something new to fix that problem but some of my old functions are using that function, this happens all the time and I completely understand it is my fault for not fully understanding the structure of my game or the program.

So basically I am trying to create a simple clone of Mario Bros, so we have a title screen, a character, some enemies, a map made of blocks, score, time, lives, levels, continues, projectiles etc. So here is the my problem, using SFML i have myself a imageService, soundService and musicService, now these basically just load a file and store it inside of a map so I can call on that file when I need. But here is the main problem

I have a State which has a ImageService, the state has a hero and a level, would I assign them each a image? for example hero.sprite = imageService.images["heroImg"]; would that be the best way? Second lets say if a level had some blocks, but some blocks are infront of the hero, would I have to write out my render function to say

//Draw level blocks

//Draw hero

//Draw upper level blocks

//Draw menu


But then a really big important part is, the renderwindow is 800 by 600, in most computer games the user is allowed to change the size of the game, so lets say the user wants to display 1280 by 768, where would be the best place to draw the sprites differently? What about collision detection? if the view was 800 by 600 and now it is 1280 by 768 the width has go up by 1.5 and a bit and the height has changed by 168 pixels, would I save a global variable in my state which has the "ratios" of the screen? so 800 by 600 = 1:1 and 1280 by 768 = 1.6:1.28 would I then use that to modify all sprites displaying and also use that to modify collision detection?

I'm just really trying to get my head around the structure of a game, does anyone have any simple links to books or articles on how to structure one, or even better a tutorial on how to structure a simple SFML game.

How do I implement a simple 2D torch effect on screen with GLSL with SFML

26 May 2014 - 04:01 PM

Hello there gamedev community smile.png


At the moment i'm creating a basic 2D game with the help of SFML and good old C++. Now if you look at the image attached below, the left part is what I have so far, but the right side is something i would like to implement, now I know the image on the right is just a simple radial fill rectangle with the middle part transparent and the edges not transparent.


I'm trying to achieve a basic darkness around the edges of the screen and brightness at the centre (like a torch effect in a dungeon crawler). I feel like the openGL shader would be the best option for this, but I have to admit my skills with C++ and SFML are good enough to create this game, but my openGL shader knowledge is basically non-existent, I just wanted to ask first off, is a shader the best option for this? Second, if yes, could you provide some shader code or some information on where I can learn openGL shaders, Third, if no, could you provide why a shader would not be the best idea and how I should achieve this effect.


The effect is something similar to this, but of course my game is only in 2D not 3D and the torch would flicker.vYljM.jpg




C++ and SFML game structure help

10 May 2014 - 06:19 AM

I'm in the early stages of a game I would love to create and i'm trying to work out how the game program should be structured (classes, headers etc). I'm using C++ and SFML for this project.

Let me first by showing you my basic image of the structure. Don't pay attention to MainMenuState.cpp and NewGameState.cpp


Game.cpp will have an instance of all those services, it will also have the MainMenuState, NewGameState and LevelState. Now here is my problem.

Game.cpp will have a method that will call the RenderService.RenderWindow, I'm trying to work out exactly how I should code this method? Should I pass in an arrayList of sf::sprites? If I do this, the LevelState.cpp will need an ArrayList of sf::Sprites. which will be updated on each game step. But lets say the Hero.cpp has 1 sf::Sprite. the Map.cpp has 20 sf::sprites and Monster.cpp has 1 sf::Sprite. this would mean I have to pass 22 sf::Sprites back to the RenderService every game step (60fps). so that is 1320 sf::Sprites per second back to the RenderService. I understand game structure is a very hard thing to do and hard to implement correctly, because there isn't a "set" way. I have created a Vector which holds sf::Sprites and every time I call my Render function I clear the vector before so everything is removed for memory. This works fine. Would that be the answer? But as I stated before is passing a lot of sf::Sprites to be rendered ok?




Here is my simple SFML program to test this

#include <SFML/Graphics.hpp>
#include "ImageService.h"
#include "DisplayObject.h"
#include "Enums.h"

ImageService is;
DisplayObject displayObject;

int main()
	sf::RenderWindow window(sf::VideoMode(1024, 768), "SFML works!");
	sf::CircleShape shape(100.f);

	std::vector<sf::Sprite> displayObjects;

	while (window.isOpen())

		sf::Event event;
		while (window.pollEvent(event))
			if (event.type == sf::Event::Closed)


		//Draw out the selected sprites
		for (int i = 0; i < displayObjects.size(); i++)


	return 0;

Let me know if you would like me to explain any part of my program

Website to upload game for free

10 December 2013 - 02:33 PM

Hey there people,


I'm looking for a website or a program like steam where I can upload my game for free so anyone can download my game for free and play it. Just want to get my games our there and don't mine allowing people to download them for free. Is there any such website or software? My games are mostly focused around C++