Jump to content

  • Log In with Google      Sign In   
  • Create Account

aanthonyz1

Member Since 22 Feb 2011
Offline Last Active Mar 29 2016 12:44 AM

Topics I've Started

Making my game code cleaner/easier to work with

28 March 2016 - 04:29 PM

Hello, so for the past week I have been working on a 2D SFML game written in C++ but the more I program, the more it starts to get disorganized. Aside from how I name my methods. I feel like my code is all over the place.
 
 
There are alot of files so for an easy example of what im talking about, look at my GameEngine and stdafx files since I feel that's where the source of my problem is. Also is there anything I could remove and incorporate into Lua? I hear alot of people use it for their game logic instead of hardcoding it into the game. Any advice would be appreciated.
 
 
GameEngine.cpp
#include "stdafx.h"
#include "GameEngine.h"

GameEngine::GameEngine(void)
{
	GameState = Uninitialized;
	GameTitle = "2D SFML RPG";
	ScreenWidth = 1920;
	ScreenHeight = 1080;
	Section = 0;
	GameView.reset(sf::FloatRect(0,0,ScreenWidth,ScreenHeight));
	GameView.setViewport(sf::FloatRect(0,0,1,1));
}

void GameEngine::Start()
{
	if(GameState != Uninitialized)
		return;
	
	GameWindow.create(sf::VideoMode::getDesktopMode(), GameTitle);
	GameWindow.setFramerateLimit(30);
	GameWindow.setVerticalSyncEnabled(true);
	Running = true;
	GameState = State::Title;
	Loop();
}

void GameEngine::Loop()
{
	while(Running)
	{
		GameWindow.setView(GameView);
		GameWindow.clear();
		Event(GameState);
		switch(GameState)
		{
			case State::Title:
				Menu.Show(GameWindow);
				break;
			case State::CharacterCreation:
				CCreate.Show(GameWindow);
				MapLocation = Location::HomeTown;
				break;
			case State::Play:
				MapSelection();
				break;
		}
		GameWindow.display();
	}
}

void GameEngine::Event(State GState)
{
	while(GameWindow.pollEvent(event))
	{
		if(event.type == sf::Event::Closed)
			Running = false;
		switch(GState)
		{
			case State::Title:
				Menu.Event(GameState,Running,event,GameWindow);
				break;
			case State::CharacterCreation:
				CCreate.Event(GameState,Running,event,GameWindow,Character);
				break;
			case State::Play:
				GameMap.Event(GameState,Running,event,GameWindow,GameView);
				Character.Event(event,GameWindow,GameView,PlayerLocation);
				TestNPC.Event(event);
				break;
		}
	}
}

void GameEngine::MapSelection()
{
	switch(MapLocation)
	{
		case Location::HomeTown:
				GameMap.Show(GameWindow);
				Character.Show(GameWindow);
				TestNPC.Load(MapLocation);
				TestNPC.Show(GameWindow,PlayerLocation);
				break;
	}
}

GameEngine::~GameEngine(void)
{
}

GameEngine.h

#pragma once

#include "MainMenu.h"
#include "CharacterCreator.h"
#include "Map.h"

class GameEngine
{
private:
	sf::RenderWindow GameWindow;
	sf::Event event;
	sf::View GameView;
	int ScreenHeight;
	int ScreenWidth;
	int Section;
	char *GameTitle;
	bool Running;
	sf::Sprite PlayerLocation;
	MainMenu Menu;
	CharacterCreator CCreate;
	Map GameMap;
	Player Character;
	NPC TestNPC;
	Location MapLocation;
public:
	GameEngine(void);
	~GameEngine(void);
	void Start();
	void Loop();
	void Event(State GState);
	void MapSelection();
};

stdafx.h

#pragma once
enum Location {HomeTown, Dungeon1};
static Location MapLocation;
#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
#include <string>
#include <iostream>
#include <fstream>
#include <SFML\Graphics.hpp>

#include "Player.h"
#include "NPC.h"

enum State {Uninitialized, Splash, Title, CharacterCreation, Play};
static State GameState;

static sf::Color Red = sf::Color(255,0,0);
static sf::Color Black = sf::Color(0,0,0);
static sf::Color White = sf::Color(255,255,255);

Terrain Generation

02 January 2015 - 11:54 PM

Currently im working on Terraria clone in SFML and was wondering how I should approach terrain generation. After looking into it for a bit I found libnoise and was able to create this heightmap:

 

http://imgur.com/XKch0Ou

 

The problem is I dont know how to proceed after that. I dont know how to turn it into a 2D form of terrain and then be able to turn it into something I can use tiles with like a numerical array.

 

I dont know if im making this harder than it seems but I was also thinking of randomly filling a 2D array and using that for my terrain instead but I dont know how to limit the range that certain blocks may appear on for example like grass only being at the top, etc.

 

If you can help me with my suggestions or have any of your own, your help will be appreciated.


Other Uses for Graphic Libraries

09 September 2014 - 09:51 AM

So the main thing that comes to mind well for me at least when it comes to graphic libraries is incorporating them to create video games. Anyone know of examples that use them for other purposes? Im asking because being that my art is abysmal and I dont have the patience for it, rather than create a game I would enjoy and have more fun making an actual program like Blender as an example that may incorporate it in some way. Any help or pointers in the right direction will be greatly appreciated.


Creating Pixel Art

07 September 2014 - 12:01 PM

Hello, can anyone guide me in the right direction for creating pixel art in the style of these 3 examples?

 

https://www.kickstarter.com/projects/1054244612/c-wars-roguelike-pixel-art-pc-game

 

http://media.tumblr.com/0227ef17327e317a89829d4b4b52c629/tumblr_inline_mm014sUgzP1qz4rgp.jpg

 

 

Any help would be appreciated.


Sprite Animation

14 May 2014 - 10:59 AM

This is a question for people who know alot about animation or who have made games using sprite animation. What is the recommended number of frames for each different animation that the character does? I know some will take more than others like combo attacks, etc but overall for example lets say just walking, how many frames are recommended for something as simple as that?


PARTNERS