#include "stdafx.h"
#include "Shooter0.h"
#include "Shooter0Mark.h"
CShooter0::CShooter0()
{
//载入图片
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero 静.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero 右.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero 右上.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero 上.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero 左上.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero 左.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero 左下.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero 下.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero 右下.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Fire Path.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Left Fire 00.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Left Fire 01.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Left Fire 02.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Left Fire 03.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Left Fire 04.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Right Fire 00.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Right Fire 01.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Right Fire 02.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Right Fire 03.png")));
m_vImage.push_back(Image::FromFile(
_T("res/Foton The Desktop Hero Right Fire 04.png")));
// 设置本类的大小
RectF rc;
rc.Width = (float)m_vImage[0]->GetWidth();
rc.Height = (float)m_vImage[0]->GetHeight();
rc.X = 800.0f;
rc.Y = 600.0f;
SetRect(rc);
}
CShooter0::~CShooter0()
{
}
// 根据 自己当前的属性画自己
void CShooter0::Draw(Gdiplus::Graphics &gh)
{
switch(m_eStatus) {
case EStatus0: {
// 当前阶段,机器上下晃动
// 设置显示的图片
m_index = 0;
// 判断时间
if(m_timer0.IsTimeval()) {
m_bUp = !m_bUp;
if(m_bUp) {
// 位置向上移
auto pt = GetCenterPos();
pt.Y += 1.0f;
SetCenterPos(pt);
}
else {
// 位置向下移
auto pt = GetCenterPos();
pt.Y -= 1.0f;
SetCenterPos(pt);
}
}
gh.DrawImage(m_vImage[m_index], GetRect());
break;
}
case EStatusMove0: { // 移动 向右 画向右的图片
m_index = 1 + (EStatusMove0 - EStatusMove0);
gh.DrawImage(m_vImage[m_index], GetRect());
DrawMove(gh);
break;
}
case EStatusMove1: { // 移动 右上 画右上的图片
m_index = 1 + (EStatusMove1 - EStatusMove0);
gh.DrawImage(m_vImage[m_index], GetRect());
DrawMove(gh);
break;
}
case EStatusMove2: { // 移动 向上 画向上的图片
m_index = 1 + (EStatusMove2 - EStatusMove0);
gh.DrawImage(m_vImage[m_index], GetRect());
DrawMove(gh);
break;
}
case EStatusMove3: { // 移动 左上 画左上的图片
m_index = 1 + (EStatusMove3 - EStatusMove0);
gh.DrawImage(m_vImage[m_index], GetRect());
DrawMove(gh);
break;
}
case EStatusMove4: { // 移动 向左 画向左的图片
m_index = 1 + (EStatusMove4 - EStatusMove0);
gh.DrawImage(m_vImage[m_index], GetRect());
DrawMove(gh);
break;
}
case EStatusMove5: { // 移动左下 画向右的图片
m_index = 1 + (EStatusMove5 - EStatusMove0);
gh.DrawImage(m_vImage[m_index], GetRect());
DrawMove(gh);
break;
}
case EStatusMove6: { // 移动 向下 画向下的图片
m_index = 1 + (EStatusMove6 - EStatusMove0);
gh.DrawImage(m_vImage[m_index], GetRect());
DrawMove(gh);
break;
}
case EStatusMove7: { // 移动 右下 画右下的图片
m_index = 1 + (EStatusMove7 - EStatusMove0);
gh.DrawImage(m_vImage[m_index], GetRect());
DrawMove(gh);
break;
}
case EStatusFireLeft: { // 向左开火
DrawFire(gh);
break;
}
case EStatusFireRight: { // 向右开火
DrawFire(gh);
break;
}
default:
break;
}
}
void CShooter0::DrawMove(Gdiplus::Graphics &gh)
{
//只更新位置,直到到达为止
//如果到达,更新状态
if(GetRect().Contains(m_moveTo)) {
m_eStatus = EStatus0;
return;
}
// 否则移动机器人
PointF pt = GetCenterPos();
pt.X += 20.0f * cos(PI(2.0f) - m_moveDir);
pt.Y += 20.0f * sin(PI(2.0f) - m_moveDir);
// 设置中心位置
SetCenterPos(pt);
}
void CShooter0::DrawFire(Gdiplus::Graphics &gh)
{
// 画图片
switch(m_eStatus) {
case EStatusFireLeft: {
switch(m_index_fire) {
case 0: { // 小人转身
auto img = m_vImage[10];
RectF r = GetRect();
r.Width = (float)img->GetWidth();
r.Height = (float)img->GetHeight();
gh.DrawImage(img, r);
break;
}
case 1: { // 聚集能量
auto img = m_vImage[11];
RectF r = GetRect();
r.Width = (float)img->GetWidth();
r.Height = (float)img->GetHeight();
gh.DrawImage(img, r);
break;
}
case 2: { // 聚集能量
auto img = m_vImage[12];
RectF r = GetRect();
r.Width = (float)img->GetWidth();
r.Height = (float)img->GetHeight();
gh.DrawImage(img, r);
break;
}
case 3: { // 发射子弹
// 射击开始:发出一个子弹
g_game->Append(std::make_shared<CShooter0Mark>(
m_fireTo.X, GetRect().Y));
/* break **** 注意此处没有break ****; */
}
case 4: { // 发射激光
const float Y = GetRect().Y;
const float X = GetRect().X;
const float YY = Y;
const float XX = m_fireTo.X + 30.0f;
// 画小人身体,动作
{
auto img = m_vImage[13];
gh.DrawImage(img, X, Y);
}
// 画激光中间部分
{
auto img = m_vImage[9];
float left = X + 52;
// 拼接图片进行输出,因为中间部分长度不确定,不能事先确定图片的长度
while(left >= (XX + 60.0f)) {
gh.DrawImage(img, left, Y, (float)img->GetWidth(),
(flo