all right!, thanks for the push, I managed to make a bool like you said
made it as 'attacking'
I have a feeling this piece of code will be useful to those wanting to make an action/rpg battle system.
Im working on making a hybrid action/rpg which will soon develop into a MMO. no classes, just weapons which you learn skills from using, just like materia from ff7. It may seem overpowered but if you spend enough time in a game, shouldnt you be?
heres my code!
Code:
if(Ms.bp(0))
{if((time_to_attack-Time.d())<=0)
{Attacking=1;
time_to_attack = 1;} }
if(Attacking==1)
{ attack_motions.New().set(cskel,obj_file_path+"/human/attack.anim");
Attacking=0;
Bool in_range=inAttackRange(AIs[0]);
if(in_range)
{
hit(); // get AI looking direction
}
// check all the players
}
REPA(attack_motions)
{
Motion &motion=attack_motions[i];
if(!motion.updateAuto(3,3,1))
{attack_motions.clear();
time_to_attack=0;
}
// if "hit" event occured (event's are set in Mesh Editor tool - Animation mode)
// if finished playing then remove
}
These are definitions I needed in the Struct(Player, Chr) section
Code:
Memb<Motion> attack_motions;
bool Attacking;
void addDamage (Flt damage, Chr *src);
flt health;
flt living;
here are the corresponding actions needed to complete the player's side of battle:
Code:
void Player.create(Game.ObjParams &obj)
{ for(Game::ObjParamsPtr op=&obj; op; op=op->base())
{if(CChar *name=Game::Objs(op))
{
obj_file_path=GetPath(name);
}
}
ctrl_pos=Player.pos();
Player.health = 100;
Player.living = 1;
Attacking = 0;
time_to_attack=0;
super.create(obj);
}
void Player.addDamage(Flt damage,Chr *src)
{
health -= damage;
if(health <= 0)
die();
}
void Player::die()
{
if(Player.health <= 0)
{Player.living = 0;
Player.respawn();
}
// when dying drop down active item moved by mouse
}
Bool Player::inAttackRange(Chr &ai)
{
return Dist(pos(),ai.pos()) <= ctrl.radius()+ai.ctrl.radius()+0.6;
}
void Player::animate()
{
__super::animate();
// apply idle animations
REPA(attack_motions)cskel.animate(attack_motions[i],true); // apply attack animations
}
void Player::respawn()
{
if(Player.living==0)
{
Player.pos(ctrl_pos);
Player.living = 1;
Player.health = 100;
}
// when dying drop down active item moved by mouse
}
void Player::hit()
{
Vec dir; SinCos(dir.z,dir.x,angle.x+PI_2); dir.y=0; // get AI looking direction
// check all the players
REPA(AIs)
{
AI &mob=AIs[0];
if(Dist(pos(),mob.pos()) <= ctrl.radius()+mob.ctrl.radius()+0.6)
if(AbsAngleBetween(dir,mob.pos()-Player.pos())<=PI_3) // 60 degrees
{mob.addDamage(RandomF(10,13),this);}
}
}
PS: I did not list the AI code as I barely altered it and my player.es code should work with the default AI code if you implemented it correctly.
EDIT: I know its not perfect, as it will probably bring errors if multiple enemies come in contact with you. I will modify the code later.
EDIT2: Change AIs[0] to AIs[i] and put int i; in the Struct(Player, Chr) section.
For a better effect on swings and attacks, change the angle from PI_3 to PI_6