cprojectile.cpp
来自「C人工智能游戏开发的一些实例源代码 C Game development in 」· C++ 代码 · 共 56 行
CPP
56 行
//Tanks
//Copyright John Manslow
//29/09/2001
#include "stdafx.h"
#include "CProjectile.h"
#include "math.h"
const double dGravity=0.1;
const double dFriction=0.997;
CProjectile::CProjectile(const double dNewxPosition,
const double dNewyPosition,
const double dNewHeadingX,
const double dNewHeadingY)
{
TRACE("\t\tCreating projectile...");
//Record the parameters of the projectile:
//Its current position,
dxPosition=dNewxPosition;
dyPosition=dNewyPosition;
//its position at the end of the previous time step,
dPreviousxPosition=dxPosition;
dPreviousyPosition=dyPosition;
//and the x and y components of its velocity.
dSpeedx=dNewHeadingX;
dSpeedy=dNewHeadingY;
TRACE("successful.\n");
}
CProjectile::~CProjectile()
{
TRACE("\t\tDestroying projectile...");
TRACE("successful.\n");
}
void CProjectile::TimeStep(const double dWindSpeed)
{
//Record its current position as its old position
dPreviousxPosition=dxPosition;
dPreviousyPosition=dyPosition;
//Update the projectile's position
dxPosition+=dSpeedx;
dyPosition+=dSpeedy;
//Update the projectile's velocity. If this model changes, the neural network may have to
//be retrained
dSpeedy-=dGravity;
dSpeedy*=dFriction;
dSpeedx+=(dWindSpeed-dSpeedx)*(1.0-dFriction);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?