Jump to content
  • Advertisement

N.O.W.

Sign in to follow this  
  • entries
    3
  • comments
    6
  • views
    7173

overtime and an SDL joystick / gamepad

Sign in to follow this  
Wrathnut

2013 views

So for a few weeks I have been working on coloring the art for the over world map from the sketches I received from my artist. Apparently my skills with photoshop could use some serious improvement! I have put in about 20 hours so far and I think I still have at least that many to go. I am getting the effect I was looking for so I am pretty happy.

[size="3"][heading]"Time is an illusion... lunch time doubley so!" - Douglas Adams[/heading]

As is the way of it, I started doing some serious overtime at work two weeks ago( looks like it will continue for a couple more weeks too). Due to my ridiculously long commute it was easier to stay in town at my brother's place than to come home. Otherwise a 12 hour day turns into a 16 hour day. Needless to say I don't have a laptop that has any of the art programs I need to continue work. But I do have visual studio on it. So I decided to figure out a gamepad for Bash.

I have never worked with a joystick or gamepad before as this is the first platformer I have worked on. Looking around at examples of input control for SDL on the net all I seem to find is event based control systems.

[size="3"][subheading]Burn the witch![/subheading]
I don't particularly like event based control systems. Now before the pitchforks and torches are passed around and appropriate chants are agreed upon let me say that they ARE useful. Event based systems(not just keyboard or controller input) solve a fair number of problems. It just seems to me that they are a bit over-used(is it just me??) and not the best solution in every case. Being programmers we should evaluate our tools in our toolbox and pick the best one for the job and not just go along with the latest fad.

The above rant aside I figured what the hell it can't be that hard! And it really isn't! The code posted below it the result of an hour or so's work. It is not a fully fleshed controller class but it is functional enough to replicate the Super NES controller. Meaning I am more interested to know if something is being held down or just pressed. Hence the identifiers DOWN and PRESSED. Down is being actively held down. Pressed will only register 1 time when it is pressed. It won't register a press until it is released and held down again.

SDL Controller

gamepad.h

#pragma once
#include
#include
#include "button.h"
#include "SDL.h"
#include "vector2d.h"

using namespace std;

class gamepad
{
public:

string name;
bool available;
int availableButtons;
int availableHats;

vector2d axis, axis_old;
int hat, hat_old;
float threshold;

gamepad(void);
~gamepad(void);

void init(void);
void update(void);

void addButton(string name, int number);
void setButton(string name, int newNumber);

bool isButtonDown(string name);
bool isButtonPressed(string name);

bool stickUp(void);
bool stickDown(void);
bool stickLeft(void);
bool stickRight(void);

bool stickPressedUp(void);
bool stickPressedDown(void);
bool stickPressedLeft(void);
bool stickPressedRight(void);

bool hatUp(void);
bool hatDown(void);
bool hatLeft(void);
bool hatRight(void);

bool hatPressedUp(void);
bool hatPressedDown(void);
bool hatPressedLeft(void);
bool hatPressedRight(void);

bool state(int num);

private:
vector
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!