Beispiel #1
0
 private void OnUpdateFlagAnd32Bit(uint flag, uint val)
 {
     if (flag == UpdateRayTestDistance)
     {
         RayTestResult.BeginInvoke(new PFN_UpdateFlagAnd32Bit(InvokeUpdateRayTestResult), flag, val);
     }
 }
        protected override void Update(double deltaTime)
        {
            var cam  = MMW.MainCamera;
            var from = cam.Transform.WorldPosition;
            var to   = from + ((cam.Target - from).Normalized() * Distance);

            rays = Bullet.RayTest(from, to, GameObject);

            var prev = closed;

            closed = null;
            foreach (var r in rays)
            {
                if (r.GameObject.Destroyed)
                {
                    continue;
                }
                closed = r;
                break;
            }

            float rot = 0.0f;

            {
                var t = (cam.Target - from);
                t.Y = 0.0f;
                t.Normalize();
                rot = Vector3.CalculateAngle(-Vector3.UnitZ, t);
                var cross = Vector3.Cross(-Vector3.UnitZ, t);
                rot *= cross.Y >= 0.0f ? -1.0f : 1.0f;
            }

            if (closed != null)
            {
                data.gameobject = closed.GameObject;
                data.position   = closed.Position;
                data.normal     = closed.Normal;
                data.rotate     = new Vector3(0.0f, rot, 0.0f);
                data.distance   = Distance * closed.Rate;
            }

            if (prev == null && closed != null)
            {
                MMW.BroadcastMessage("focus enter", closed.GameObject, data);
            }
            else if (prev != null && closed == null)
            {
                MMW.BroadcastMessage("focus leave", prev.GameObject, data);
            }
            else if (prev != null && closed != null && prev != closed)
            {
                MMW.BroadcastMessage("focus leave", prev.GameObject, data);
                MMW.BroadcastMessage("focus enter", closed.GameObject, data);
            }
        }
Beispiel #3
0
        protected override void Update(double deltaTime)
        {
            if (time > 0.0)
            {
                time -= deltaTime;
            }

            if (time < 0.0 && totalCoin < maxCoin)
            {
                time += userData.CoinSpownTime;

                var r    = Util.RandomInt(0, 100);
                var coin = cupperCoin;
                if (r >= 90)
                {
                    coin = silverCoin;
                }
                else if (r == 99)
                {
                    coin = goldCoin;
                }

                RayTestResult res  = null;
                int           test = 5;
                while (test > 0)
                {
                    var x   = MMWMath.Lerp(bounds.Min.X, bounds.Max.X, Util.RandomFloat());
                    var z   = MMWMath.Lerp(bounds.Min.Z, bounds.Max.Z, Util.RandomFloat());
                    var pos = new Vector4(x, 0.0f, z, 1.0f) * Transform.WorldTransform;

                    var rays = Bullet.RayTest(new Vector3(pos.X, 100.0f, pos.Z), new Vector3(pos.X, -50.0f, pos.Z));
                    if (rays.Count > 0 && rays[0].GameObject.Tags.Contains("world"))
                    {
                        res = rays[0];
                        break;
                    }

                    test--;
                }

                if (res != null)
                {
                    var go = new NwWalkerGameObject()
                    {
                        CreateDate  = DateTime.Now.ToString(),
                        CreatorName = MMW.GetAsset <UserData>().UserName,
                        Hash        = Util.CreateHash(12),
                        Name        = "coin",
                        ObjectHash  = coin.Hash,
                        Position    = (res.Position + Vector3.UnitY * 0.2f).ToVec3f(),
                        Rotation    = new Vector3f(),
                        Scale       = new Vector3f(1, 1, 1),
                        SessionID   = MMW.GetAsset <UserData>().SessionID,
                        UserID      = MMW.GetAsset <UserData>().UserID,
                    };

                    MMW.FindGameComponent <WalkerScript>().PutGameObject(go, false);
                    totalCoin++;
                }
            }
        }