private static bool Collision(Position bullet, Position enemy)
        {
            if (bullet == null || enemy == null) return false;

            var bulletBounding = new RectangleF(new PointF(bullet.X, bullet.Y), new SizeF(1.5f, 1.5f));
            var enemyBounding = new RectangleF(new PointF(enemy.X - 32, enemy.Y - 32), new SizeF(64, 64));

            return bulletBounding.IntersectsWith(enemyBounding);
        }
Esempio n. 2
0
        private void Rotate(double dt, Position moveable)
        {
            var left = _keyboard.IsKeyDown(Keys.Left);
            var right = _keyboard.IsKeyDown(Keys.Right);

            var zRotMult = _keyboard.IsKeyDown(Keys.Left) ? -1 :
                           _keyboard.IsKeyDown(Keys.Right) ? 1 :
                           0;

            moveable.ZRot += (float)(zRotMult * Math.PI * dt);
        }
Esempio n. 3
0
        public static Entity Create(EntityManager manager, Position position)
        {
            var bullet = manager.CreateEntity();
            Vector3 velocity = new Vector3(0, 600, 0);
            Matrix4 rotation;
            Matrix4.Rotation(position.XRot, position.YRot, position.ZRot, out rotation);
            Matrix4.Multiply(ref rotation, ref velocity, out velocity);
            bullet.AddComponent(new Model(new[] {
                new Vector3(-1, 1, 0), new Vector3(1, 1, 0), new Vector3(1, -1, 0), new Vector3(-1, -1, 0)
            }, new[] {
                0, 1, 2, 3
            }, 1.5f));
            bullet.AddComponent(new Expiration() { MaxLifetime = 1 });
            bullet.AddComponent(new Position()
            {
                X = position.X,
                Y = position.Y,
                Z = position.Z,
                Velocity = velocity
            });
            bullet.AddComponent(new Bullet() { Damage = 0.5f });

            return bullet;
        }