Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

878018 Posts in 32899 Topics- by 24324 Members - Latest Member: Fi_designer

May 21, 2013, 02:34:46 AM
  Show Posts
Pages: [1] 2 3 ... 6
1  Developer / DevLogs / Re: ¡Cacto Loco! on: May 16, 2013, 06:41:43 PM
when are u going to post that namescreen music u promised to post?
2  Developer / Design / Re: A strategy game idea: Interlocked economies-of-scale (and other ideas) on: May 15, 2013, 07:32:59 PM
IMHO its overcomplex.
Sure it adds to the reality in the game, but does it add to the fun?
3  Developer / Design / Re: Some idea for an X4 on: May 15, 2013, 12:07:09 PM
Hmm...

Have a pre-set orbit for each planet around a star. The planet will traverse the orbit. If there's another planet within a constant distance of that planet, make a link with it.

The problem is figuring out an ellipse's mathematical formula.
4  Developer / Unpaid Work / Re: The Cat & The Castle looking for programers and artists! on: May 13, 2013, 04:37:12 PM
maild u, Zeunel
5  Developer / Tutorials / Game writing tips & design patterns (C++) on: May 12, 2013, 05:12:05 AM
Hello.

I write games in C++, using SDL and OpenGL (mostly). Here I will update and maintain a list of snippets that you might find useful. I post this in the tutorial section because you could learn from it.

I'll begin with an SDL Event handling system.
events.h:
Code:
#ifndef EVENTS_H_INCLUDED
#define EVENTS_H_INCLUDED

#include "SDL.h"

class EventHandler
{
public:
    virtual void handle(const SDL_Event sdl_event) = 0;

    EventHandler();
    ~EventHandler();
};

void updateEvents();

#endif

events.cpp:
Code:
#include <deque>
#include "events.h"

std::deque<EventHandler*> handlers;

EventHandler::EventHandler()
{
    handlers.push_back(this);
}

EventHandler::~EventHandler()
{
    bool found = false;
    for(unsigned int i = 0; i < handlers.size() && !(found); i++)
    {
        if(handlers[i] == this)
        {
            found = true;
            handlers[i] = handlers[handlers.size() - 1];
            handlers.pop_back();
        }
    }
}

void updateEvents()
{
    SDL_Event sdl_event;
    while(SDL_PollEvent(&sdl_event) > 0)
    {
        for(unsigned int i = 0; i < handlers.size(); i++)
        {
            handlers[i]->handle(sdl_event);
        }
    }
}

This is basically a listener that registers once it's instantiated. Read more: http://en.wikipedia.org/wiki/Observer_pattern

Now, let's say you want to use the event handling system I showed above.
Let's write a mouse class!
mouse.h:
Code:
#ifndef MOUSE_H_INCLUDED
#define MOUSE_H_INCLUDED

class MouseEventHandler;

class Mouse
{
public:
    friend MouseEventHandler;

    enum ButtonState
    {
        BUTTONSTATE_UP,
        BUTTONSTATE_DOWN
    };

private:
    ButtonState  left;
    ButtonState  middle;
    ButtonState  right;
    unsigned int x;
    unsigned int y;
    signed int   offx;
    signed int   offy;

public:
    bool         isLeftButtonDown()   const { return left   == BUTTONSTATE_DOWN; }
    bool         isMiddleButtonDown() const { return middle == BUTTONSTATE_DOWN; }
    bool         isRightButtonDown()  const { return right  == BUTTONSTATE_DOWN; }
    bool         isLeftButtonUp()     const { return left   == BUTTONSTATE_UP; }
    bool         isMiddleButtonUp()   const { return middle == BUTTONSTATE_UP; }
    bool         isRightButtonUp()    const { return right  == BUTTONSTATE_UP; }
    unsigned int getX()               const { return x; }
    unsigned int getY()               const { return y; }
    signed int   getXOffset()         const { return offx; }
    signed int   getYOffset()         const { return offy; }

    Mouse();
};

extern Mouse mouse;

#endif
mouse.cpp:
Code:
#include "mouse.h"
#include "events.h"

Mouse mouse;

class MouseEventHandler : public EventHandler
{
public:
    void handle(const SDL_Event sdl_event)
    {
        switch(sdl_event.type)
        {
        case(SDL_MOUSEBUTTONDOWN):
            switch(sdl_event.button.button)
            {
            case(SDL_BUTTON_LEFT):
                mouse.left = Mouse::BUTTONSTATE_DOWN;
                break;
            case(SDL_BUTTON_MIDDLE):
                mouse.middle = Mouse::BUTTONSTATE_DOWN;
                break;
            case(SDL_BUTTON_RIGHT):
                mouse.right = Mouse::BUTTONSTATE_DOWN;
                break;
            }
            break;
        case(SDL_MOUSEBUTTONUP):
            switch(sdl_event.button.button)
            {
            case(SDL_BUTTON_LEFT):
                mouse.left = Mouse::BUTTONSTATE_UP;
                break;
            case(SDL_BUTTON_MIDDLE):
                mouse.middle = Mouse::BUTTONSTATE_UP;
                break;
            case(SDL_BUTTON_RIGHT):
                mouse.right = Mouse::BUTTONSTATE_UP;
                break;
            }
            break;
        case(SDL_MOUSEMOTION):
            mouse.x = sdl_event.motion.x;
            mouse.y = sdl_event.motion.y;
            mouse.offx = sdl_event.motion.xrel;
            mouse.offy = sdl_event.motion.yrel;
            break;
        }
    }
};

MouseEventHandler mouse_event_handler;

Mouse::Mouse() :
        left(BUTTONSTATE_UP),
        middle(BUTTONSTATE_UP),
        right(BUTTONSTATE_UP),
        x(0),
        y(0),
        offx(0),
        offy(0)
{
}

Please note that for the mouse to work, you need to use the mouse in the header. Don't instantiate your own. However, for unit testing, you could write your own handler & use that. I didn't make it a singleton just because of unit testing. More about singletons: http://en.wikipedia.org/wiki/Singleton_pattern

By the way, to see it in action:
main.cpp:
Code:
#include <exception>
#include "SDL.h"
#include "events.h"

#define GAME_NAME "Sample Game 1"

bool running = true;

class WindowEventHandler : public EventHandler
{
public:
    void handle(const SDL_Event sdl_event)
    {
        if(sdl_event.type == SDL_QUIT)
        {
            running = false;
        }
    }
};

int main(int argc, char* argv[])
{
    try
    {
        if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
        {
            throw(std::runtime_error(SDL_GetError()));
        }
        SDL_WM_SetCaption(GAME_NAME, NULL);
        if(SDL_SetVideoMode(852, 480, 0, SDL_OPENGL) == NULL)
        {
            throw(std::runtime_error(SDL_GetError()));
        }

        WindowEventHandler window_event_handler;
        while(running)
        {
            updateEvents();
        }

        SDL_Quit();
    }
    catch(std::runtime_error& error)
    {
        fprintf(stderr, "%s", error.what());
        return 1;
    }
    
    return 0;
}

More will come, so stay up to date!
6  Developer / Collaborations / Re: Composer needed for CactoLoco on: May 12, 2013, 04:47:21 AM
pmd yee
7  Developer / Unpaid Work / Re: Young, Bright Minded Writer looking for a team! on: May 12, 2013, 04:40:52 AM
pmd yee
8  Developer / Technical / Re: Creating a win32 window on: May 09, 2013, 06:31:59 AM
Uh... You're talking about portability but using win32? Hmm... Does not compute.
9  Developer / Collaborations / Re: Indie Studio Looking To Make First Game on: May 09, 2013, 06:00:56 AM
Hi.
I'm a programmer.

Do you have any finished work to show us? I don't want to have my time wasted.
10  Developer / Technical / Re: Creating a win32 window on: May 09, 2013, 06:00:06 AM
Why not use SDL?
11  Developer / Design / Re: Making a game disturbing on: May 03, 2013, 04:13:30 PM
Play on human instincts.
Humans don't like when they have no power over a situation.
Humans don't like when they are put in a corner.
Humans don't like when things don't go as planned.
12  Developer / Design / Some idea for an X4 on: May 03, 2013, 05:28:41 AM
So I dreamed about a concept for an X4 kind of a game. For some reason, I don't see it happen anywhere but it seems to add alot of depth to the game without adding complexity.

The idea is as follows:
You're in space (duh). Space isn't static (duh). Wait, it is in most X4. Why?
Make planets move around stars, and stars move in galaxies. Neighboring planets change, so the passable route also changes.

The pros:
* The "map" changes. It's like destructible terrain in other RTS, but without destruction.
* Allows for interesting concepts like "Grab your chance to move to that galaxy before the planets move away! The next alignment will occour in half an hour". Could be awesome of this galaxy was rich in resources! The place is kinda defended by the map, but also generates alot of "heat" in it's vicinity.
* Adds an element of "planning for the future". Perhapes you should colonize this planet, because it will become harder to defend in the future. Or maybe you should colonize and defend this planet everybody passes through, because in the future it will become a dead end?
* Dynamic chokepoints. No more obvious bottlenecks. A bottleneck can become an intersection, and the opposite.
* To sum up these, there's another layer to decision making. Where do I place my army? What planets do I colonize? A secluded planet at the moment can become a huge battlefield in an hour, if the solar systems align in a specific order.
The cons:
* Difficulty to implement... or not?

Think of more, woah. You could play one map for days, and never get bored. It constantly changes! Sure, it changes cyclicly (you will get the same state once in say, four hours). It also adds the option to make "passing-by-galaxies" that join the map for sometime, and then go away. The possibilities are endless!

I wonder why nobody does that. I will probably hack up a prototype someday.
Could be interesting to see what any one of you could come up with based on this concept.
13  Developer / Design / Re: Ways to explain death and retry on: May 03, 2013, 05:18:48 AM
Haha, that's awesome!  Big Laff
Personally, I've been entertained. And if you analyse it objectively, you'd see that it's adding depth to the thing (replayability, yay).

How about this:
* You die, go to heaven. God says, "You're too young to die". You're banished back to earth with a sad face (no heaven for you!)
* You die, death comes for you. Death says: "Oh, it's you again!", and "I found your death amusing. Let's see if you can make an even better one!", and doesn't take you.
Or perhaps death says "Lol, it's you again. Loser! Anyway, I pity you. Get the fuck back to life."
14  Developer / Collaborations / Re: AlphaWolfGames Expanding The Robot Universe Online Game Development Team on: May 03, 2013, 04:21:04 AM
Contacted you on Skype.
Then again, this reply is probably useless because you wouldn't check tigsource.
15  Developer / Technical / Re: [Java] Object/Class Design for Games? on: May 03, 2013, 04:18:11 AM
You'd probably require an events polling class, events handling classes (like Input registration), a game logic class (doing all the game mechanics), a renderer (duh), perhaps a scenegraph, a physics thingy, rules class, UI class, state class... You'll need aLOt of classes.
Pages: [1] 2 3 ... 6
Theme orange-lt created by panic