CONTROL.CPP
资源名称:tc3d.zip [点击查看]
上传用户:abcdshs
上传日期:2007-01-07
资源大小:1858k
文件大小:4k
源码类别:
游戏
开发平台:
Visual C++
- // (C) Copyright 1996 by Anthony J. Carin. All Rights Reserved.
- #include "stdafx.h"
- #include "control.h"
- #include "levels.h"
- control::control(baseobject *ptr)
- {
- rstep = FALSE;
- object = ptr;
- maincmd =
- rstepcmd =
- lstepcmd =
- rruncmd =
- lruncmd =
- rstepbackcmd =
- lstepbackcmd =
- turnleftcmd =
- turnrightcmd =
- pickupcmd =
- blockcmd = NULL;
- loadmaincmd();
- maincmd->purgeold();
- blocking = FALSE;
- }
- control::~control()
- {
- delete maincmd;
- delete rstepcmd;
- delete lstepcmd;
- delete rruncmd;
- delete lruncmd;
- delete rstepbackcmd;
- delete lstepbackcmd;
- delete turnleftcmd;
- delete turnrightcmd;
- delete pickupcmd;
- delete blockcmd;
- }
- void control::stepfoward()
- {
- rstep = (char) !rstep;
- if (rstep)
- {
- loadrstepcmd();
- rstepcmd->restart();
- maincmd->append(*rstepcmd);
- }
- else
- {
- loadlstepcmd();
- lstepcmd->restart();
- maincmd->append(*lstepcmd);
- }
- blocking = FALSE;
- }
- void control::runfoward()
- {
- rstep = (char)!rstep;
- if (rstep)
- {
- loadrruncmd();
- rruncmd->restart();
- maincmd->append(*rruncmd);
- }
- else
- {
- loadlruncmd();
- lruncmd->restart();
- maincmd->append(*lruncmd);
- }
- blocking = FALSE;
- }
- void control::stepbackward()
- {
- rstep = (char)!rstep;
- if (rstep)
- {
- loadrstepbackcmd();
- rstepbackcmd->restart();
- maincmd->append(*rstepbackcmd);
- }
- else
- {
- loadlstepbackcmd();
- lstepbackcmd->restart();
- maincmd->append(*lstepbackcmd);
- }
- blocking = FALSE;
- }
- void control::turnleft()
- {
- loadturnleftcmd();
- turnleftcmd->restart();
- maincmd->append(*turnleftcmd);
- blocking = FALSE;
- }
- void control::turnright()
- {
- loadturnrightcmd();
- turnrightcmd->restart();
- maincmd->append(*turnrightcmd);
- blocking = FALSE;
- }
- void control::pickup()
- {
- stopeverything();
- loadpickupcmd();
- pickupcmd->restart();
- maincmd->append(*pickupcmd);
- blocking = FALSE;
- }
- void control::block()
- {
- loadblockcmd();
- blockcmd->restart();
- maincmd->append(*blockcmd);
- blocking = TRUE;
- }
- void control::falldown()
- {
- command tmp("falldown.cmd");
- maincmd->append(tmp);
- }
- void control::issuecommands()
- {
- if (maincmd->nomore())
- return;
- object->followcommands(*maincmd);
- }
- void control::stopwalking()
- {
- maincmd->remove(TURNLEFT);
- maincmd->remove(TURNRIGHT);
- maincmd->remove(MOVEFOWARD);
- maincmd->remove(MOVEBACKWARD);
- blocking = FALSE;
- }
- void control::stopeverything()
- {
- maincmd->remove(NOMORE);
- maincmd->restart();
- blocking = FALSE;
- }
- void control::selectpunch(short v,CString& punch)
- {
- stopeverything();
- if (maincmd->isempty())
- {
- CString tmpstr;
- if (v < 0)
- v = 0;
- if (v > 100)
- v = 99;
- float fv = (float) v/100.0f;
- tmpstr = picklist(fv, punch);
- if (!tmpstr.IsEmpty())
- {
- command tmpcom((LPCTSTR) tmpstr);
- maincmd->append(tmpcom);
- }
- }
- blocking = FALSE;
- }
- void control::gothit(instruction& inst, short bonus)
- {
- char tmpptr[20];
- switch (inst())
- {
- case THEYDO:
- strcpy(tmpptr,inst.string());
- strcat(tmpptr,".CMD");
- break;
- case STRIKETOP:
- if (blocking)
- strcpy(tmpptr,"HITTOP.CMD");
- else
- strcpy(tmpptr,"HHITTOP.CMD");
- break;
- case STRIKEMED:
- if (blocking)
- strcpy(tmpptr,"HITMED.CMD");
- else
- strcpy(tmpptr,"HHITMED.CMD");
- break;
- case STRIKEBOT:
- if (blocking)
- strcpy(tmpptr,"HITBOT.CMD");
- else
- strcpy(tmpptr,"HHITBOT.CMD");
- break;
- }
- maincmd->purge();
- command tmpcom(tmpptr);
- if (bonus)
- tmpcom.AddToValue(HURTME, bonus);
- maincmd->append(tmpcom);
- if (blocking)
- block();
- }