DUDE.CPP
资源名称:tc3d.zip [点击查看]
上传用户:abcdshs
上传日期:2007-01-07
资源大小:1858k
文件大小:11k
源码类别:
游戏
开发平台:
Visual C++
- // (C) Copyright 1996 by Anthony J. Carin. All Rights Reserved.
- #include <stdafx.h>
- #include <dude.h>
- #include <mmsystem.h>
- #include "levels.h"
- #include "antagon.h"
- #include "weapon.h"
- dude::dude(personal *p) : baseobject(p->body())
- {
- setpersonal(*p);
- float hight = p->hight();
- hightlevel = 1.5f * hight;
- if (m_body)
- m_body->setyoff((direction)0);
- coordinate left(0.3f*hight,0.14f*hight,0.0f);
- coordinate right(-0.3f*hight,0.14f*hight,0.0f);
- leftarm = new totalarm(left,p);
- rightarm = new totalarm(right,p);
- left.setto(0.1f*hight,-0.7f*hight,0.0f);
- right.setto(-0.1f*hight,-0.7f*hight,0.0f);
- leftleg = new totalleg(left,p);
- rightleg = new totalleg(right,p);
- left.setto(0.0f,0.5f*hight,-0.08f*hight);
- neck = new attachment(left);
- m_head = new head(p);
- neck->attachto(m_head);
- shirtcolor(RGB(0,148,0));
- pantscolor(RGB(0,0,200));
- skincolor(RGB(240,200,0));
- m_health = 100;
- rightweapon = leftweapon = NULL;
- personaleffect();
- }
- dude::~dude()
- {
- delete rightweapon;
- delete leftweapon;
- delete leftarm;
- delete rightarm;
- delete leftleg;
- delete rightleg;
- delete neck;
- delete m_head;
- }
- void dude::shirtcolor(COLORREF c)
- {
- setcolor(c);
- leftarm->setcolor(c);
- rightarm->setcolor(c);
- }
- void dude::pantscolor(COLORREF c)
- {
- leftleg->setcolor(c);
- rightleg->setcolor(c);
- }
- void dude::skincolor(COLORREF c)
- {
- m_head->setcolor(c);
- }
- void dude::setto(view& v)
- {
- baseobject::setto(v);
- leftarm->setto(v);
- rightarm->setto(v);
- leftleg->setto(v);
- rightleg->setto(v);
- neck->setto(v);
- }
- void dude::draw()
- {
- baseobject::draw();
- leftarm->setto(m_view);
- rightarm->setto(m_view);
- leftleg->setto(m_view);
- rightleg->setto(m_view);
- neck->setto(m_view);
- leftarm->draw();
- rightarm->draw();
- leftleg->draw();
- rightleg->draw();
- neck->draw();
- float nhight;
- float xnhight = tccos(m_view.xdirection(), hightlevel);
- float znhight = tccos(m_view.zdirection(), hightlevel);
- nhight = (znhight < xnhight) ? znhight : xnhight;
- settledown(nhight);
- view tmp;
- if (rightweapon)
- {
- tmp = righthandloc();
- tmp.setydir(tmp.ydirection()+(direction)TC_PI_2+rightweapontilt);
- rightweapon->setto(tmp);
- rightweapon->draw();
- }
- if (leftweapon)
- {
- tmp = lefthandloc();
- tmp.setydir(tmp.ydirection()+(direction)TC_PI_2+leftweapontilt);
- leftweapon->setto(tmp);
- leftweapon->draw();
- }
- }
- void dude::followcommands(command& c)
- {
- CString tmpbuf;
- LPCTSTR tmpptr;
- int tmpi;
- instruction inst;
- inst = c.next();
- while (inst() != NOMORE && inst() != ENDSESSION)
- {
- switch (inst())
- {
- case RARMRAISEFWD:
- rightarm->raisefoward(inst.value());
- break;
- case LARMRAISEFWD:
- leftarm->raisefoward(inst.value());
- break;
- case RARMRAISEBCK:
- rightarm->raisebackward(inst.value());
- break;
- case LARMRAISEBCK:
- leftarm->raisebackward(inst.value());
- break;
- case RARMRAISESIDE:
- rightarm->raisesideward(-inst.value());
- break;
- case LARMRAISESIDE:
- leftarm->raisesideward(inst.value());
- break;
- case RARMBENDELBOW:
- rightarm->bendelbow(inst.value());
- break;
- case LARMBENDELBOW:
- leftarm->bendelbow(inst.value());
- break;
- case RLEGBENDKNEE:
- rightleg->bendknee(inst.value());
- break;
- case LLEGBENDKNEE:
- leftleg->bendknee(inst.value());
- break;
- case RLEGRAISEFWD:
- rightleg->raisefoward(inst.value());
- break;
- case LLEGRAISEFWD:
- leftleg->raisefoward(inst.value());
- break;
- case RLEGRAISEBCK:
- rightleg->raisebackward(inst.value());
- break;
- case LLEGRAISEBCK:
- leftleg->raisebackward(inst.value());
- break;
- case RLEGRAISESIDE:
- rightleg->raisesideward(-inst.value());
- break;
- case LLEGRAISESIDE:
- leftleg->raisesideward(inst.value());
- break;
- case TILTBODYRIGHT:
- tiltright(inst.value());
- break;
- case TILTBODYLEFT:
- tiltleft(inst.value());
- break;
- case TILTBODYFWD:
- tiltfoward(inst.value());
- break;
- case TILTBODYBCK:
- tiltbackward(inst.value());
- break;
- case TURNHEADLEFT:
- m_head->turnleft(inst.value());
- break;
- case TURNHEADRIGHT:
- m_head->turnright(inst.value());
- break;
- case TURNHEADUP:
- m_head->turnup(inst.value());
- break;
- case TURNHEADDOWN:
- m_head->turndown(inst.value());
- break;
- case CLEAR:
- clear();
- break;
- case TURNRIGHT:
- turnright(inst.value());
- break;
- case TURNLEFT:
- turnleft(inst.value());
- break;
- case MOVEUPWARD:
- moveupward(inst.value());
- break;
- case MOVEFOWARD:
- movefoward(inst.value());
- break;
- case MOVEBACKWARD:
- movebackward(inst.value());
- break;
- case PLAYSOUND:
- tmpbuf = inst.string();
- tmpbuf += ".wav";
- PlaySound(getpath(tmpbuf), NULL, SND_ASYNC);
- break;
- case TILTRIGHTWEAPON:
- rightweapontilt = (direction) (TC_PI2*inst.value());
- break;
- case TILTLEFTWEAPON:
- leftweapontilt = (direction) (TC_PI2*inst.value());
- break;
- case PLAYGENERIC:
- tmpi = (int) (inst.value());
- switch(tmpi)
- {
- case 1: tmpptr = m_personal.hia(); break;
- case 2: tmpptr = m_personal.ugh(); break;
- default: tmpptr = m_personal.laugh(); break;
- }
- PlaySound(tmpptr, NULL, SND_ASYNC);
- break;
- case STRIKETOP:
- case STRIKEMED:
- case STRIKEBOT:
- case THEYDO:
- checkifgothit(inst);
- break;
- case HURTME:
- takedamage(inst.value());
- break;
- case RTHROW:
- if (rightweapon)
- {
- weapon *tmp = (weapon *)rightweapon;
- releaserightweapon();
- tmp->Throw(location().ydirection(), inst.value());
- }
- break;
- case LTHROW:
- if (leftweapon)
- {
- weapon *tmp = (weapon *)leftweapon;
- releaseleftweapon();
- tmp->Throw(location().ydirection(), inst.value());
- }
- break;
- case PICKUP:
- if (!leftweapon || !rightweapon)
- pickup();
- break;
- }
- inst = c.next();
- }
- }
- void dude::clear()
- {
- rightarm->raisefoward(0.0f);
- leftarm->raisefoward(0.0f);
- rightarm->raisesideward(0.0f);
- leftarm->raisesideward(0.0f);
- rightarm->bendelbow(0.0f);
- leftarm->bendelbow(0.0f);
- rightleg->bendknee(0.0f);
- leftleg->bendknee(0.0f);
- rightleg->raisefoward(0.0f);
- leftleg->raisefoward(0.0f);
- rightleg->raisesideward(0.0f);
- leftleg->raisesideward(0.0f);
- tiltright(0.0f);
- tiltbackward(0.0f);
- m_head->turnleft(0.0f);
- m_head->turnup(0.0f);
- }
- void dude::moveupward(float v)
- {
- coordinate tmp = m_view;
- tmp.sety(tmp.y() + 1.0f*v);
- m_view.stepto(tmp,7.0f);
- }
- void dude::movefoward(float v)
- {
- view tmp = m_view;
- tmp.setx(tmp.x() + tcsin(tmp.ydirection(), v));
- tmp.setz(tmp.z() + tccos(tmp.ydirection(), v));
- m_view.stepto(tmp,7.0f);
- }
- void dude::movebackward(float v)
- {
- view tmp = m_view;
- tmp.setx(tmp.x() - tcsin(tmp.ydirection(), v));
- tmp.setz(tmp.z() - tccos(tmp.ydirection(), v));
- m_view.stepto(tmp,7.0f);
- }
- void dude::checkifgothit(instruction& inst)
- {
- short HitBonus = 0;
- if (rightweapon)
- {
- if (((handheld *)rightweapon)->IsAKnife())
- HitBonus = 10;
- else if (((handheld *)rightweapon)->IsASword())
- HitBonus = 30;
- }
- else if (leftweapon)
- {
- if (((handheld *)leftweapon)->IsAKnife())
- HitBonus = 10;
- else if (((handheld *)leftweapon)->IsASword())
- HitBonus = 30;
- }
- if (Game->LevelPtr()->usercontrol->location() != location())
- {
- if (inrange(Game->LevelPtr()->usercontrol->location()) && !Game->Motionless())
- Game->LevelPtr()->usercontrol->gothit(inst, HitBonus);
- return;
- }
- antagonist *target;
- target = findtarget();
- if (target)
- target->gothit(inst, HitBonus);
- }
- antagonist * dude::findtarget()
- {
- antagonist *atmp;
- atmp = (antagonist *)Game->DrawQueue()->first(ANTAGONIST);
- while (atmp)
- {
- if (inrange(atmp->location()) && atmp->location() != location())
- return atmp;
- atmp = (antagonist *)Game->DrawQueue()->next(ANTAGONIST);
- }
- return NULL;
- }
- char dude::inrange(view& c)
- {
- float ftmp;
- ftmp = m_view.distanceto(c);
- if (ftmp > 1.0f)
- return FALSE;
- if (fabs(c.y() - m_view.y()) > 1.0f)
- return FALSE;
- direction tmp;
- tmp = m_view.ydirectionto(c);
- tmp = m_view.ydirection() - tmp;
- if (tmp > (direction) TC_PI_4 &&
- tmp < (direction) -TC_PI_4)
- return FALSE;
- return TRUE;
- }
- void dude::takedamage(float v)
- {
- m_health = (short) ((float)m_health - 100.0f*v);
- if (m_health < 40)
- {
- if (random(4) == 2)
- releaseleftweapon();
- else
- releaserightweapon();
- }
- if (m_health < 0)
- {
- m_health = 0;
- releaserightweapon();
- releaseleftweapon();
- }
- }
- void dude::personaleffect()
- {
- skincolor(m_personal.skincolor());
- haircolor(m_personal.haircolor());
- leftarm->setskincolor(m_personal.skincolor());
- rightarm->setskincolor(m_personal.skincolor());
- m_head->facesurface(m_personal.face());
- }
- void dude::releaserightweapon()
- {
- if (rightweapon)
- {
- Game->Landscapes()->AddLSEntry(rightweapon->location(), (CString)"WEAPON", ((weapon *)rightweapon)->NumType());
- Game->DrawQueue()->add(rightweapon);
- rightweapon = 0;
- }
- }
- void dude::releaseleftweapon()
- {
- if (leftweapon)
- {
- Game->Landscapes()->AddLSEntry(leftweapon->location(), (CString)"WEAPON", ((weapon *)leftweapon)->NumType());
- Game->DrawQueue()->add(leftweapon);
- leftweapon = 0;
- }
- }
- void dude::pickup()
- {
- if (leftweapon && rightweapon)
- return;
- handheld *atmp;
- atmp = (handheld *)Game->DrawQueue()->first(HANDHELD);
- while (atmp)
- {
- if (inrange(atmp->location()))
- {
- atmp->RemoveLSEntry();
- atmp->detach();
- if (!rightweapon)
- {
- rightweapon = atmp;
- break;
- }
- if (!leftweapon)
- {
- leftweapon = atmp;
- break;
- }
- }
- atmp = (handheld *)Game->DrawQueue()->next(HANDHELD);
- }
- }