3DWRAP.CPP
资源名称:tc3d.zip [点击查看]
上传用户:abcdshs
上传日期:2007-01-07
资源大小:1858k
文件大小:9k
源码类别:
游戏
开发平台:
Visual C++
- // (C) Copyright 1996 by Anthony J. Carin. All Rights Reserved.
- #include <stdafx.h>
- #include "3dwrap.h"
- #include "3dshapes.h"
- #include "personal.h"
- #include "queue.h"
- #pragma warning (disable: 4096)
- #include "vfw.h"
- #include "floor.h"
- #include "command.h"
- #include "levels.h"
- #include "3dtools.h"
- #include "bmpsurf.h"
- #include "landscpe.h"
- #include "gateway.h"
- #include "dudehold.h"
- #include "teleport.h"
- #include "weaphold.h"
- #include "resource.h"
- DudesWrapper::DudesWrapper()
- {
- m_g = new global;
- hdc = 0;
- hrc = 0;
- hwnd = 0;
- ghwnd = NULL;
- wndcreated = FALSE;
- }
- DudesWrapper::~DudesWrapper()
- {
- delete m_g;
- }
- short DudesWrapper::Centx()
- {
- return m_g->centx;
- }
- short DudesWrapper::Centy()
- {
- return m_g->centy;
- }
- short DudesWrapper::Cx()
- {
- return m_g->cx;
- }
- short DudesWrapper::Cy()
- {
- return m_g->cy;
- }
- void DudesWrapper::SetCentx(short s)
- {
- m_g->centx = s;
- }
- void DudesWrapper::SetCenty(short s)
- {
- m_g->centy = s;
- }
- void DudesWrapper::SetCx(short s)
- {
- m_g->cx = s;
- }
- void DudesWrapper::SetCy(short s)
- {
- m_g->cy = s;
- }
- short DudesWrapper::Detail()
- {
- return m_g->detail;
- }
- void DudesWrapper::SetDetail(short d)
- {
- m_g->detail = d;
- }
- coordinate& DudesWrapper::Aim()
- {
- static coordinate c = *(m_g->aim);
- return c;
- }
- short DudesWrapper::LevelNum()
- {
- return m_g->levelnum;
- }
- void DudesWrapper::SetLevelNum(short l)
- {
- m_g->levelnum = l;
- }
- levels *DudesWrapper::LevelPtr()
- {
- return m_g->levelptr;
- }
- void DudesWrapper::SetLevelPtr(levels *p)
- {
- m_g->levelptr = p;
- }
- drawqueue *DudesWrapper::DrawQueue()
- {
- return m_g->queue;
- }
- personal *DudesWrapper::Hero()
- {
- return m_g->hero;
- }
- floortype *DudesWrapper::Floor()
- {
- return m_g->floor;
- }
- tc3dtools *DudesWrapper::Tool3d()
- {
- return m_g->tool3d;
- }
- char DudesWrapper::Motionless()
- {
- return m_g->motionless;
- }
- void DudesWrapper::NowMotionless()
- {
- m_g->motionless = TRUE;
- }
- void DudesWrapper::NotMotionless()
- {
- m_g->motionless = FALSE;
- }
- char DudesWrapper::IsPaused()
- {
- return m_g->pause;
- }
- void DudesWrapper::PauseOn()
- {
- m_g->pause = TRUE;
- }
- void DudesWrapper::PauseOff()
- {
- m_g->pause = FALSE;
- }
- viewmodetype DudesWrapper::Viewmode()
- {
- return m_g->viewmode;
- }
- void DudesWrapper::SetViewmode(viewmodetype v)
- {
- m_g->viewmode = v;
- }
- bmplist *DudesWrapper::Bmpsurfs()
- {
- return m_g->bmpsurfs;
- }
- highlist *DudesWrapper::HighAreas()
- {
- return m_g->highareas;
- }
- landscapelist *DudesWrapper::Landscapes()
- {
- return m_g->landscapes;
- }
- float DudesWrapper::Sintable(int i)
- {
- return m_g->sintable[i];
- }
- float DudesWrapper::Costable(int i)
- {
- return m_g->costable[i];
- }
- void DudesWrapper::SetDrawQueue (drawqueue *p)
- {
- m_g->queue = p;
- }
- void DudesWrapper::SetHero (personal *p)
- {
- m_g->hero = p;
- }
- void DudesWrapper::SetHero (personal& p)
- {
- *(m_g->hero) = p;
- }
- void DudesWrapper::SetFloor (floortype *p)
- {
- m_g->floor = p;
- }
- void DudesWrapper::SetTool3d (tc3dtools *p)
- {
- m_g->tool3d = p;
- }
- void DudesWrapper::SetBmpsurfs (bmplist *p)
- {
- m_g->bmpsurfs = p;
- }
- void DudesWrapper::SetHighAreas (highlist *p)
- {
- m_g->highareas = p;
- }
- void DudesWrapper::SetLandscapes (landscapelist *p)
- {
- m_g->landscapes = p;
- }
- void DudesWrapper::NewGame()
- {
- #ifdef EDITOR
- char OKtoLoad = FALSE;
- if (m_g->levelptr && m_g->levelptr->completed())
- OKtoLoad = TRUE;
- #endif
- delete m_g->levelptr;
- m_g->levelptr = NULL;
- if (ghwnd == NULL && wndcreated == FALSE)
- {
- wndcreated = TRUE;
- ghwnd = MCIWndCreate(hwnd, NULL,
- MCIWNDF_NOPLAYBAR |
- MCIWNDF_NOMENU |
- MCIWNDF_NOERRORDLG |
- MCIWNDF_NOOPEN, NULL);
- }
- DrawQueue()->purge();
- NotMotionless();
- Floor()->setcolor(RGB(random(256),random(256),random(256)));
- createlevel(Hero()->startlevel());
- if (Detail() > 50)
- Floor()->settexture((CString)"floor.bmp");
- else
- Floor()->cleartexture();
- #ifndef EDITOR
- m_g->levelptr->usercontrol->selectpunch(random(100),getpath((CString)"punch.dat"));
- #else
- if (OKtoLoad)
- #endif
- Landscapes()->load(getpath((CString)"landscpe.map"));
- camera.setx(0.0f);
- camera.setz(-7.0f);
- }
- void DudesWrapper::InitLaunch()
- {
- char tmpbuf[300];
- FILE *fp = fopen("starter.dat", "r");
- if (fp > 0)
- {
- fscanf(fp, "%s", tmpbuf);
- fclose(fp);
- }
- else
- strcpy(tmpbuf, "level1\bobal.dud");
- Hero()->load(tmpbuf);
- createlevel(Hero()->startlevel());
- }
- void DudesWrapper::Launch()
- {
- if (IsPaused())
- return;
- Tool3d()->reset();
- #ifndef EDITOR
- Tool3d()->lookat(camera, Aim());
- #else
- if (m_g->levelptr->selection)
- Tool3d()->lookat(camera, m_g->levelptr->selection->location());
- else
- Tool3d()->lookat(camera, Aim());
- #endif
- camera.setxdir(camera.xdirectionto(Aim()));
- camera.setydir(camera.ydirectionto(Aim()));
- Tool3d()->lightposition(camera);
- if (Detail() > 10)
- Floor()->draw(Aim());
- m_g->levelptr->draw();
- if (m_g->levelptr->completed())
- {
- SetLevelNum((short)(LevelNum()+1));
- if (nextlevelexists())
- {
- Hero()->setstartlevel(LevelNum());
- Hero()->save();
- NewGame();
- }
- }
- Tool3d()->finish();
- Landscapes()->CreateCloseLandscapes();
- if (ghwnd != NULL)
- {
- if (MCIWndGetPosition(ghwnd) >= MCIWndGetEnd(ghwnd))
- MCIWndPlay(ghwnd);
- }
- }
- void DudesWrapper::CleanUp()
- {
- FILE *fp = fopen("starter.dat", "w");
- if (fp > 0)
- {
- fprintf(fp, "%sn", Hero()->filepath());
- fclose(fp);
- }
- if (ghwnd != NULL)
- MCIWndDestroy(ghwnd);
- }
- void DudesWrapper::createlevel(short level)
- {
- levels *lptr;
- switch (level)
- {
- case 0:Hero()->setstartlevel(1);
- case 1:lptr = new level1(); break;
- case 2:lptr = new level2(); break;
- case 3:lptr = new level3(); break;
- case 4:lptr = new level4(); break;
- case 5:lptr = new level5(); break;
- case 6:lptr = new level6(); break;
- case 7:lptr = new level7(); break;
- case 8:lptr = new level8(); break;
- case 9:lptr = new level9(); break;
- case 10:lptr = new level10(); break;
- case 11:lptr = new level11(); break;
- case 12:lptr = new level12(); break;
- default:lptr = new lastlevel(level); break;
- }
- SetLevelPtr(lptr);
- #ifndef EDITOR
- LPCSTR tmp = (LPCSTR)getpath((CString)"3ddudes.mid");
- if (ghwnd != NULL)
- {
- MCIWndClose(ghwnd);
- MCIWndOpen(ghwnd, tmp, 0);
- MCIWndPlay(ghwnd);
- }
- #endif
- }
- char DudesWrapper::nextlevelexists()
- {
- char buf[40];
- FILE *fp;
- sprintf(buf, "level%d\test.cmd", LevelNum());
- fp = fopen(buf,"r");
- if (fp > 0)
- {
- fclose(fp);
- return TRUE;
- }
- if (Motionless() == FALSE)
- {
- NowMotionless();
- CDialog nomore(IDD_NOMORE);
- nomore.DoModal();
- }
- return FALSE;
- }
- void DudesWrapper::NewLandscape(CString& s)
- {
- landscape *tmp = new landscape(s);
- DrawQueue()->add(tmp);
- LevelPtr()->selection = tmp;
- }
- void DudesWrapper::NewGateway(CString& s)
- {
- gateway *tmp = new gateway(s);
- DrawQueue()->add(tmp);
- LevelPtr()->selection = tmp;
- }
- void DudesWrapper::NewDudeholder(CString& s)
- {
- dudeholder *tmp = new dudeholder(s);
- DrawQueue()->add(tmp);
- LevelPtr()->selection = tmp;
- }
- void DudesWrapper::NewTeleporter(short s)
- {
- Teleporter *tmp = new Teleporter(s);
- DrawQueue()->add(tmp);
- LevelPtr()->selection = tmp;
- }
- void DudesWrapper::NewWeaponholder(int s)
- {
- weaponholder *tmp = new weaponholder((WeaponType)s);
- DrawQueue()->add(tmp);
- LevelPtr()->selection = tmp;
- }
- landscape *DudesWrapper::LastLandscape()
- {
- return LevelPtr()->selection;
- }