public FrmMain() { InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true); UpdateStyles();// reduces flicker for high FPS Goku = new Saiyan(new Vector(800, 100), new Vector(0, 0), new Vector(0, 0), new Vector(0, 0), 0, Properties.Resources.Goku); Vegeta = new Saiyan(new Vector(100, 100), new Vector(10, 0), new Vector(0, 0), new Vector(100, 800), 0, Properties.Resources.Vegeta); tmr = new Timer(); tmr.Interval = 16;// 16 millisec = 60 frames per sec tmr.Tick += Tmr_Tick; }
public void Move(double time, bool player) { if (player == false) { if (contacts.Count > 0) // do I see anybody to attack? { Saiyan enemy = contacts[0]; // get my first enemy from my list Vector point = enemy.Pos - Pos; // face my enemy Vector unit = point.Unitized; Vel = 10 * unit; // scale up my velocity according to my speed factor of 3 } else { // I see no one to attack, so go to my goal position Vector point = Goal - Pos; // face my goal Vector unit = point.Unitized; Vel = 10 * unit; // scale up velocity } } else { Vel = Vel + Acc * time; // calc my new Velocity } Pos = Pos + Vel * time; // calc my new Position in space }