Jump to content

  • Log In with Google      Sign In   
  • Create Account


Shawn Greer

Member Since 06 Aug 2009
Offline Last Active Jul 22 2014 09:51 AM
-----

Topics I've Started

Android - Partial Transparency

02 July 2012 - 02:03 PM

Hello all. I'm laying out the design for a game on the Android using openGL ES, and I've stumbled upon an issue that I can't seem to find a solution for. I'm looking to be able to draw something on the screen, like a wall, then have a character pass behind the wall. When the character is behind the wall, I'm looking to apply an auro of transparency on the wall in front of the character, enabling you to see the character behind, without making the entire wall transparent.

Any help anyone could offer any help, or at least point me in the right direction, I'd greatly appreciate it.

Shawn

Android - partial transparency

02 July 2012 - 01:55 PM

Hello all. I'm laying out the design for a game on the Android using openGL ES, and I've stumbled upon an issue that I can't seem to find a solution for. I'm looking to be able to draw something on the screen, like a wall, then have a character pass behind the wall. When the character is behind the wall, I'm looking to apply an auro of transparency on the wall in front of the character, enabling you to see the character behind, without making the entire wall transparent.

Any help anyone could offer any help, or at least point me in the right direction, I'd greatly appreciate it.

Shawn

State management

27 August 2009 - 12:48 PM

First off, I know there's already a lot out about state management. However, I couldn't find anything that could help answer the question. I've got the basic idea of the states down, using the method put forth here: http://gamedevgeek.com/tutorials/managing-game-states-in-c/ Basically create a vector of states. The problem I'm having, is that I don't know how to go about filling out the handleEvents function of the state itself, specifically regarding any of the windows and message events. Do I have to write my own message handler class, then push messages through to it? Any help, or a nudge in the right direction would be appreciated. The applicable code is here. Most of it is just an empty shell as I've just been trying to get the handleEvents function working. <gameState.h>
#ifndef GAMESTATE_H
#define GAMESTATE_H

#include "gameEngine.h"
#include "windows.h"

class GameState
{
public:
	virtual void init() = 0;
	virtual void cleanUp() = 0;
	virtual void pause() = 0;
	virtual void resume() = 0;

	virtual void handleEvents(GameEngine* game) = 0;
	virtual void update(GameEngine* game) = 0;
	virtual void draw(GameEngine* game) = 0;

	void changeState(GameEngine* game, GameState* state) {
		game->changeState(state);
	}

protected:
	GameState() {}
};
#endif

introState.h
#ifndef INTROSTATE_H
#define INTROSTATE_H

#include "gameState.h"
#include "windows.h"

class IntroState : public GameState
{
public:
	void init();
	void cleanUp();
	void pause();
	void resume();

	void handleEvents(GameEngine* game);
	void update(GameEngine* game);
	void draw(GameEngine* game);

	static IntroState* instance() {
		static IntroState m_IntroState;
		return &m_IntroState;
	}

protected:
	IntroState() {}
};

#endif

gameEngine.h
#ifndef GAMEENGINE_H
#define GAMEENGINE_H

#include <vector>
#include "windows.h"

using namespace std;

class GameState;

class GameEngine
{
public:
	bool init(HINSTANCE& hInstance, int& showCmd);
	void cleanUp();
	void changeState(GameState* state);
	void pushState(GameState* state);
	void popState();

	void handleEvents();
	void update();
	void draw();

	bool running();
	bool quit();


private:
	vector<GameState*> states;
	bool mRunning;

	WNDCLASSEX	wcx;
	HWND		ghMainWnd;
	HINSTANCE	ghAppInst;
};

#endif

gameEngine.cpp
#include "gameEngine.h"
#include "gameState.h"

void GameEngine::init(HINSTANCE& hInstance, int& showCmd)
{
	mRunning = true;

	ghAppInst = hInstance;

	wcx.cbSize = sizeof(WNDCLASSEX);
	wcx.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wcx.lpfnWndProc = WndProc;
	wcx.cbClsExtra = 0;
	wcx.cbWndExtra = 0;
	wcx.hInstance = ghAppInst;
	wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wcx.lpszMenuName = NULL;
	wcx.lpszClassName="Tetris Clone";
	wcx.hIconSm = NULL;

	RegisterClassEx(&wcx);

	ghMainWnd = CreateWindowEx(0, "Tetris Clone", "Tetris Clone", WS_BORDER | WS_SYSMENU | WS_CAPTION| WS_VISIBLE,
		500, 200, 320, 272, NULL, NULL, ghAppInst, NULL);

	ShowWindow(ghMainWnd, showCmd);
	UpdateWindow(ghMainWnd);
}

void GameEngine::cleanUp()
{
	while ( !states.empty() ) {
		states.back()->cleanUp();
		states.pop_back();
	}
}

void GameEngine::changeState(GameState *state)
{
	if ( !states.empty() ) {
		states.back()->cleanUp();
		states.pop_back();
	}

	states.push_back(state);
	states.back()->init();
}

void GameEngine::pushState(GameState *state)
{
	if ( !states.empty() ) {
		states.back()->pause();
	}

	states.push_back(state);
	states.back()->init();
}

void GameEngine::popState()
{
	if ( !states.empty() ) {
		states.back()->cleanUp();
		states.pop_back();
	}

	if (!states.empty() ) {
		states.back()->resume();
	}
}

void GameEngine::handleEvents() 
{
	// let the state handle events
	states.back()->handleEvents(this);
}

winMain.cpp
#include "windows.h"
#include "gameEngine.h"
#include "introState.h"
#include "gameState.h"

int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmdLine, int showCmd)
{
	GameEngine game;
	game.init(hInstance, showCmd);

	game.changeState( IntroState::instance() );

	while (game.running()) {
		game.handleEvents();
	}

	game.cleanUp();

	return 0;
}


PARTNERS