Best way to program?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
The Onslaught
Posts: 41
Joined: Mon Jan 29, 2007 3:33 pm

Post by The Onslaught »

3DModelerMan wrote:No way... you do kendo?
I hope not, I can't imagine rogerborg as a Kendo master
After reading this sentence you will realize you have wasted 5 seconds of your life
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Rogerborg would probably make a good Kendo instructor. You'd either learn to defend yourself within a couple days, or you'd leave.

Anyway, to actually add to the topic at hand, yes, FSM's are still used everywhere. The Source Engine's AI is heavily FSM based, running "thinking" functions every AI frame to decide which state the AI should change to.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

hmmm

Post by 3DModelerMan »

I guess so, could you recomend me some good books or tutorials on finite state machines?.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Google is your friend man....

http://www.devmaster.net/articles/fsm_intro/
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

thanks

Post by 3DModelerMan »

Thanks! :D .
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Sudi wrote:Google is your friend man....

http://www.devmaster.net/articles/fsm_intro/
It's a lost cause. He just wants to be fed, he doesn't want to learn how to use the spoon himself.
TheQuestion = 2B || !2B
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

We can't fault his tenacity though. I see him having a promising career in either politics, or panhandling.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Politics....nothing else
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

huh

Post by 3DModelerMan »

My mom said I would be a good politician too... I guess I'm just more of a modeler than a programmer, but I enjoy programming too.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

noober please,

a finite state machine and the state pattern are completely different things.

I remember when I thought that I could learn how to make commercial games in two weeks also. now I just don't worry about that and count the years as they fly by.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

ummm?

Post by 3DModelerMan »

So what would be the best way to devide this code up into different functions to where I can have different menu screens?.

Code: Select all

#include <irrlicht.h>
#include "newton.h"
#include "tumle.h"
#include "SDL.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace tumle;

//{control variables
int P1_button_press = 0;
enum P1_hat_state { UP,DOWN,LEFT,RIGHT,MIDDLE };
//}

//initialize first joystick globaly
SDL_Joystick* joystick1 = 0;

int main(int argc, char *argv[])
{
//{add classes
SDL_Event event;
//}

//{initialize SDL
if(SDL_Init( SDL_INIT_JOYSTICK|SDL_INIT_TIMER|SDL_INIT_VIDEO ) < 0)  return 1;
//}

//{create an irrlicht device
    IrrlichtDevice* device = createDevice(EDT_OPENGL, dimension2d<s32>(1024, 768), 32,
    true, false, true, 0);


    //if the device can't be created exit the program
    if (!device) return 1;

    //{pointers
     //create and check driver
     IVideoDriver* driver = device->getVideoDriver();
     if (!driver) return 1;
     //create and check smgr
     ISceneManager* smgr = device->getSceneManager();
     if (!smgr) return 1;
     //create and check guienv
     IGUIEnvironment* guienv = device->getGUIEnvironment();
     if (!guienv) return 1;
     //create and check physics manager
     IPhysicsManager* pmgr = createPhysicsManager(device);
     if (!pmgr) return 1;
     //}
     //}

//=======================================================================
//{menu screen variables
int menu_item = 1;

bool in_main_menu = true;

//}

//{add menu screen objects

//{add menu screen background image
IGUIImage* menu_bkg = guienv->addImage(driver->getTexture("menu_background.png"),
position2d<int>(0,0));
//}

//{add logo image
IGUIImage* logo = guienv->addImage(driver->getTexture("logo.png"),
position2d<int>(25,10));
//}

//{sky background
IMeshSceneNode* sky = smgr->addMeshSceneNode(smgr->getMesh("cylinder.obj") );
if (sky)
{
sky->setPosition(vector3df(0,-10,0) );
sky->setScale(vector3df(550,550,550) );
sky->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
sky->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
sky->setMaterialFlag(EMF_LIGHTING, false);
sky->setMaterialTexture( 0, driver->getTexture("menu_clouds.bmp") );
//rotation animator
ISceneNodeAnimator* rotate = smgr->createRotationAnimator(core::vector3df(0,0.04f,0));
sky->addAnimator(rotate);
rotate->drop();
}
//}

//{battle background
IMeshSceneNode* battle = smgr->addMeshSceneNode(smgr->getMesh("battlefield_stage.obj") );
if (battle)
{
battle->setScale(vector3df(3,3,3) );
battle->setPosition(vector3df(0,-10,0) );
battle->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);
battle->setMaterialFlag(EMF_BACK_FACE_CULLING, false);
battle->setMaterialFlag(EMF_LIGHTING, true);
battle->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
battle->setMaterialTexture( 0, driver->getTexture("battlefield_UV_map.png") );
battle->getMaterial(0).EmissiveColor.set(0,100,100,100);
}
//}

//{camera
ICameraSceneNode* camera = smgr->addCameraSceneNode(0, vector3df(0,5,0), vector3df(0,0,0));
ISceneNodeAnimator* fly = smgr->createFlyCircleAnimator (core::vector3df(0,5,0),130.0f, -0.0001f);
camera->addAnimator(fly);
fly->drop();
//}

//{light
//add light
ILightSceneNode* light = smgr->addLightSceneNode(0, vector3df(-15,5,-105), video::SColorf(1.0f, 1.0f, 1.0f));
//}

//{add P1 button is selected image
IGUIImage* P1_brawl_selected = guienv->addImage(driver->getTexture("pressed_button.png"),
position2d<int>(650,10));
//}

//{add P1 button image
IGUIImage* P1_brawl_button = guienv->addImage(driver->getTexture("menu_button.png"),
position2d<int>(650,10));
//}

//{add P1 button text image
IGUIImage* P1_brawl_text = guienv->addImage(driver->getTexture("P1_brawl.png"),
position2d<int>(650,10));
//}

//{add P2 button is selected image
IGUIImage* P2_brawl_selected = guienv->addImage(driver->getTexture("pressed_button.png"),
position2d<int>(650,120));
//}

//{add P2 button image
IGUIImage* P2_brawl_button = guienv->addImage(driver->getTexture("menu_button.png"),
position2d<int>(650,120));
//}

//{add adventure mode button is selected image
IGUIImage* adventure_selected = guienv->addImage(driver->getTexture("pressed_button.png"),
position2d<int>(650,230));
//}

//{add adventure mode button image
IGUIImage* adventure_button = guienv->addImage(driver->getTexture("menu_button.png"),
position2d<int>(650,230));
//}

//{add guess what button is selected image
IGUIImage* guess_what_selected = guienv->addImage(driver->getTexture("pressed_button.png"),
position2d<int>(650,340));
//}

//{add guess what button image
IGUIImage* guess_what_button = guienv->addImage(driver->getTexture("menu_button.png"),
position2d<int>(650,340));
//}

//{add guess what button text image
IGUIImage* guess_what_text = guienv->addImage(driver->getTexture("guess_what.png"),
position2d<int>(650,340));
//}

//{add quit button is selected image
IGUIImage* quit_button_selected = guienv->addImage(driver->getTexture("pressed_button.png"),
position2d<int>(650,450));
//}

//{add quit button image
IGUIImage* quit_button = guienv->addImage(driver->getTexture("menu_button.png"),
position2d<int>(650,450));
//}

//{add quit button text image
IGUIImage* quit_text = guienv->addImage(driver->getTexture("quit.png"),
position2d<int>(650,445));
//}

//{add answer image
IGUIImage* guess_what_answer = guienv->addImage(driver->getTexture("answer.png"),
position2d<int>(0,0));
guess_what_answer->setVisible(false);
//}

//}

//{error text objects

//{error text
IGUIStaticText* joy_error = guienv->addStaticText(L"Please insert a joystick or gamepad...",rect<s32>(15,1,260,22), true);
joy_error->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
joy_error->move(position2d<int>(350,350) );
//}

//}

//{open joysticks

//Open joystick1
SDL_JoystickEventState(SDL_ENABLE);
joystick1 = SDL_JoystickOpen(0);

//}

//main game loop
while( device->run() )
{
//=======================================================================

//{check joysticks
if ( SDL_NumJoysticks() < 1 ) joy_error->setVisible(true); else joy_error->setVisible(false);
if ( joystick1 == NULL ) joy_error->setVisible(true);
//}

//{menu screen logic functions

//{menu item wrapping
if ( menu_item < 1 ) menu_item = 5;

if ( menu_item > 5 ) menu_item = 1;
//}

//{menu item selection image
//=======================================================================
if ( menu_item == 1 )
{
 P1_brawl_button->setVisible(false);
 P2_brawl_button->setVisible(true);
 adventure_button->setVisible(true);
 guess_what_button->setVisible(true);
 quit_button->setVisible(true);
}
//=======================================================================

//=======================================================================
if ( menu_item == 2 )
{
 P1_brawl_button->setVisible(true);
 P2_brawl_button->setVisible(false);
 adventure_button->setVisible(true);
 guess_what_button->setVisible(true);
 quit_button->setVisible(true);
}
//=======================================================================

//=======================================================================
if ( menu_item == 3 )
{
 P1_brawl_button->setVisible(true);
 P2_brawl_button->setVisible(true);
 adventure_button->setVisible(false);
 guess_what_button->setVisible(true);
 quit_button->setVisible(true);
}
//=======================================================================

//=======================================================================
if ( menu_item == 4 )
{
 P1_brawl_button->setVisible(true);
 P2_brawl_button->setVisible(true);
 adventure_button->setVisible(true);
 guess_what_button->setVisible(false);
 quit_button->setVisible(true);
}
//=======================================================================

//=======================================================================
if ( menu_item == 5 )
{
 P1_brawl_button->setVisible(true);
 P2_brawl_button->setVisible(true);
 adventure_button->setVisible(true);
 guess_what_button->setVisible(true);
 quit_button->setVisible(false);
}
//=======================================================================

//}
//}

 while(SDL_PollEvent(&event))
    {

        switch(event.type)
        {
             case SDL_JOYBUTTONDOWN:  /* Handle Joystick Button Presses */

             if ( event.jbutton.button == 0 && in_main_menu == true )
             {
             //{ menu selection
             if ( menu_item == 1 )
              {
               in_main_menu = false;
               menu_bkg->remove();
               logo->remove();
               battle->remove();
               sky->remove();
               guess_what_answer->remove();
               P1_brawl_button->remove();
               P1_brawl_selected->remove();
               P1_brawl_text->remove();
               camera->remove();
               light->remove();
               P2_brawl_button->remove();
               P2_brawl_selected->remove();
               quit_button->remove();
               quit_button_selected->remove();
               quit_text->remove();
               guess_what_answer->remove();
               guess_what_button->remove();
               guess_what_selected->remove();
               guess_what_text->remove();
              }

             if ( menu_item == 4 )
             {
              guess_what_answer->setVisible(true);
             }

             if ( menu_item == 5 )
              {
               device->closeDevice();
               SDL_JoystickClose(joystick1);
               atexit(SDL_Quit);
               return 0;
              }

              //}
             }
             break;

             case SDL_JOYHATMOTION:  /* Handle Hat Motion */

             if ( event.jhat.value & SDL_HAT_UP && in_main_menu == true )
             {
              menu_item--;
             }
             if ( event.jhat.value & SDL_HAT_DOWN && in_main_menu == true )
             {
              menu_item++;
             }
             break;

        }
    }


//=======================================================================
 //{update the world

driver->beginScene(true, true, SColor(0,200,200,200));

smgr->drawAll();
guienv->drawAll();

driver->endScene();

//update the newton world
pmgr->update();
SDL_JoystickUpdate();
P1_button_press = 0;
P1_hat_state MIDDLE;
//}
//=======================================================================

}

device->drop();
SDL_JoystickClose(joystick1);
atexit(SDL_Quit);
return 0;

}


That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

it depends on your preference and style
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

The forum wrote:You may also post general programming questions here.
You may, but there really are limits to how much time we're going to sink into teaching C 101.

Seriously, there are plenty of general C/C++ resources out there. You don't have to keep asking these non Irrlicht related questions here.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

this cant be taught in a book or 1 time example. you may opt to join a project and learn through your peers and experience
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

ohhh

Post by 3DModelerMan »

No I just meant, should I put it all into a few headers and cpp's or is it best to do seperate levels as seperate funcs.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Post Reply