public void bounce(Projectile pro, Mob mob = null) { pro.physobj.pos = Vector2.Subtract(pro.physobj.pos, pro.physobj.vel); if (mob == null) { pro.physobj.vel = Vector2.Negate(pro.physobj.vel); } else if (mob.physobj.shape == CollideMode.circle) { pro.physobj.vel = Vector2.Reflect(pro.physobj.vel, Vector2.Normalize(Vector2.Subtract(pro.physobj.pos, mob.physobj.pos))); } else if (mob.physobj.shape == CollideMode.box) { float relx = Math.Abs(pro.physobj.pos.X - mob.physobj.pos.X); float rely = Math.Abs(pro.physobj.pos.Y - mob.physobj.pos.Y); if (relx > rely) { //Console.WriteLine("x > y"); pro.physobj.vel = Vector2.Reflect(pro.physobj.vel, new Vector2(1, 0)); } else { //Console.WriteLine("y > x"); pro.physobj.vel = Vector2.Reflect(pro.physobj.vel, new Vector2(0, 1)); } } else pro.physobj.vel = Vector2.Negate(pro.physobj.vel); pro.physobj.move(); pro.angle = Physics.VectorToAngle(pro.physobj.vel); }
public void fire(List<Projectile> shots, Vector2 origin, Vector2 target) { if (curcooldown <= 0) { for (int i = 0; i < projcount; i++) { Projectile pro = new Projectile(this, new PhysicsObject(origin), target); Vector2 tvel; if (projcount > 1 && spread > 0) { //give spreads the velocity for the appropriate angle float thisang = Physics.VectorToAngle(Vector2.Subtract(target, origin)) + (i + 0.5f) * (spread / projcount) - (spread / 2); tvel = Physics.AngleToVector(thisang); } else { //standard trajectory tvel = Vector2.Normalize(Vector2.Subtract(target, origin)); } if (inaccuracy != 0) { //add some inaccuracy double thisdeviation = random.NextSample(0, inaccuracy); tvel = Vector2.Transform(tvel, Matrix.CreateRotationZ((float)thisdeviation)); } pro.physobj.vel = Vector2.Multiply(tvel, speed); pro.physobj.pos = Vector2.Subtract(pro.physobj.pos, pro.physobj.vel); pro.drawshot = drawshot; pro.duration = duration; pro.angle = Physics.VectorToAngle(pro.physobj.vel); shots.Add(pro); } curcooldown = cooldown; } }
public void burst(Projectile pro, Mob mob = null) { for (float i = 0; i < Physics.twopi; i += 0.3f) { Projectile newpro = new Projectile(GameLogic.blankattack, new PhysicsObject(pro.physobj.pos), new Vector2()); newpro.physobj.vel = Vector2.Multiply(Physics.AngleToVector(i), 10); newpro.angle = i; newpro.drawshot = 5; newpro.duration = 10; GameLogic.particles.Add(newpro); } }
public void seek(Projectile pro) { if (pro.tarmob == null) { float neardist = 99999; foreach (Enemy enemy in GameLogic.enemies) { float thisdist = Vector2.Subtract(pro.physobj.pos, enemy.physobj.pos).Length(); if ( thisdist < neardist) { neardist = thisdist; pro.tarmob = enemy; } } } Vector2 seekvec = Vector2.Multiply(Vector2.Normalize(Vector2.Subtract(pro.tarmob.physobj.pos, pro.physobj.pos)), 1.5f); pro.physobj.vel = Vector2.Add(pro.physobj.vel, seekvec); pro.angle = Physics.VectorToAngle(pro.physobj.vel); pro.physobj.chokespeed(10, 20); }
public void testhit(Projectile pro, Mob mob = null) { Console.WriteLine("BOOM!"); }
public void fizzle(Projectile pro, Mob mob = null) { pro.duration = -1; }
public void whirl(Projectile pro) { float angle = (pro.duration / 3.0f) % Physics.twopi; pro.physobj.vel = Vector2.Add(pro.physobj.vel, Physics.AngleToVector(angle)); }
public void testtick(Projectile pro) { Console.WriteLine("TICK"); }
public void spinfast(Projectile pro) { pro.angle += 0.3f; }
public void spin(Projectile pro) { pro.angle += 0.1f; }
public void speedup(Projectile pro) { pro.physobj.vel = Vector2.Multiply(pro.physobj.vel, 1.04f); }
public void slow(Projectile pro) { pro.physobj.vel = Vector2.Multiply(pro.physobj.vel, 0.97f); }
public void ontick(Projectile pro) { handletick(pro); }
public void onexpire(Projectile pro) { handleexpire(pro, null); }
public void oncollide(Projectile pro, Mob mob) { handlecollide(pro, mob); }