Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 22 Jun 2008
Offline Last Active Aug 23 2012 04:54 AM

Posts I've Made

In Topic: SDL light effects

20 July 2012 - 11:33 PM

Yea I was thinking of doing this but if I wanted more then one torch I would have trouble

You could implent a basic lightmap:

Setup an array as big as your screen:
uint8_t lightmap[SCREEN_SIZE];

- Reset lightmap to 0 (black)
- Do one pass and fill this lightmap, you would basically take your lightsources, fill in whites in your lightmap at their position (use some fade out formula so it gets darker further away from the light source)
- Alpha blend (multiplicative blend) the screen with your lightmap

Although, doing this in software is gonna be pretty slow if you use a high resolution.

In Topic: Win32 disable or get around key repeating (only check if up or down once)

13 January 2012 - 07:18 PM

Use two input buffers, that way you can keep track of key presses and releases. I use something like this:

static char key_state[2][NUM_KEYS];
static int curinput = 0;

// this is called every frame
void update_input(void)
    curinput ^= 1; // flip to next buffer index
    memset(key_sate[curinput], 0, NUM_KEYS); // clear it

    // now process all the input events and populate
    // our key_state buffer, do it in your WndProc, your event loop,
    // sdl, or whatever
    // i use sdl, but translate into my own key codes
    Uint8 *state = SDL_GetKeyboardState(&n);
    translate_sdlkeys(key_state[curinput], state, n);

// now you can query these two states for key presses and releases like so:

// is_key_press:
// key is down this frame AND was not down last frame
key_state[curinput][key] && !key_state[curinput^1][key];

// is_key_release:
// key is up this frame AND was down last frame
!key_state[curinput][key] && key_state[curinput^1][key];

// if you just wanna know if the key is up or down, just query the current state
key_state[curinput][key] // 1 on down, 0 on up

Obviously wrap that up in functions or your input class, but that is the gist of it.

In Topic: Best Resolution for 2D games

12 January 2012 - 04:50 PM

This is fine for a 4:3 ratio screen but if you if you do this on a 16:9 screen, guess what? It gets stretched out.

Thats why I go for the users native resoultion. and position things relative (not absolute). From my understanding, this is what the AAA game dev's do.

But the thing about 2D games is that changing the screen resolution can significantly change the gameplay or feel of the game because of how they usually use planar coordinates.
Diablo 2 widescreen "hack" is a good example of this, the oringinal game has quite a narrow view to limit your visibility for monsters, but using the widescreen hack you gain a huge view of the surrounding area and get quite a different experience of the game.
In 3D games this effect isn't felt that much because most of the action takes place along the z-axis ("dow/ninto" the monitor)

In Topic: Help with a timer problem?

16 November 2011 - 08:59 AM

Just store the last time the cursor moved, and if the current time minus the last time is greater than some threshold then move again.

struct cursor {
	float x, y;
	int last_tick;

cursor c;
cur_tick = get_current_time_in_ms();
if (key up pressed && key is repeated) { // can't remember how you check this in SDL, think there's some flag or something in the keyevent that tells you if it's a repeated key (key being held down)
	if ((cur_tick - c.last_tick) >= 1000) { // if you hold down the up key, the cursor will take 1 second (1000 ms) to move to the next stop
		move cursor up;
		c.last_tick = cur_tick; // update the time it last moved
} else if (key up pressed && not repeated) {
// just move without checking time, but still update last_tick
   move cursor up;
   c.last_tick = cur_tick;

In Topic: Trouble making performance consistent on Windows and Linux. [solved]

08 September 2010 - 03:34 PM

Original post by mhagain
Have a look here: http://www.gamedev.net/community/forums/topic.asp?topic_id=339475

Apparently SDL_GetTicks is a no-go area on Windows. Might be better off #ifdef'ing it out and using timeGetTime instead (don't forget to use timeBeginPeriod (1) first).

SDL_GetTicks uses timeGetTime on Windows, and it sets timeBeginPeriod to 1 (although it depends on how you compile SDL, it has a USE_GETTICKCOUNT macro definition it checks for).