📄 tack.cpp
字号:
#include ".\tack.h"
Tack::Tack(HDC hdc, HDC mdc, HDC bufdc)
{
t_hdc = hdc;
t_mdc = mdc;
t_bufdc = bufdc;
map1 = new Map(hdc, mdc, bufdc);
for (int i=0; i<2; i++)
{
t_bullet[i] = new Bullet(hdc, mdc, bufdc);
}
t_life = 0;
t_live = false;
t_show = false;
t_ableMove = false;
t_stop = false;
t_bullet[0]->b_exit = false;
t_bullet[1]->b_exit = false;
t_bulletMode = 0;
}
Tack::~Tack(void)
{
SAFE_DELETEDC(t_bufdc);
SAFE_DELETEDC(t_mdc);
SAFE_DELETEDC(t_hdc);
for (int j=0; j<2; j++)
{
if (t_bullet[j] != NULL)
{
delete t_bullet[j];
t_bullet[j] = NULL;
}
}
if (map1 != NULL)
{
delete map1;
map1 = NULL;
}
}
void Tack::MoveTack()
{
t_lockY = t_nextY;
t_lockX = t_nextX;
if (t_lockY <= 30)
{
t_lockY = 30;
}
if (t_lockY >= 470)
{
t_lockY = 470;
}
if (t_lockX >= 540)
{
t_lockX = 540;
}
if (t_lockX <= 60)
{
t_lockX = 60;
}
}
void Tack::CreatBullet(int tackX, int tackY, int index, int bulletMode)
{
if (t_bullet[0]->b_exit==false && t_bullet[1]->b_exit==false)
{
PlaySound(TEXT("../res/sound/laser1.wav"), NULL, SND_ASYNC | SND_FILENAME | SND_NOSTOP);
for (int i=0; i<2; i++)
{
switch (index)
{
case 0: // 右
t_bullet[i]->b_point.x = tackX+i*25;
t_bullet[i]->b_point.y = tackY+15;
t_bullet[i]->b_xV = 10;
t_bullet[i]->b_yV = 0;
t_bullet[i]->b_M = bulletMode + 1;
break;
case 1: // 下
t_bullet[i]->b_point.x = tackX+15;
t_bullet[i]->b_point.y = tackY+i*25;
t_bullet[i]->b_xV = 0;
t_bullet[i]->b_yV = 10;
t_bullet[i]->b_M = bulletMode;
break;
case 2: // 上
t_bullet[i]->b_point.x = tackX+15;
t_bullet[i]->b_point.y = tackY+i*25;
t_bullet[i]->b_xV = 0;
t_bullet[i]->b_yV = -10;
t_bullet[i]->b_M = bulletMode;
break;
case 3: // 左
t_bullet[i]->b_point.x = tackX+i*25;
t_bullet[i]->b_point.y = tackY+15;
t_bullet[i]->b_xV = -10;
t_bullet[i]->b_yV = 0;
t_bullet[i]->b_M = bulletMode + 1;
break;
default:
break;
}
t_bullet[i]->b_exit = true;
}
}
}
void Tack::Shoot()
{
for (int j=0; j<2; j++)
{
if (t_bullet[j]->b_exit)
{
if (t_bullet[j]->b_point.y<=35 || t_bullet[j]->b_point.y>=500 || t_bullet[j]->b_point.x<=65 || t_bullet[j]->b_point.x>=565) // 该成有没碰撞
{
t_bullet[j]->b_exit = false;
}
else
{
t_bullet[j]->b_point.x += t_bullet[j]->b_xV;
t_bullet[j]->b_point.y += t_bullet[j]->b_yV;
if (t_bullet[j]->BulletHitMap(map1, t_bullet[j]->b_point.x, t_bullet[j]->b_point.y))
{
t_bullet[j]->b_exit = false;
}
if (t_bullet[j]->BulletHitKing(map1, t_bullet[j]->b_point.x, t_bullet[j]->b_point.y))
{
t_bullet[j]->b_exit = false;
}
}
t_bullet[j]->ShowBullet();
}
}
}
void Tack::SetRect(int x, int y)
{
t_rect.left = x;
t_rect.top = y;
t_rect.right = t_rect.left + 40;
t_rect.bottom = t_rect.top + 40;
}
bool Tack::TackHitMap(int x, int y)
{
RECT temp;
SetRect(x, y);
map1->SetKingRect();
for (int i=0; i<TILE_H; i++)
{
for (int j=0; j<TILE_W; j++)
{
if (map1->m_map[i][j]==1 || map1->m_map[i][j]==3 || map1->m_map[i][j]==4)
{
map1->SetRect(i, j);
if (IntersectRect(&temp, &t_rect, &(map1->m_rect)))
{
return true;
}
if (IntersectRect(&temp, &t_rect, &(map1->m_kingRect)))
{
return true;
}
}
}
}
return false;
}
bool Tack::TackHitTack(Tack *otherTack, int thisnewX, int thisnewY)
{
if (this == otherTack)
{
return false;
}
RECT temp;
this->t_rect.left = thisnewX;
this->t_rect.top = thisnewY;
this->t_rect.right = this->t_rect.left + 40;
this->t_rect.bottom = this->t_rect.top + 40;
otherTack->t_rect.left = otherTack->t_lockX;
otherTack->t_rect.top = otherTack->t_lockY;
otherTack->t_rect.right = otherTack->t_rect.left + 40;
otherTack->t_rect.bottom = otherTack->t_rect.top + 40;
if (IntersectRect(&temp, &(this->t_rect), &(otherTack->t_rect)))
{
return true;
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -