📄 dudeview.cpp
字号:
// dudeView.cpp : implementation of the DudeView class
//
#include "stdafx.h"
#include "dudes.h"
#include "dudeDoc.h"
#include "dudeView.h"
#include "levels.h"
KeyControl keyboardcontrol = NOKEYHIT;
static char movebuttondown = FALSE;
static char walkcount;
static CPoint currpoint;
#ifdef EDITOR
enum selectmodetype
{
STOP,
MOVING,
ROTATING
};
selectmodetype selectmode;
#endif
/////////////////////////////////////////////////////////////////////////////
// DudeView
IMPLEMENT_DYNCREATE(DudeView, CView)
BEGIN_MESSAGE_MAP(DudeView, CView)
//{{AFX_MSG_MAP(DudeView)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_SIZE()
ON_WM_TIMER()
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_NEW_GAME, OnNewGame)
ON_WM_KEYDOWN()
ON_WM_KEYUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DudeView construction/destruction
DudeView::DudeView()
{
hdc = ::GetDC(m_hWnd);
Game = new DudesWrapper;
Game->InitLaunch();
}
DudeView::~DudeView()
{
::ReleaseDC(m_hWnd, hdc);
Game->CleanUp();
delete Game;
}
void DudeView::LaunchGame()
{
wglMakeCurrent(Game->hdc, Game->hrc);
Game->Launch();
wglMakeCurrent(Game->hdc, NULL);
}
BOOL DudeView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// DudeView
void DudeView::OnDraw(CDC* pDC)
{
//DudeDoc* pDoc = GetDocument();
//ASSERT_VALID(pDoc);
pDC = pDC;
SetTimer(1, 1, NULL);
//::ReleaseDC(m_hWnd, hdc);
//hdc = ::GetDC(m_hWnd);
//LaunchGame();
}
/////////////////////////////////////////////////////////////////////////////
// DudeView diagnostics
#ifdef _DEBUG
void DudeView::AssertValid() const
{
CView::AssertValid();
}
void DudeView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
DudeDoc* DudeView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(DudeDoc)));
return (DudeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// DudeView message handlers
void DudeView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
{
CView::CalcWindowRect(lpClientRect, nAdjustType);
}
LRESULT DudeView::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
return CView::DefWindowProc(message, wParam, lParam);
}
void DudeView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
::ReleaseDC(m_hWnd, hdc);
hdc = ::GetDC(m_hWnd);
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
BOOL DudeView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
return CView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
BOOL DudeView::OnCommand(WPARAM wParam, LPARAM lParam)
{
return CView::OnCommand(wParam, lParam);
}
LRESULT DudeView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
return CView::WindowProc(message, wParam, lParam);
}
void DudeView::WinHelp(DWORD dwData, UINT nCmd)
{
// TODO: Add your specialized code here and/or call the base class
CView::WinHelp(dwData, nCmd);
}
void DudeView::OnLButtonDown(UINT nFlags, CPoint point)
{
CView::OnLButtonDown(nFlags, point);
currpoint = point;
#ifdef EDITOR
if (Game->LevelPtr()->selection)
selectmode = MOVING;
else
movebuttondown = TRUE;
#else
movebuttondown = TRUE;
#endif
}
void DudeView::OnMouseMove(UINT nFlags, CPoint point)
{
CView::OnMouseMove(nFlags, point);
#ifdef EDITOR
if (Game->LevelPtr()->selection && selectmode != STOP)
{
view newloc = Game->LevelPtr()->selection->location();
float xdif = (float)(currpoint.x - point.x);
float zdif = (float)(currpoint.y - point.y);
if (selectmode == MOVING)
{
newloc.setx(newloc.x() + xdif/100.0f);
newloc.setz(newloc.z() + zdif/100.0f);
}
else if (selectmode == ROTATING)
{
newloc.setxdir(newloc.xdirection()+(direction)xdif);
newloc.setzdir(newloc.zdirection()+(direction)zdif);
}
Game->LevelPtr()->selection->setto(newloc);
}
#endif
currpoint = point;
}
void DudeView::OnRButtonDown(UINT nFlags, CPoint point)
{
CView::OnRButtonDown(nFlags, point);
#ifdef EDITOR
if (Game->LevelPtr()->selection)
selectmode = ROTATING;
#else
if (!Game->Motionless())
Game->LevelPtr()->usercontrol->block();
#endif
}
void DudeView::OnTimer(UINT nIDEvent)
{
static char turning;
LaunchGame();
CView::OnTimer(nIDEvent);
char motion = (char) ((movebuttondown || keyboardcontrol != NOKEYHIT)
&& !Game->Motionless());
#ifdef EDITOR
if (!Game->LevelPtr()->selection)
#endif
if (motion)
{
if (keyboardcontrol != NOKEYHIT)
{
switch(keyboardcontrol)
{
case FOWARD:
if (++walkcount > 7)
Game->LevelPtr()->usercontrol->runfoward();
else
Game->LevelPtr()->usercontrol->stepfoward();
break;
case BACK:
walkcount = 0;
Game->LevelPtr()->usercontrol->stepbackward();
break;
case LEFT:
walkcount = 0;
Game->LevelPtr()->usercontrol->turnleft();
break;
case RIGHT:
walkcount = 0;
Game->LevelPtr()->usercontrol->turnright();
break;
case HIT:
if (random(10) == 3)
Game->LevelPtr()->usercontrol->selectpunch(random(100),Game->Hero()->punchlist());
else
Game->LevelPtr()->usercontrol->selectpunch(random(100),Game->Hero()->normalpunch());
break;
case BLOCK:
Game->LevelPtr()->usercontrol->block();
break;
}
keyboardcontrol = NOKEYHIT;
}
else
{
direction tmpdir, tcdir, tmp;
tmpdir = getdirection((float)Game->Centx(),
(float)Game->Centy(),
(float)currpoint.x,
(float)currpoint.y) +
Game->Aim().ydirectionto(camera);
tcdir = Game->LevelPtr()->usercontrol->location().ydirection();
tmp = tmpdir - tcdir;
if (tmp < (direction) TC_PI_8 || tmp > (direction) -TC_PI_8)
{
if (turning)
{
turning = FALSE;
walkcount = 0;
Game->LevelPtr()->usercontrol->stopeverything();
}
if (movebuttondown)
{
if (++walkcount > 7)
Game->LevelPtr()->usercontrol->runfoward();
else
Game->LevelPtr()->usercontrol->stepfoward();
}
}
else
{
if (!turning)
{
turning = TRUE;
Game->LevelPtr()->usercontrol->stopeverything();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -