Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 3d Strategy style game
Index -> Programming, C++ -> C++ Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Tue Feb 10, 2009 4:46 pm   Post subject: 3d Strategy style game

I got kinda bored with my space game so i started working on this thing i'll get back to that one eventually.

controls :
camera: wsad and arrow keys

use mouse to select the models and click on the ground surface to tell them to move there(like starcraft)

i haven't really thought of what kind of game i want to make with this, so suggestions on the topic are welcome =)
Sponsor
Sponsor
Sponsor
sponsor
SNIPERDUDE




PostPosted: Tue Feb 10, 2009 9:44 pm   Post subject: RE:3d Strategy style game

Animations are a little sketchy, but certainly a great start. Lighting was a little harsh though. But then I'm on a really old machine, so it may actually look good at a better speed.
Homer_simpson




PostPosted: Wed Feb 11, 2009 1:43 am   Post subject: Re: RE:3d Strategy style game

SNIPERDUDE @ Tue Feb 10, 2009 9:44 pm wrote:
Animations are a little sketchy

here i've improved the code it should be much faster now even on an old computer.
CodeMonkey2000




PostPosted: Wed Feb 11, 2009 10:39 am   Post subject: RE:3d Strategy style game

Why is it so slow?
Homer_simpson




PostPosted: Wed Feb 11, 2009 11:37 am   Post subject: Re: 3d Strategy style game

i'm not sure why it would be slow Sad i get 115 frames per second and i got a crappy old ati graphic card with 32 mb memory =/
what frame rate are you getting? and what kind of computer u have?
wtd




PostPosted: Wed Feb 11, 2009 2:45 pm   Post subject: RE:3d Strategy style game

Just as a suggestion, since this is a site intended to help people learn, you may wish to submit source code as well.
SNIPERDUDE




PostPosted: Wed Feb 11, 2009 7:47 pm   Post subject: RE:3d Strategy style game

Oh yes, that's much better. Whatever you did improved the speed extraordinarily. One problem I have though is selecting characters:
1) sometimes I find it hard to find the spot where I'm supposed to click. Make it so I can click anywhere on the character no matter the angle.
2) maybe a drag select might be an idea to run with...
3) I find the fact that it deselects everytime you move the character(s) annoying.


Keep up the awesome work
Homer_simpson




PostPosted: Wed Feb 11, 2009 9:24 pm   Post subject: Re: 3d Strategy style game

i'll develop better controls thanx for suggestions.



wtd wrote:

Just as a suggestion, since this is a site intended to help people learn, you may wish to submit source code as well.


I intend to. the reason i haven't done it yet because the code is a mess i'll have to clean it up a bit.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Thu Feb 12, 2009 12:42 am   Post subject: RE:3d Strategy style game

You'll get suggestions for cleaning up the code if you show off your messy code. Wink
Homer_simpson




PostPosted: Thu Feb 12, 2009 1:50 am   Post subject: Re: 3d Strategy style game

Very Happy

alright so i've improved the controls and fixed the light glitch;

controls are exactly like starcraft for picking and moving the units u can also drag the mouse to select more than one at once.
the camera controls are the same as before arrow keys and wasd.

i still have to do collision between the bots and avoiding. but i haven't though of anything past that yet =)



data.zip
 Description:

Download
 Filename:  data.zip
 Filesize:  2.27 MB
 Downloaded:  304 Time(s)

Homer_simpson




PostPosted: Fri Feb 13, 2009 3:17 pm   Post subject: Re: 3d Strategy style game

added movement AI and collisions, i didn't spend much time debugging so report bugs plz


data.zip
 Description:

Download
 Filename:  data.zip
 Filesize:  2.27 MB
 Downloaded:  295 Time(s)

CodeMonkey2000




PostPosted: Fri Feb 13, 2009 9:40 pm   Post subject: RE:3d Strategy style game

Are you path finding?
Homer_simpson




PostPosted: Sat Feb 14, 2009 1:44 am   Post subject: Re: 3d Strategy style game

not exactly, since there can be more than 1 unit moving at the same time i check for collisions in the next frame and if there's a collision i set a temporary target point at a 90 degree angle to the original target which results in the unit moving around the obstacles.if there's a collision when moving towards the temporary taget point, the temporary target points will get recalculated.

#############################
##unit ______ obstacle _____--->target##
#########|##### /#############
#########|______/##############
#############################

it seems to work well.
I'll comment the ai code and post it.
Homer_simpson




PostPosted: Sat Feb 14, 2009 1:35 pm   Post subject: Re: 3d Strategy style game

c++:

void moveunit(unit_type &unitp)
{
    double arbx,arby,arbz;
    ///////////////////////////////action 1////////////////////////////////

    if(unitp.action==1)// if unit is in motion
    {
        for(int ucounter = 0;ucounter<MAX_UNITS;ucounter++)/// go through all units
        {
           if((distance3d(unit[ucounter].x,unit[ucounter].y,unit[ucounter].z,unitp.x+unitp.dir.vx,unitp.y+unitp.dir.vy,unitp.z+unitp.dir.vz)<2)&&(unit[ucounter].id!=unitp.id))//check for collision
                {
                if((unit[ucounter].action!=1)&&(distance3d(unit[ucounter].x,unit[ucounter].y,unit[ucounter].z,unitp.targetx,unitp.targety,unitp.targetz)<2))
                {/// if the the other unit is standing on the moving units target tell it to move
                         unit[ucounter].targetx=unit[ucounter].z+(unitp.dir.vz*2);
                         unit[ucounter].targety=0;
                         unit[ucounter].targetz=unit[ucounter].x+(unitp.dir.vx*2);
                         
                         unit[ucounter].temptargetx=unit[ucounter].z+(rand()%5);
                         unit[ucounter].temptargety=0;
                         unit[ucounter].temptargetz=unit[ucounter].x+(rand()%5);
                         unit[ucounter].temptarget=true;
                }else/// if the unit is in the way set up temporary target to move to
                {
                    unitp.temptarget=true;/// we have temporary target
                    unitp.temptargetx=unitp.x+(((unitp.z-unitp.targetz)/distance2d(unitp.x,unitp.z,unitp.targetx,unitp.targetz))*4)+(((rand()%50)/10)-2.5);//calculate temp target
                    unitp.temptargetz=unitp.z-(((unitp.x-unitp.targetx)/distance2d(unitp.x,unitp.z,unitp.targetx,unitp.targetz))*4)+(((rand()%50)/10)-2.5);//calculate temp target
                }
           }
        }
        if(!unitp.temptarget)/// if no temporary target
        {
            if((model[unitp.modelid].currentFrameIndex<40)||(model[unitp.modelid].currentFrameIndex>45))
            {
                model[unitp.modelid].SetAnimation(40,45);//set model animation
                model[unitp.weaponid].SetAnimation(40,45);
                //guideunit(unitp);
            }
            crossproduct(unitp.dir.vx,unitp.dir.vy,unitp.dir.vz,-unitp.x+unitp.targetx,-unitp.y+unitp.targety,-unitp.z+unitp.targetz,arbx,arby,arbz);// find a 90 degree axis of rotate between the unit direction and the target vector
            if(fabs(anglebetween2d(unitp.dir.vx,unitp.dir.vz,unitp.x-unitp.targetx,unitp.z-unitp.targetz)-180)<20){// if we're moving in the correct general direction move fast and rotate slow
                unitp.dir.rotateARB(arbx,arby,arbz,1);
                unitp.x+=unitp.dir.vx/2;
                unitp.z+=unitp.dir.vz/2;
           }else// if we're not looking in the right direction turn fast and move slow
           {
                unitp.dir.rotateARB(arbx,arby,arbz,+5);
                unitp.x+=unitp.dir.vx/4;
                unitp.z+=unitp.dir.vz/4;
           }
           
           if(distance3d(unitp.x,0,unitp.z,unitp.targetx,0,unitp.targetz)<4)//if we've reached the target
           {
               unitp.action=0;//stop moving
               model[unitp.modelid].SetAnimation(1,10);//set animation
               model[unitp.weaponid].SetAnimation(1,10);
           }
       
       }else//if we have temporary target repeat the same thing for the temporary targets
       {
            if((model[unitp.modelid].currentFrameIndex<40)||(model[unitp.modelid].currentFrameIndex>45))
            {
                model[unitp.modelid].SetAnimation(40,45);
                model[unitp.weaponid].SetAnimation(40,45);
            }
            crossproduct(unitp.dir.vx,unitp.dir.vy,unitp.dir.vz,-unitp.x+unitp.temptargetx,-unitp.y+unitp.temptargety,-unitp.z+unitp.temptargetz,arbx,arby,arbz);
            if(fabs(anglebetween2d(unitp.dir.vx,unitp.dir.vz,unitp.x-unitp.temptargetx,unitp.z-unitp.temptargetz)-180)<6){
                unitp.dir.rotateARB(arbx,arby,arbz,1);
                unitp.x+=unitp.dir.vx/2;
                unitp.z+=unitp.dir.vz/2;
           }else
           {
                unitp.dir.rotateARB(arbx,arby,arbz,+5);
                unitp.x+=unitp.dir.vx/10;
                unitp.z+=unitp.dir.vz/10;
           }
           
           if(distance3d(unitp.x,0,unitp.z,unitp.temptargetx,0,unitp.temptargetz)<2)//if we reached temporary target move towards original target
           {
               unitp.temptarget=false;
           }
       }
    }
    ///////////////////////////////action 1////////////////////////////////
       model[unitp.modelid].movemodel(timemove);//animate model
       model[unitp.weaponid].movemodel(timemove);
}



Mod Edit: Quotations are required around the language for the syntax tags
code:
[syntax="cpp"]Code Here[/syntax]
Homer_simpson




PostPosted: Sat Feb 14, 2009 5:46 pm   Post subject: Re: 3d Strategy style game

added terrain:

edit: updated the file,should have faster rendering using display lists.



data.zip
 Description:

Download
 Filename:  data.zip
 Filesize:  4.92 MB
 Downloaded:  380 Time(s)

Display posts from previous:   
   Index -> Programming, C++ -> C++ Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: