LEVELS.CPP
资源名称:tc3d.zip [点击查看]
上传用户:abcdshs
上传日期:2007-01-07
资源大小:1858k
文件大小:6k
源码类别:
游戏
开发平台:
Visual C++
- // (C) Copyright 1996 by Anthony J. Carin. All Rights Reserved.
- #include "stdafx.h"
- #include "levels.h"
- #include <io.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- const short mincamdist = VIEWRANGE/4;
- const short maxcamdist = VIEWRANGE/2;
- static void getnew(CString& path, short level, CString& filename);
- levels::levels()
- {
- Game->SetLevelNum(1);
- if (Game->Hero()->gender() == MALE)
- guy = new dude(Game->Hero());
- else
- guy = new girl(Game->Hero());
- Game->DrawQueue()->add(guy);
- coordinate tmp(0.0f,0.0f,0.0f);
- guy->setto((view) tmp);
- camdist = mincamdist;
- camrise = 0.0f;
- camangle = 0;
- camstep = 0.05f;
- camrstep = 0.02f;
- usercontrol = new control(guy);
- tmp.setto(0.0f,15.0f,0.0f);
- camera.stepto(tmp,15.0f);
- mcompleted = FALSE;
- #ifdef EDITOR
- selection = 0;
- selectionstep = 1.0f;
- selectioncolor = RGB(250,250,250);
- #endif
- }
- levels::~levels()
- {
- delete usercontrol;
- }
- void levels::draw()
- {
- Game->DrawQueue()->run();
- #ifdef EDITOR
- if (selection)
- {
- selection->setcolor(RGB(random(256), random(256), random(256)));
- }
- #endif
- usercontrol->issuecommands();
- if (!Game->Motionless() && guy->isdead())
- {
- Game->NowMotionless();
- usercontrol->falldown();
- }
- runcamera();
- }
- void levels::runcamera()
- {
- float tmpval = 0.0f;
- switch (Game->Viewmode())
- {
- case CIRCLING:
- camangle = camangle + (direction) 1;
- nextcam.setx(guy->location().x()+tcsin(camangle,camdist));
- nextcam.setz(guy->location().z()+tccos(camangle,camdist));
- nextcam.sety(guy->location().y()+camrise);
- camdist += camstep;
- camrise += camrstep;
- if (camrise > 10.0f)
- camrstep = (float)-fabs(camrstep);
- if (camrise < 2.0f)
- camrstep = (float)fabs(camrstep);
- if (camdist > maxcamdist)
- camstep = (float)-fabs(camstep);
- if (camdist < mincamdist)
- camstep = (float)fabs(camstep);
- camera.stepto(nextcam, .1f, FALSE);
- break;
- case DUDEVIEW:
- case DUDEVIEWHIGH:
- case DUDEVIEWLOW:
- switch (Game->Viewmode())
- {
- case DUDEVIEW:
- camrise = 0.0f;
- break;
- case DUDEVIEWHIGH:
- camrise = -1.4f;
- break;
- case DUDEVIEWLOW:
- camrise = 1.4f;
- break;
- }
- camdist = 3.0f;
- nextcam.setx(guy->location().x()+tcsin(guy->location().ydirection(),-3.0f));
- nextcam.setz(guy->location().z()+tccos(guy->location().ydirection(),-3.0f));
- nextcam.sety(guy->location().y()+camrise);
- camera.stepto(nextcam, .4f, FALSE);
- break;
- case AERIAL:
- #ifdef EDITOR
- camrise = 10.0f;
- #else
- camrise = 4.0f;
- #endif
- camdist = 3.0f;
- nextcam.setx(guy->location().x()+tcsin(guy->location().ydirection(),-1.3f));
- nextcam.setz(guy->location().z()+tccos(guy->location().ydirection(),-1.3f));
- nextcam.sety(guy->location().y()+camrise);
- camera.stepto(nextcam, .3f, FALSE);
- break;
- case HIGHANGLE:
- camrise = 2.0f;
- camangle = camangle + (direction) 1;
- nextcam.setx(guy->location().x()+tcsin(camangle,camdist));
- nextcam.setz(guy->location().z()+tccos(camangle,camdist));
- nextcam.sety(guy->location().y()+camrise);
- camdist += camstep;
- if (camdist > maxcamdist)
- camstep = (float)-fabs(camstep);
- if (camdist < mincamdist)
- camstep = (float)fabs(camstep);
- camera.stepto(nextcam, .5f, FALSE);
- break;
- case RIGHTSIDE:
- tmpval = 3.5f;
- camdist += camstep;
- if (camdist > maxcamdist)
- camstep = (float)-fabs(camstep);
- if (camdist < mincamdist)
- camstep = (float)fabs(camstep);
- nextcam.setx(guy->location().x()-camdist);
- nextcam.setz(guy->location().z());
- nextcam.sety(guy->location().y()+tmpval);
- camera.stepto(nextcam, .5f, FALSE);
- break;
- case LEFTSIDE:
- tmpval = 3.5f;
- camdist += camstep;
- if (camdist > maxcamdist)
- camstep = (float)-fabs(camstep);
- if (camdist < mincamdist)
- camstep = (float)fabs(camstep);
- nextcam.setx(guy->location().x()+camdist);
- nextcam.setz(guy->location().z());
- nextcam.sety(guy->location().y()+tmpval);
- camera.stepto(nextcam, .5f, FALSE);
- break;
- case FRONTSIDE:
- tmpval = 3.5f;
- camdist += camstep;
- if (camdist > maxcamdist)
- camstep = (float)-fabs(camstep);
- if (camdist < mincamdist)
- camstep = (float)fabs(camstep);
- nextcam.setx(guy->location().x());
- nextcam.setz(guy->location().z()+camdist);
- nextcam.sety(guy->location().y()+tmpval);
- camera.stepto(nextcam, .5f, FALSE);
- break;
- case BACKSIDE:
- tmpval = 3.5f;
- camdist += camstep;
- if (camdist > maxcamdist)
- camstep = (float)-fabs(camstep);
- if (camdist < mincamdist)
- camstep = (float)fabs(camstep);
- nextcam.setx(guy->location().x());
- nextcam.setz(guy->location().z()-camdist);
- nextcam.sety(guy->location().y()+tmpval);
- camera.stepto(nextcam, .5f, FALSE);
- break;
- }
- Game->Aim() = guy->location();
- }
- char exist(LPCTSTR path)
- {
- FILE *fp = fopen(path, "r");
- if (fp <= 0)
- return FALSE;
- fclose(fp);
- return TRUE;
- }
- static void getnew(CString& path, short level, CString& filename)
- {
- char tmpbuf[7];
- if (level == 0)
- {
- path = "dudes";
- }
- else
- {
- sprintf(tmpbuf, "%d", level);
- path = "level";
- path += tmpbuf;
- }
- path += '\';
- path += filename;
- if (!exist((LPCTSTR)path) && level > 0)
- getnew(path, --level, filename);
- }
- CString& getpath(CString& filename)
- {
- static CString path;
- getnew(path, Game->LevelNum(), filename);
- return path;
- }