Untitled

Published August 21, 2006
Advertisement
lolz i maek gaem!!1`1

Granted. Its kind of a hack - it injects events directly into the GUI to make the buttons change colors during the 'instructions' phase because I was too lazy to write stuff to do it a more logical way. Granted, you shouldn't be able to see that.

Hur hur hur.
Previous Entry Untitled
Next Entry Untitled
0 likes 2 comments

Comments

HopeDagger
Awesome. Now add online support and it'll be the next big thing. Simon MMORPG!
August 21, 2006 10:20 PM
Mushu
Here's the cleanest code I've ever written*

#include "GUI.h"
#include "SDL_Events.h"
#include "SDL_Window.h"
#include "OGL_Gfx.h"
#include "OGL_Textures.h"
#include "OGL_Font.h"

#include "Log.h"

#include "Button.h"
#include "TextBox.h"
#include "Label.h"

#include <vector>

using namespace pain::sdl;
using namespace pain::ogl;
using namespace pain::gui;
using namespace pain::log;
using namespace pain::core;

struct SimonEvent {};

class ISimonButton :
	public IButton,
	public HandlerList< SimonEvent >
{
protected:
	unsigned long _lightTime;
	unsigned long _unlightTime;

public:
	USE_HANDLER_LIST( SimonEvent );

	void light( DWORD time ) {
		// highlight the button
		MouseDownEvent mde;
		mde.button = BUTTON_LEFT;
		mde.x = getX();
		mde.y = getY();

		IComponent::raiseEvent( mde );

		// count down timer
		_lightTime = time;
	}

	void unlight( DWORD time ) {
		// do nothing, just set the timer
		_unlightTime = time;
	}
};

typedef std::vector<ISimonButton*> ComboBreakerType;
ComboBreakerType combolist;
ComboBreakerType::iterator currcombo;
unsigned long combotime = 50000;
unsigned long combountime = 5000;
unsigned long flashtime = 200000;
int startInstructionCount = 3;

template < class GfxAdapter, class Style = Style< GfxAdapter, 0 > >
class SimonButton :
	public ISimonButton,
	protected Style
{
	GfxAdapter* _gfx;
	
public:
	USE_HANDLER_LIST( SimonEvent );
	USE_HANDLER_LIST( ButtonEvent );

	explicit SimonButton( GfxAdapter* gfx )
		: _gfx( gfx )
	{}

	virtual void render( int rel_x, int rel_y ) {
		int x = getX() + rel_x;
		int y = getY() + rel_y;
		int w = getW();
		int h = getH();

		_gfx->fillRect( x, y, w, h, _cShadow );
		_gfx->fillRect( x+(isPressed() ? _sBorder : 0), y+(isPressed() ? _sBorder : 0), w-_sBorder, h-_sBorder, _cHighlight );
		_gfx->fillRect( x+_sBorder, y+_sBorder, w-2*_sBorder, h-2*_sBorder, (isPressed() ? _cHighlight : _cFront ) );
	}

	virtual void update( unsigned long step ) {
		// only operate if we still have lighttime
		if ( _lightTime > 0 ) {

			// subtract the light time
			if ( step >= _lightTime ) {
				_lightTime = 0;

				// send another event to return the button to normal
				MouseUpEvent mue;
				mue.button = BUTTON_LEFT;
				mue.x = getX();
				mue.y = getY();

				IComponent::raiseEvent( mue );

				// set to the unlight state.
				_unlightTime = combountime;
			}
			else {
				_lightTime -= step;

				// check to see if the damned thing is still lit.
				if ( !isPressed() ) {
					// if not, light it

					MouseDownEvent mde;
					mde.button = BUTTON_LEFT;
					mde.x = getX();
					mde.y = getY();

					IComponent::raiseEvent( mde );

					// because of a dirty dirty event code hack (injecting
					// events into the GUI results in somewhat undefined
					// behavior.
				}
			}

		} else if ( _unlightTime > 0 ) {
			
			// subtract from unlight time
			if ( step >= _unlightTime ) {
				_unlightTime = 0;

				// send a custom event to notify that the animation is done
				SimonButton::raiseEvent( SimonEvent() );
			}
			else {
				_unlightTime -= step;
			}
		}
	}
};

static bool running = true;
GfxAdapter gfx;
typedef Style<GfxAdapter, 1> hStyle1;
typedef Style<GfxAdapter, 2> hStyle2;
typedef Style<GfxAdapter, 3> hStyle3;
typedef Style<GfxAdapter, 4> hStyle4;
ISimonButton* buttons[4]; // hack.
SimonButton<GfxAdapter,hStyle1> button1( &gfx 
August 21, 2006 10:26 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Untitled

5308 views

Untitled

1043 views

Untitled

1185 views

Untitled

1100 views

Untitled

1145 views

Untitled

1429 views

Untitled

1098 views

Untitled

999 views

Untitled

1003 views

Untitled

1183 views
Advertisement