团队作业
思路描述
此次任务我负责两个部分,一是技能类,并对一些人物数值和英雄数值进行权衡,二是精灵类,对每个精灵的贴图进行汇总并绘制。
设计实现过程及代码说明
精灵类头文件
sprite.h
#pragma once
#include<stdio.h>
#include<graphics.h>
#include<windows.h>
#include<conio.h>
#include<atlimage.h>
#include<math.h>
#include<stdlib.h>
class sprite
{
public:
sprite(int num, int be)//精灵图片的数量 开始的位置
{
pic_num = num;
begin = be;
}
sprite() {
}
~sprite() {
}
int pic_num;//图片数量
int begin;
void show(int x, int y, int index, HDC hdc, CImage pic[])//index 0 开始
{
pic[(index%pic_num) + begin].Draw(hdc, x, y);
}
void show(int x, int y, int index, HDC hdc, CImage pic[], int w, int h)//重载
{
pic[(index%pic_num) + begin].Draw(hdc, x, y, w, h);
}
void show(int x, int y, int index, HDC hdc, CImage pic[], int w, int h, int Px, int Py, int Pw, int Ph)// 重载
{
pic[(index%pic_num) + begin].Draw(hdc, x, y, w, h, Px, Py, Pw, Ph);
}
};
一开始设计的精灵类只是用来存储各个精灵的图片,经过改善后,把所有的精灵图片按照编号存储在专门的数组里面,用指针来访问它,pic_num表示该精灵有多少的图片,begin表示其起始位置,这样就能访问该精灵的所有图集。重载了三个show函数用于对图像的绘制,有些图形会发生改变,如血条蓝条的长短,需要进行重载绘制,第一个为普通的绘制,第二个为只有某些固定方向变化的图形绘制,如各个物体的血条等,第三个为多个方向都变化的图形绘制,如大字爆(某个技能)会随着移动慢慢变大。
精灵类cpp文件
sprite.cpp
#include "sprite.h"
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<atlimage.h>
#include<math.h>
#include<stdlib.h>
所有的描述都在头文件中,这部分没有什么实际的内容。
技能类头文件
skill.h
#pragma once
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<atlimage.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<list>
#include<queue>
#include<iostream>
#include"skill.h"
#define red 0
#define blue 1
#define so_big 99999
class hero;
class Army;
class hurt;
class tower;
using namespace std;
class skill
{
public:
skill() {}
skill(int who_, sprite SPR_atk_[]);
~skill() {}
int CD, cost;//技能CD和消耗
int who;//技能编号
sprite *Spr_ani;//技能图标和技能效果
void skill_use(hero *, list<hurt>&, long long&);// 使用者 伤害列表 编号
bool can_use_skill(int cd_, int mp_);//可以使用当前技能
};
该部分include许多相关作用的文件,并进行了一些必要的声明。
技能类cpp文件
skill.cpp
#include "sprite.h"
#include"skill.h"
#include<string.h>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<atlimage.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<list>
#include<queue>
#include<iostream>
#include"hero.h"
#include"hurt.h"
#include"Army.h"
#include "tower.h"
using namespace std;
#pragma once
#define red 0
#define blue 1
skill::skill(int who_, sprite SPR_atk_[])
{
who = who_;
Spr_ani = SPR_atk_;
if (who_ == 1)
{
CD = 10;
cost = 10;
}
if (who_ == 2)
{
CD = 10;
cost = 10;
}
if (who_ == 3)
{
CD = 10;
cost = 10;
}
if (who_ == 4)
{
CD = 10;
cost = 10;
}
if (who_ == 5)
{
CD = 10;
cost = 10;
}
if (who_ == 6)
{
CD = 10;
cost = 10;
}
if (who_ == 7)
{
CD = 10;
cost = 10;
}
if (who_ == 8)
{
CD = 10;
cost = 10;
}
if (who_ == 9)
{
CD = 10;
cost = 10;
}
if (who_ == 10)
{
CD = 10;
cost = 10;
}
if (who_ == 11)
{
CD = 10;
cost = 10;
}
if (who_ == 12)
{
CD = 10;
cost = 10;
}
}
void skill::skill_use(hero *user, list<hurt> &Magic, long long &object_ID)
{
if (who == 1)//疾跑
{
user->fast = 1;
user->fast_time = 100;
}
else if (who == 2)//狂暴
{
user->angry = 1;
user->angry_time = 100;
}
else if (who == 3)//寄生种子
{
int tx, ty;
tx = user->x + 24 - 16;
ty = user->y + 24 - 16;
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 8, *(Spr_ani + 2), user->atk, user, user->fx));
user->sleep = 1;
user->weak_time = 5;//技能硬直
}
else if (who == 4)//百万吨拳击
{
int tx, ty;
int ax, ay;
ax = user->x + user->wide;
ay = user->y + user->hight;
if (user->fx == 0)
{
tx = ax + 24;
ty = ay - 24 - 16;
}
if (user->fx == 90)
{
tx = ax - 16;
ty = ay - 24 - 64;
}
if (user->fx == 180)
{
tx = ax - 24 - 32;
ty = ay - 24 - 16;
}
if (user->fx == 270)
{
tx = ax - 16;
ty = ay + 24;
}
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 3, *(Spr_ani + 4), user->atk, user, user->fx));
user->sleep = 1;
user->weak_time = 5;//技能硬直
}
else if (who == 5)//催眠粉
{
int tx, ty;
tx = user->x + 24 - 32;
ty = user->y + 24 - 32;
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 2, *(Spr_ani + 5), 0, user, user->fx));
user->sleep = 1;
user->weak_time = 5;//技能硬直
}
else if (who == 6)//大字爆
{
int tx, ty;
tx = user->x + 24;
ty = user->y + 24;
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 5, *(Spr_ani + 7), user->atk, user, user->fx));
user->sleep = 1;
user->weak_time = 5;//技能硬直
}
else if (who == 7)//飞叶快刀
{
int tx, ty;
tx = user->x;
ty = user->y;
for (int i = 0; i<360; i += 45)
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 6, *(Spr_ani + 9), user->atk, user, i));
user->sleep = 1;
user->weak_time = 5;//技能硬直
}
else if (who == 8)//喷射火焰
{
int tx, ty;
tx = user->x + 24 - 16;
ty = user->y + 24 - 16;
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 9, *(Spr_ani + 3), user->atk, user, user->fx));
user->sleep = 1;
user->weak_time = 5;//技能硬直
}
else if (who == 9)//阳光烈焰
{
int tx, ty;
tx = user->x + 24 - 80;
ty = user->y + 24 - 80;
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 4, *(Spr_ani + 8), user->atk, user, user->fx));
user->sleep = 1;
user->weak_time = 20;//技能硬直
}
else if (who == 10)//铁壁
{
user->wudi = 1;
user->wudi_time = 50;
}
else if (who == 11)//泡泡攻击
{
int tx, ty;
tx = user->x + 24 - 16;
ty = user->y + 24 - 16;
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 1, *(Spr_ani), user->atk, -1, user));
user->sleep = 1;
user->weak_time = 5;//技能硬直
}
else//水炮
{
int tx, ty, fx_;
tx = user->x + 24 - 16;
ty = user->y + 24 - 16;
fx_ = user->fx;
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 7, *(Spr_ani), user->atk, user, fx_));
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 7, *(Spr_ani), user->atk, user, (fx_ + 45) % 360));
Magic.push_back(hurt(tx, ty, user->color, object_ID++, 7, *(Spr_ani), user->atk, user, (fx_ - 45 + 360) % 360));
user->sleep = 1;
user->weak_time = 5;//技能硬直
}
}
bool skill::can_use_skill(int cd_, int mp_) {
if (cd_ >= CD && mp_ >= cost)
return true;
return false;
}
- 第一部分对各个技能进行初始化,who表示技能编号用于识别,检索编号,赋予对应的cd和蓝耗。
- 第二部分为各个技能的相关描述hero *user用于对英雄自身有作用的技能时的指针,伤害列表的引用Magic将技能创造出来的hurt类实体塞到伤害列表里, long long &object_ID是每个物体的编号,技能创造的伤害也是一个物体,要对新的hurt实体一个新的编号,即object_ID++。技能内容各有不同,不多叙述。
- 第三部分判断当前的蓝量是否足够释放技能。
花费时间
精灵类从构想到实现结合资料查询大概一个多小时,技能类需要进行赋值以及对对各个参数的平衡与消弱改善,以及对各个技能的效果的改善,比较繁琐,用时三个小时左右。
遇到的问题
绘图问题一直很困扰,查了许多的资料也不太看的懂,最后只能用最粗暴的方法解决,先绘制背景再在背景上绘制各个物体,再次用背景覆盖掉所有内容,再次绘制新的物体,如此往复。