visual attack alert
This commit is contained in:
parent
e9c8928b49
commit
5ea9cd092a
|
@ -2235,6 +2235,7 @@ void Renderer::renderMinimap(){
|
|||
const GameCamera *gameCamera= game->getGameCamera();
|
||||
const Pixmap2D *pixmap= minimap->getTexture()->getPixmapConst();
|
||||
const Metrics &metrics= Metrics::getInstance();
|
||||
const WaterEffects *attackEffects= world->getAttackEffects();
|
||||
|
||||
int mx= metrics.getMinimapX();
|
||||
int my= metrics.getMinimapY();
|
||||
|
@ -2293,6 +2294,57 @@ void Renderer::renderMinimap(){
|
|||
glActiveTexture(baseTexUnit);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
// draw attack alarm
|
||||
for(int i=0; i<attackEffects->getWaterSplashCount(); ++i){
|
||||
const WaterSplash *ws= attackEffects->getWaterSplash(i);
|
||||
|
||||
float scale= (1/ws->getAnim()*ws->getSize())*5;
|
||||
glColor4f(1.f, 1.f, 0.f, 1.f-ws->getAnim());
|
||||
float alpha=(1.f-ws->getAnim())*0.01f;
|
||||
Vec2f pos= ws->getPos()/Map::cellScale;
|
||||
float attackX=mx +pos.x*zoom.x;
|
||||
float attackY=my +mh -pos.y*zoom.y;
|
||||
if(ws->getEnabled()){
|
||||
// glBegin(GL_QUADS);
|
||||
// glVertex2f(attackX-scale, attackY-scale);
|
||||
// glVertex2f(attackX-scale, attackY+scale);
|
||||
// glVertex2f(attackX+scale, attackY+scale);
|
||||
// glVertex2f(attackX+scale, attackY-scale);
|
||||
// glEnd();
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor4f(1.f, 1.f, 0.f, alpha);
|
||||
glVertex2f(attackX-scale, attackY-scale);
|
||||
glVertex2f(attackX-scale, attackY+scale);
|
||||
glColor4f(1.f, 1.f, 0.f, 0.8f);
|
||||
glVertex2f(attackX, attackY);
|
||||
glEnd();
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor4f(1.f, 1.f, 0.f, alpha);
|
||||
glVertex2f(attackX-scale, attackY+scale);
|
||||
glVertex2f(attackX+scale, attackY+scale);
|
||||
glColor4f(1.f, 1.f, 0.f, 0.8f);
|
||||
glVertex2f(attackX, attackY);
|
||||
glEnd();
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor4f(1.f, 1.f, 0.f, alpha);
|
||||
glVertex2f(attackX+scale, attackY+scale);
|
||||
glVertex2f(attackX+scale, attackY-scale);
|
||||
glColor4f(1.f, 1.f, 0.f, 0.8f);
|
||||
glVertex2f(attackX, attackY);
|
||||
glEnd();
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor4f(1.f, 1.f, 0.f, alpha);
|
||||
glVertex2f(attackX+scale, attackY-scale);
|
||||
glVertex2f(attackX-scale, attackY-scale);
|
||||
glColor4f(1.f, 1.f, 0.f, 0.8f);
|
||||
glVertex2f(attackX, attackY);
|
||||
glEnd();
|
||||
|
||||
}
|
||||
}
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
//draw units
|
||||
if(useQuadCache == true) {
|
||||
VisibleQuadContainerCache &qCache = getQuadCache();
|
||||
|
@ -2384,6 +2436,7 @@ void Renderer::renderMinimap(){
|
|||
glVertex2i(x2,y2);
|
||||
|
||||
glEnd();
|
||||
|
||||
glPopAttrib();
|
||||
|
||||
assertGl();
|
||||
|
|
|
@ -1706,6 +1706,7 @@ void UnitUpdater::findEnemiesForCell(const AttackSkillType *ast, Cell *cell, con
|
|||
bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr,
|
||||
const AttackSkillType *ast){
|
||||
vector<Unit*> enemies;
|
||||
Unit* enemySeen = NULL;
|
||||
bool result=false;
|
||||
//we check command target
|
||||
const Unit *commandTarget = NULL;
|
||||
|
@ -1756,7 +1757,7 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr,
|
|||
for(int i = 0; i< enemies.size(); ++i) {
|
||||
if(enemies[i]->getType()->hasSkillClass(scAttack)) {
|
||||
*rangedPtr= enemies[i];
|
||||
|
||||
enemySeen=enemies[i];
|
||||
result=true;
|
||||
break;
|
||||
}
|
||||
|
@ -1765,7 +1766,7 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr,
|
|||
//any enemy
|
||||
if(!result && (enemies.size() > 0)) {
|
||||
*rangedPtr= enemies.front();
|
||||
|
||||
enemySeen=*rangedPtr;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1774,6 +1775,7 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr,
|
|||
|
||||
if(world->getFrameCount()-lastWarnFrameCount>80) //after 100 frames attack break we warn again
|
||||
{
|
||||
world->addAttackEffects(enemySeen);
|
||||
SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound());
|
||||
}
|
||||
lastWarnFrameCount=world->getFrameCount();
|
||||
|
|
|
@ -46,13 +46,13 @@ WaterEffects::WaterEffects(){
|
|||
anim= 0;
|
||||
}
|
||||
|
||||
void WaterEffects::update(){
|
||||
void WaterEffects::update(float speed){
|
||||
anim+= 0.5f/GameConstants::updateFps;
|
||||
if(anim>1.f){
|
||||
anim= 0;
|
||||
}
|
||||
for(int i=0; i<waterSplashes.size(); ++i){
|
||||
waterSplashes[i].update(1.f/GameConstants::updateFps);
|
||||
waterSplashes[i].update(speed/GameConstants::updateFps);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ void WaterEffects::addWaterSplash(const Vec2f &pos, int size){
|
|||
}
|
||||
}
|
||||
waterSplashes.push_back(WaterSplash(pos,size));
|
||||
printf("count of watereffects=%d\n",getWaterSplashCount());
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
|
|
|
@ -63,7 +63,7 @@ private:
|
|||
public:
|
||||
WaterEffects();
|
||||
|
||||
void update();
|
||||
void update(float speed);
|
||||
|
||||
float getAmin() const {return anim;}
|
||||
|
||||
|
|
|
@ -331,7 +331,9 @@ void World::update(){
|
|||
timeFlow.update();
|
||||
|
||||
//water effects
|
||||
waterEffects.update();
|
||||
waterEffects.update(1.0f);
|
||||
// attack effects
|
||||
attackEffects.update(0.25f);
|
||||
|
||||
//bool needToUpdateUnits = true;
|
||||
//if(staggeredFactionUpdates == true) {
|
||||
|
@ -577,6 +579,12 @@ void World::moveUnitCells(Unit *unit) {
|
|||
scriptManager->onCellTriggerEvent(unit);
|
||||
}
|
||||
|
||||
void World::addAttackEffects(const Unit *unit)
|
||||
{
|
||||
attackEffects.addWaterSplash(
|
||||
Vec2f(unit->getPos().x, unit->getPos().y),1);
|
||||
}
|
||||
|
||||
//returns the nearest unit that can store a type of resource given a position and a faction
|
||||
Unit *World::nearestStore(const Vec2i &pos, int factionIndex, const ResourceType *rt) {
|
||||
float currDist= infinity;
|
||||
|
|
|
@ -106,6 +106,7 @@ private:
|
|||
|
||||
UnitUpdater unitUpdater;
|
||||
WaterEffects waterEffects;
|
||||
WaterEffects attackEffects; // onMiniMap
|
||||
Minimap minimap;
|
||||
Stats stats; //BattleEnd will delete this object
|
||||
|
||||
|
@ -161,6 +162,7 @@ public:
|
|||
const Stats *getStats() const {return &stats;};
|
||||
Stats *getStats() {return &stats;};
|
||||
const WaterEffects *getWaterEffects() const {return &waterEffects;}
|
||||
const WaterEffects *getAttackEffects() const {return &attackEffects;}
|
||||
int getNextUnitId(Faction *faction);
|
||||
int getFrameCount() const {return frameCount;}
|
||||
|
||||
|
@ -181,6 +183,7 @@ public:
|
|||
bool toRenderUnit(const Unit *unit, const Quad2i &visibleQuad) const;
|
||||
bool toRenderUnit(const Unit *unit) const;
|
||||
Unit *nearestStore(const Vec2i &pos, int factionIndex, const ResourceType *rt);
|
||||
void addAttackEffects(const Unit *unit);
|
||||
|
||||
//scripting interface
|
||||
void createUnit(const string &unitName, int factionIndex, const Vec2i &pos);
|
||||
|
|
Loading…
Reference in New Issue