added 'xoffset' attribute with attack...
...which allows attacking frames to be displaced in the x-axis
This commit is contained in:
parent
ef1faef014
commit
26ef479976
3 changed files with 36 additions and 16 deletions
|
@ -1732,7 +1732,8 @@ bool display::unit_attack_ranged(const gamemap::location& a,
|
|||
const int missile_frame = i + first_missile;
|
||||
|
||||
const std::string* missile_image
|
||||
= attack.get_frame(missile_frame,attack_type::MISSILE_FRAME,dir);
|
||||
= attack.get_frame(missile_frame,NULL,
|
||||
attack_type::MISSILE_FRAME,dir);
|
||||
|
||||
static const std::string default_missile("missile-n.png");
|
||||
static const std::string default_diag_missile("missile-ne.png");
|
||||
|
@ -1890,7 +1891,13 @@ bool display::unit_attack(const gamemap::location& a,
|
|||
|
||||
draw_tile(b.x,b.y,NULL,defender_alpha,defender_colour);
|
||||
|
||||
const std::string* unit_image = attack.get_frame(i);
|
||||
int xoffset = 0;
|
||||
const std::string* unit_image = attack.get_frame(i,&xoffset);
|
||||
if(!attacker.facing_left())
|
||||
xoffset *= -1;
|
||||
|
||||
xoffset = int(double(xoffset)*(zoom_/DefaultZoom));
|
||||
|
||||
if(unit_image == NULL)
|
||||
unit_image = &attacker.image();
|
||||
|
||||
|
@ -1898,7 +1905,7 @@ bool display::unit_attack(const gamemap::location& a,
|
|||
NULL : getImage(*unit_image);
|
||||
|
||||
const double pos = double(i)/double(i < 0 ? begin_at : end_at);
|
||||
const int posx = int(pos*xsrc + (1.0-pos)*xdst);
|
||||
const int posx = int(pos*xsrc + (1.0-pos)*xdst) + xoffset;
|
||||
const int posy = int(pos*ysrc + (1.0-pos)*ydst);
|
||||
|
||||
if(image != NULL && !update_locked())
|
||||
|
|
|
@ -42,20 +42,23 @@ attack_type::attack_type(config& cfg)
|
|||
for(i = frames.begin(); i != frames.end(); ++i){
|
||||
const int beg = atoi((*i)->values["begin"].c_str());
|
||||
const int end = atoi((*i)->values["end"].c_str());
|
||||
const int xoff = atoi((*i)->values["xoffset"].c_str());
|
||||
const std::string& img = (*i)->values["image"];
|
||||
frames_[UNIT_FRAME].push_back(frame(beg,end,img));
|
||||
frames_[UNIT_FRAME].push_back(frame(beg,end,img,xoff));
|
||||
}
|
||||
|
||||
std::vector<config*>& missile_frames = cfg.children["missile_frame"];
|
||||
for(i = missile_frames.begin(); i != missile_frames.end(); ++i){
|
||||
const int beg = atoi((*i)->values["begin"].c_str());
|
||||
const int end = atoi((*i)->values["end"].c_str());
|
||||
const int xoff = atoi((*i)->values["xoffset"].c_str());
|
||||
|
||||
const std::string& img = (*i)->values["image"];
|
||||
const std::string& img_diag = (*i)->values["image_diagonal"];
|
||||
if(img_diag.empty())
|
||||
frames_[MISSILE_FRAME].push_back(frame(beg,end,img));
|
||||
frames_[MISSILE_FRAME].push_back(frame(beg,end,img,xoff));
|
||||
else
|
||||
frames_[MISSILE_FRAME].push_back(frame(beg,end,img,img_diag));
|
||||
frames_[MISSILE_FRAME].push_back(frame(beg,end,img,img_diag,xoff));
|
||||
|
||||
}
|
||||
|
||||
|
@ -121,9 +124,9 @@ int attack_type::get_last_frame(attack_type::FRAME_TYPE type) const
|
|||
return maximum<int>(frames_[type].back().end,0);
|
||||
}
|
||||
|
||||
const std::string* attack_type::get_frame(int milliseconds,
|
||||
attack_type::FRAME_TYPE type,
|
||||
attack_type::FRAME_DIRECTION dir) const
|
||||
const std::string* attack_type::get_frame(int milliseconds, int* xoff,
|
||||
attack_type::FRAME_TYPE type,
|
||||
attack_type::FRAME_DIRECTION dir) const
|
||||
{
|
||||
for(std::vector<frame>::const_iterator i = frames_[type].begin();
|
||||
i != frames_[type].end(); ++i) {
|
||||
|
@ -131,10 +134,15 @@ const std::string* attack_type::get_frame(int milliseconds,
|
|||
return NULL;
|
||||
|
||||
if(i->start <= milliseconds && i->end > milliseconds) {
|
||||
if(dir == DIAGONAL && i->image_diagonal != NULL)
|
||||
if(xoff != NULL) {
|
||||
*xoff = i->xoffset;
|
||||
}
|
||||
|
||||
if(dir == DIAGONAL && i->image_diagonal != NULL) {
|
||||
return i->image_diagonal;
|
||||
else
|
||||
} else {
|
||||
return i->image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@ public:
|
|||
//function which gets an attack animation frame. The argument
|
||||
//is 0 for the frame at the time of impact, and negative for
|
||||
//frames before the time of impact
|
||||
const std::string* get_frame(int milliseconds, FRAME_TYPE type=UNIT_FRAME,
|
||||
const std::string* get_frame(int milliseconds, int* xoffset=NULL,
|
||||
FRAME_TYPE type=UNIT_FRAME,
|
||||
FRAME_DIRECTION direction=VERTICAL) const;
|
||||
|
||||
struct sfx {
|
||||
|
@ -65,15 +66,19 @@ private:
|
|||
int num_attacks_;
|
||||
|
||||
struct frame {
|
||||
frame(int i1, int i2, const std::string& img)
|
||||
: start(i1), end(i2), image(&img), image_diagonal(NULL)
|
||||
frame(int i1, int i2, const std::string& img, int offset)
|
||||
: start(i1), end(i2), xoffset(offset),
|
||||
image(&img), image_diagonal(NULL)
|
||||
{}
|
||||
|
||||
frame(int i1, int i2, const std::string& img, const std::string& diag)
|
||||
: start(i1), end(i2), image(&img), image_diagonal(&diag)
|
||||
frame(int i1, int i2, const std::string& img, const std::string& diag,
|
||||
int offset)
|
||||
: start(i1), end(i2), xoffset(offset),
|
||||
image(&img), image_diagonal(&diag)
|
||||
{}
|
||||
|
||||
int start, end;
|
||||
int xoffset;
|
||||
const std::string* image;
|
||||
const std::string* image_diagonal;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue