private void ResetTarget()
            {
                MyGameObject target = Owner.m_gameObjects[1];

                target.position.x = (Owner.DISPLAY_WIDTH - target.pixelSize.x) * (float)m_random.NextDouble();
                target.position.y = (Owner.DISPLAY_HEIGHT - target.pixelSize.y) * (float)m_random.NextDouble();
            }
            private void ApplyControl(MyGameObject agent)
            {
                agent.velocity.x = 0;
                agent.velocity.y = 0;

                int   maxAction      = 4;
                float maxActionValue = 0;

                for (int i = 0; i < 9; i++)
                {
                    if (maxActionValue < Owner.Controls.Host[i])
                    {
                        maxActionValue = Owner.Controls.Host[i];
                        maxAction      = i;
                    }
                }

                if (maxAction < 3)
                {
                    agent.velocity.y = -AGENT_VELOCITY;
                }
                else if (maxAction >= 6)
                {
                    agent.velocity.y = AGENT_VELOCITY;
                }

                if (maxAction % 3 == 0)
                {
                    agent.velocity.x = -AGENT_VELOCITY;
                }
                else if (maxAction % 3 == 2)
                {
                    agent.velocity.x = AGENT_VELOCITY;
                }
            }
Example #3
0
            private void ResetBallAndPaddle()
            {
                MyGameObject ball   = Owner.m_gameObjects[0];
                MyGameObject paddle = Owner.m_gameObjects[1];

                ball.position.x = (Owner.DISPLAY_WIDTH - ball.pixelSize.x) * 0.5f;
                ball.position.y = Owner.DISPLAY_HEIGHT - 22;

                if (RandomBallDir)
                {
                    ball.velocity.x  = (float)m_random.NextDouble() * 0.6f + 0.4f;
                    ball.velocity.x *= m_random.NextDouble() < 0.5f ? -1 : 1;
                }
                else
                {
                    ball.velocity.x = 1f;
                }
                ball.velocity.y = -1f;

                ball.velocity /= (float)Math.Sqrt(ball.velocity.x * ball.velocity.x + ball.velocity.y * ball.velocity.y);
                ball.velocity *= INIT_BALL_VELOCITY;

                paddle.position.x = (Owner.DISPLAY_WIDTH - paddle.pixelSize.x) * 0.5f;
                paddle.position.y = Owner.DISPLAY_HEIGHT - 14;

                paddle.velocity.x = 0;
                paddle.velocity.y = 0;
            }
            public override void Execute()
            {
                int offset = 0;

                Owner.m_gameObjects = new List <MyGameObject>();
                CudaDeviceVariable <float> devBitmaps = Owner.Bitmaps.GetDevice(Owner);

                Bitmap bitmap = Owner.m_bitmapTable[@"res\gridworld\agent.png"];

                MyGameObject agent = new MyGameObject()
                {
                    pixelSize = new int2(bitmap.Width, bitmap.Height),
                    bitmap    = devBitmaps.DevicePointer + devBitmaps.TypeSize * offset
                };

                offset += FillWithChannelFromBitmap(bitmap, 0, Owner.Bitmaps.Host, offset);

                bitmap = Owner.m_bitmapTable[@"res\gridworld\lightsOn.png"];

                MyGameObject target = new MyGameObject()
                {
                    pixelSize = new int2(bitmap.Width, bitmap.Height),
                    bitmap    = devBitmaps.DevicePointer + devBitmaps.TypeSize * offset
                };

                offset += FillWithChannelFromBitmap(bitmap, 0, Owner.Bitmaps.Host, offset);

                Owner.m_gameObjects.Add(agent);
                Owner.m_gameObjects.Add(target);

                Owner.Bitmaps.SafeCopyToDevice();

                Owner.UpdateTask.ResetGame();
            }
Example #5
0
        /// <summary>
        /// カーソルの用意
        /// </summary>
        private void InitCursor()
        {
            this.cursor = MyGameObject.Create <Cursor>("Cursor", this.folder);
            this.cursor.SetActive(false);

            SyncCursorPosition();
        }
 // Use this for initialization
 public override void Start()
 {
     enable    = true;
     FlyTime   = 0f;
     Vx        = MyGameObject.GetComponent <DiskData>().speed;
     Direction = MyGameObject.GetComponent <DiskData>().direction;
 }
Example #7
0
            public override void Execute()
            {
                Owner.Visual.Fill(1.0f);

                if (Owner.BricksEnabled)
                {
                    MyGameObject brick = Owner.m_brickPrototype;

                    m_bricksKernel.SetupExecution(brick.pixelSize.x * brick.pixelSize.y);
                    m_bricksKernel.Run(Owner.Visual, Owner.DISPLAY_WIDTH, Owner.DISPLAY_HEIGHT,
                                       Owner.Bricks, BRICKS_COUNT_X, BRICKS_COUNT_Y,
                                       brick.bitmap, brick.position, brick.pixelSize);
                }

                for (int i = 0; i < Owner.m_gameObjects.Count; i++)
                {
                    MyGameObject g = Owner.m_gameObjects[i];

                    m_kernel.SetupExecution(g.pixelSize.x * g.pixelSize.y);
                    m_kernel.Run(Owner.Visual, Owner.DISPLAY_WIDTH, Owner.DISPLAY_HEIGHT, g.bitmap, g.position, g.pixelSize);
                }

                MyGameObject life = Owner.m_lifePrototype;

                m_kernel.SetupExecution(life.pixelSize.x * life.pixelSize.y);

                /*
                 * for (int i = 0; i < Owner.m_lifes; i++)
                 * {
                 *  life.position.x = i * 8;
                 *  m_kernel.Run(Owner.Visual, Owner.DISPLAY_WIDTH, Owner.DISPLAY_HEIGHT, life.bitmap, life.position, life.pixelSize);
                 * }
                 * */
            }
Example #8
0
            protected void ResolvePaddleEvents(MyGameObject paddle, float control)
            {
                if (EnablePaddleDynamics)
                {
                    paddle.velocity += (control * PADDLE_ACCELERATION - paddle.velocity * PaddleFriction) * DELTA_T;

                    if (paddle.velocity.x > MAX_PADDLE_VELOCITY)
                    {
                        paddle.velocity.x = MAX_PADDLE_VELOCITY;
                    }
                    else if (paddle.velocity.x < -MAX_PADDLE_VELOCITY)
                    {
                        paddle.velocity.x = -MAX_PADDLE_VELOCITY;
                    }
                }
                else
                {
                    paddle.velocity.x = control * DELTA_T;
                }

                float2 futurePos = paddle.position + paddle.velocity;

                if (futurePos.x < 0 || futurePos.x + paddle.pixelSize.x > Owner.Scene.Width)
                {
                    paddle.velocity.x = 0;
                }

                paddle.position += paddle.velocity * DELTA_T;
            }
    protected override void AddCollider()
    {
        Vector3 upward         = (m_TargetDoll.Head.position - m_TargetDoll.Spine.position).normalized;
        int     upDownDirIndex = Utils.GetDirectionIndex(Target, upward);

        Vector3[] directionsByIndex = new Vector3[] { Target.right, Target.up, Target.forward };

        float radius = (0.5f * Vector3.Dot(m_Mesh.bounds.max - Target.position, directionsByIndex[upDownDirIndex])) / Target.lossyScale[upDownDirIndex];

        SphereCollider col = MyGameObject.AddComponent <SphereCollider>();

        Vector3 centre = Vector3.zero;

        if (Vector3.Dot(upward, directionsByIndex[upDownDirIndex]) > 0.0f)
        {
            centre[upDownDirIndex] = radius;
        }
        else
        {
            centre[upDownDirIndex] = -radius;
        }

        col.center = centre;
        col.radius = radius;
    }
Example #10
0
        /// <summary>
        /// 各種オブジェクトの生成、初期化
        /// </summary>
        public Player Init()
        {
            // プレースフォルダーを作成
            this.folder        = new GameObject("Player").transform;
            this.folder.parent = this.parent;

            // パズルを作成
            this.puzzle = new Puzzle(this.folder, this.Location.Paw);
            this.puzzle.Init();
            this.puzzle.OnVanished = OnVanished;

            // ゲージを生成
            var props = new Gauges.Props();

            props.Location = this.Location;
            props.Parent   = this.folder;

            this.gauges = new Gauges(props).Init();

            // 猫を生成
            this.cat = MyGameObject.Create <Cat>("Cat", this.folder);
            this.cat.CacheTransform.position = this.Location.Cat;
            this.cat.Init(this.catType, this.Type == Define.App.Player.P2);

            // ユニークスキルを生成
            this.unique = MyGameObject.Create <UniqueSkill>("Unique", this.folder);

            return(this);
        }
Example #11
0
            protected virtual void ResetBallAndPaddle()
            {
                MyGameObject ball   = Owner.m_gameObjects[0];
                MyGameObject paddle = Owner.m_gameObjects[1];

                ball.position.x = (Owner.Scene.Width - ball.pixelSize.x) * 0.5f;
                ball.position.y = Owner.Scene.Height - 22;

                if (RandomBallDir)
                {
                    ball.velocity.x  = (float)m_random.NextDouble() * 0.6f + 0.4f;
                    ball.velocity.x *= m_random.NextDouble() < 0.5f ? -1 : 1;
                }
                else
                {
                    ball.velocity.x = 1f;
                }
                ball.velocity.y = -1f;

                ball.velocity /= (float)Math.Sqrt(ball.velocity.x * ball.velocity.x + ball.velocity.y * ball.velocity.y);
                ball.velocity *= INIT_BALL_VELOCITY;

                paddle.position.x = (Owner.Scene.Width - paddle.pixelSize.x) * 0.5f;
                paddle.position.y = Owner.Scene.Height - 14;

                paddle.velocity.x = 0;
                paddle.velocity.y = 0;
            }
        public void IsLoaded()
        {
            GameObjectManager m = new GameObjectManager();

            var a = new MyGameObject {
                Name = "A"
            };
            var aLoadCount   = a.Properties.Get <int>("LoadCount");
            var aUnLoadCount = a.Properties.Get <int>("UnLoadCount");

            Assert.IsFalse(a.IsLoaded);
            Assert.AreEqual(0, aLoadCount.Value);
            Assert.AreEqual(0, aUnLoadCount.Value);

            m.Objects.Add(a);

            Assert.IsTrue(a.IsLoaded);
            Assert.AreEqual(1, aLoadCount.Value);
            Assert.AreEqual(0, aUnLoadCount.Value);

            a.Load(); // Does nothing.
            Assert.AreEqual(1, aLoadCount.Value);
            Assert.AreEqual(0, aUnLoadCount.Value);

            m.Objects.Remove(a);

            Assert.IsFalse(a.IsLoaded);
            Assert.AreEqual(1, aUnLoadCount.Value);

            a.Unload(); // Does nothing.
            Assert.AreEqual(1, aUnLoadCount.Value);
        }
            public override void Execute()
            {
                Owner.Event.Host[0] = 0;

                MyGameObject agent  = Owner.m_gameObjects[0];
                MyGameObject target = Owner.m_gameObjects[1];

                Owner.Controls.SafeCopyToHost();

                if (m_resetCountDown > 0)
                {
                    m_resetCountDown--;

                    if (m_resetCountDown == 0)
                    {
                        ResetAgent();
                        //ResetGame();
                    }
                }

                ApplyControl(agent);
                ResolveAgentEvents(agent, target);

                Owner.AgentPosition.Host[0] = agent.position.x + agent.pixelSize.x * 0.5f;
                Owner.AgentPosition.Host[1] = agent.position.y + agent.pixelSize.y * 0.5f;

                Owner.TargetPosition.Host[0] = target.position.x + target.pixelSize.x * 0.5f;
                Owner.TargetPosition.Host[1] = target.position.y + target.pixelSize.y * 0.5f;

                Owner.AgentPosition.SafeCopyToDevice();
                Owner.TargetPosition.SafeCopyToDevice();

                Owner.Event.SafeCopyToDevice();
            }
Example #14
0
        public void IsLoaded()
        {
            GameObjectManager m = new GameObjectManager();

              var a = new MyGameObject { Name = "A" };
              var aLoadCount = a.Properties.Get<int>("LoadCount");
              var aUnLoadCount = a.Properties.Get<int>("UnLoadCount");

              Assert.IsFalse(a.IsLoaded);
              Assert.AreEqual(0, aLoadCount.Value);
              Assert.AreEqual(0, aUnLoadCount.Value);

              m.Objects.Add(a);

              Assert.IsTrue(a.IsLoaded);
              Assert.AreEqual(1, aLoadCount.Value);
              Assert.AreEqual(0, aUnLoadCount.Value);

              a.Load();  // Does nothing.
              Assert.AreEqual(1, aLoadCount.Value);
              Assert.AreEqual(0, aUnLoadCount.Value);

              m.Objects.Remove(a);

              Assert.IsFalse(a.IsLoaded);
              Assert.AreEqual(1, aUnLoadCount.Value);

              a.Unload(); // Does nothing.
              Assert.AreEqual(1, aUnLoadCount.Value);
        }
Example #15
0
            private void ResolveBallEvents(MyGameObject ball, MyGameObject paddle)
            {
                float2 futurePos = ball.position + ball.velocity;

                //topSide
                if (futurePos.y < 0 && ball.velocity.y < 0)
                {
                    ball.velocity.y = -ball.velocity.y + (float)(m_random.NextDouble() * 0.2 - 0.1);
                }
                //leftSide
                if (futurePos.x < 0 && ball.velocity.x < 0)
                {
                    ball.velocity.x = -ball.velocity.x;
                }
                //rightSide
                if (futurePos.x + ball.pixelSize.x > Owner.DISPLAY_WIDTH && ball.velocity.x > 0)
                {
                    ball.velocity.x = -ball.velocity.x;
                }

                //bottom side
                if (futurePos.y + ball.pixelSize.y > Owner.DISPLAY_HEIGHT && ball.velocity.y > 0)
                {
                    if (stepsFrozen == 0)
                    {
                        Owner.Event.Host[0] += LOST_LIFE; // take the life at the first freeze frame
                        Owner.BinaryEvent.Host[LOST_LIFE_I] = 1;
                    }
                    if (stepsFrozen == this.FreezeAfterFail)
                    {
                        stepsFrozen = 0;
                        //Owner.Event.Host[0] += LOST_LIFE;
                        ResetGame();
                    }
                    else
                    {
                        stepsFrozen++;
                        return;
                    }
                }

                //paddle
                if (futurePos.y + ball.pixelSize.y > paddle.position.y &&
                    futurePos.y + ball.pixelSize.y < paddle.position.y + paddle.pixelSize.y &&
                    futurePos.x + 10 > paddle.position.x &&
                    futurePos.x + ball.pixelSize.x < paddle.position.x + paddle.pixelSize.x + 10 &&
                    ball.velocity.y > 0)
                {
                    ball.velocity.y  = -ball.velocity.y;
                    ball.velocity.x += paddle.velocity.x * 0.2f;

                    Owner.Event.Host[0] += BOUNCE_BALL;
                    Owner.BinaryEvent.Host[BOUNCE_BALL_I] = 1;
                }

                ball.position += ball.velocity * DELTA_T;
            }
Example #16
0
 private void EcecuteRandomPaddleShuffle()
 {
     if (RndPaddleShuffle > 0 && Owner.m_gameStepsMade % RndPaddleShuffle == 0)
     {
         MyGameObject paddle = Owner.m_gameObjects[1];
         float        rnd    = (float)m_random.NextDouble();
         paddle.position.x = rnd * (Owner.Scene.Width - paddle.pixelSize.x);
     }
 }
Example #17
0
            public override void Execute()
            {
                int offset = 0;

                Owner.m_gameObjects = new List <MyGameObject>();
                CudaDeviceVariable <float> devBitmaps = Owner.Bitmaps.GetDevice(Owner);

                Bitmap bitmap = Owner.m_bitmapTable[@"res\pong\ball.png"];

                MyGameObject ball = new MyGameObject()
                {
                    pixelSize = new int2(bitmap.Width, bitmap.Height),
                    bitmap    = devBitmaps.DevicePointer + devBitmaps.TypeSize * offset
                };

                offset += FillWithChannelFromBitmap(bitmap, 0, Owner.Bitmaps.Host, offset);

                bitmap = Owner.m_bitmapTable[@"res\pong\paddle.png"];

                MyGameObject paddle = new MyGameObject()
                {
                    pixelSize = new int2(bitmap.Width, bitmap.Height),
                    bitmap    = devBitmaps.DevicePointer + devBitmaps.TypeSize * offset
                };

                offset += FillWithChannelFromBitmap(bitmap, 0, Owner.Bitmaps.Host, offset);

                bitmap = Owner.m_bitmapTable[@"res\pong\brick.png"];

                Owner.m_brickPrototype = new MyGameObject()
                {
                    pixelSize = new int2(bitmap.Width, bitmap.Height),
                    bitmap    = devBitmaps.DevicePointer + devBitmaps.TypeSize * offset,
                    position  = new float2(0, 16)
                };
                offset += FillWithChannelFromBitmap(bitmap, 0, Owner.Bitmaps.Host, offset);

                bitmap = Owner.m_bitmapTable[@"res\pong\life.png"];

                Owner.m_lifePrototype = new MyGameObject()
                {
                    pixelSize = new int2(bitmap.Width, bitmap.Height),
                    bitmap    = devBitmaps.DevicePointer + devBitmaps.TypeSize * offset,
                    position  = new float2(0, 3)
                };
                offset += FillWithChannelFromBitmap(bitmap, 0, Owner.Bitmaps.Host, offset);

                Owner.m_gameObjects.Add(ball);
                Owner.m_gameObjects.Add(paddle);

                Owner.Bitmaps.SafeCopyToDevice();

                Owner.m_lifes = 0;
                Owner.m_level = 0;
                Owner.UpdateTask.ResetGame();
            }
Example #18
0
 /// <summary>
 /// 肉球のセットアップ
 /// </summary>
 private void InitPaws()
 {
     // 肉球を生成
     for (int i = 0; i < Define.Versus.PAW_TOTAL; ++i)
     {
         var paw = MyGameObject.Create <Paw>("Paw", this.folder);
         paw.SetActive(false);
         this.paws[i] = paw;
     }
 }
            private void ResetAgent()
            {
                MyGameObject agent = Owner.m_gameObjects[0];

                agent.position.x = (Owner.DISPLAY_WIDTH - agent.pixelSize.x) * (float)m_random.NextDouble();
                agent.position.y = (Owner.DISPLAY_HEIGHT - agent.pixelSize.y) * (float)m_random.NextDouble();

                agent.velocity.x = 0;
                agent.velocity.y = 0;
            }
Example #20
0
    /// <summary>
    /// Adds object to selected list if is not on it already,
    /// otherwise removes it from that list.
    /// </summary>
    /// <param name="o">Object to toggle</param>
    /// <returns>Is selected</returns>
    private bool ToggleSelected(MyGameObject o)
    {
        if (SelectedObjects.Contains(o))
        {
            SelectedObjects.Remove(o);
            return(false);
        }

        SelectedObjects.Add(o);
        return(true);
    }
Example #21
0
        //-------------------------------------------------------------------------
        // ライフサイクル

        protected override void MyAwake()
        {
            // ユニット生成
            this.cloud = MyGameObject.Create <Mover.Glow>("Cloud", CacheTransform);

            // 状態の構築
            this.state.Add(State.Idle);
            this.state.Add(State.Create, OnCreateEnter, OnCreateUpdate);
            this.state.Add(State.Strike, OnStrikeEnter, OnStrikeUpdte);
            this.state.Add(State.Clear, OnClearEnter, OnClearUpdate, OnClearExit);
            this.state.SetState(State.Idle);
        }
            public override void Execute()
            {
                Owner.Visual.Fill(1.0f);

                for (int i = 0; i < Owner.m_gameObjects.Count; i++)
                {
                    MyGameObject g = Owner.m_gameObjects[i];

                    m_kernel.SetupExecution(g.pixelSize.x * g.pixelSize.y);
                    m_kernel.Run(Owner.Visual, Owner.DISPLAY_WIDTH, Owner.DISPLAY_HEIGHT, g.bitmap, g.position, g.pixelSize);
                }
            }
Example #23
0
    // ############################
    protected override void AddCollider()
    {
        BoxCollider col = MyGameObject.AddComponent <BoxCollider>();

        BoxColliderParams p = Utils.CalculateBoxColliderParams(GetLowerBoundPos(),
                                                               GetUpperBoundPos(),
                                                               Target,
                                                               TargetDoll);

        col.center = p.Centre;
        col.size   = p.Size;
    }
Example #24
0
    private void SpawnSpriteObject(MyGameObject o)
    {
        GameObject spriteObject = Instantiate(SpriteObjectPrefab, gameObject.transform.Find("Sprites").transform);
        var        button       = spriteObject.GetComponent <Button>();

        button.onClick.AddListener(delegate
        {
            var isSelected     = ToggleSelected(o);
            button.image.color = isSelected ? Color.white : Color.grey;
        });
        button.image.color  = Color.grey;
        button.image.sprite = Stuff.Sprites.CharacterHexagons.SingleOrDefault(c => c.name == o.Name);
    }
Example #25
0
        //-------------------------------------------------------------------------
        // ライフサイクル

        protected override void MyAwake()
        {
            // ユニット生成
            this.cutin = MyGameObject.Create <Mover.Glow>("CutIn", CacheTransform);

            // 状態の構築
            this.state.Add(State.Idle);
            this.state.Add(State.ExpandX, OnExpandXEnter, OnExpandXUpdate);
            this.state.Add(State.ExpandY, OnExpandYEnter, OnExpandYUpdate);
            this.state.Add(State.CutIn, OnCutInEnter, OnCutInUpdate, OnCutInExit);
            this.state.Add(State.Execute, OnExecuteEnter, OnExecuteUpdate, OnExecuteExit);
            this.state.SetState(State.Idle);
        }
Example #26
0
        //-------------------------------------------------------------------------
        // ライフサイクル

        protected override void MyAwake()
        {
            // 雷を生成
            for (int i = 0; i < THUNDER_COUNT; ++i)
            {
                this.movers[i] = MyGameObject.Create <Mover.Glow>("Thunder", CacheTransform);
            }

            // 状態の構築
            this.state.Add(State.Idle);
            this.state.Add(State.Flash, OnFlashEnter, OnFlashUpdate, OnFlashExit);
            this.state.SetState(State.Idle);
        }
Example #27
0
 private void SetTargetPosition(MyGameObject target)
 {
     if (ForcePosition)
     {
         target.position.x = (Owner.DISPLAY_WIDTH - target.pixelSize.x) * XPosition;
         target.position.y = (Owner.DISPLAY_HEIGHT - target.pixelSize.y) * YPosition;
     }
     else
     {
         target.position.x = (Owner.DISPLAY_WIDTH - target.pixelSize.x) * (float)m_random.NextDouble();
         target.position.y = (Owner.DISPLAY_HEIGHT - target.pixelSize.y) * (float)m_random.NextDouble();
     }
 }
Example #28
0
        //-------------------------------------------------------------------------
        // ライフサイクル

        protected override void MyAwake()
        {
            // MainとGlowのSpriteオブジェクトを生成
            this.main = MyGameObject.Create <SpriteRenderer>("Main", CacheTransform);
            this.main.sortingOrder = Define.Layer.Order.Layer00;

            this.glow = MyGameObject.Create <SpriteRenderer>("Glow", CacheTransform);
            this.glow.sortingOrder = Define.Layer.Order.Layer00 + 1;

            // 状態の構築
            this.state.Add(State.Idle);
            this.state.Add(State.Usual, OnUsualEnter, OnUsualUpdate, OnUsualExit);
            this.state.SetState(State.Idle);
        }
Example #29
0
    void Awake()
    {
        Screen.sleepTimeout = SleepTimeout.SystemSetting;
        Script = BaseConfiguration.Script.orthographicCamera.GetComponent <Bootstrap>();

        Navigation.initializeNavigationStack(1);
        Debug.Log("BOOT");

        var page = MyGameObject.Instantiate <MainMenu> ();

        page.create();
        Navigation.initializeStack(0, page);
        Navigation.navigateToStack(0);
    }
            private void AddPaddleBToGameObjects()
            {
                MyTwoPlayerPongWorld Owner = (MyTwoPlayerPongWorld)this.Owner;

                if (Owner.m_gameObjects.Count < 3)
                {
                    MyGameObject paddleA = Owner.m_gameObjects[1];
                    MyGameObject paddleB = new MyGameObject()
                    {
                        pixelSize = new int2(paddleA.pixelSize.x, paddleA.pixelSize.y),
                        bitmap    = paddleA.bitmap
                    };
                    Owner.m_gameObjects.Add(paddleB);
                }
            }
Example #31
0
        //-------------------------------------------------------------------------
        // ライフサイクル

        protected override void MyAwake()
        {
            // MainとGlowのSpriteオブジェクトを生成
            this.main = MyGameObject.Create <SpriteRenderer>("Main", CacheTransform);
            this.main.sortingOrder = Define.Layer.Order.Layer00;

            this.glow = MyGameObject.Create <SpriteRenderer>("Glow", CacheTransform);
            this.glow.sortingOrder = Define.Layer.Order.Layer00 + 1;

            this.op.SetMover(this);
            this.op.OnIdle = () => { OnIdle?.Invoke(this); };

            // デフォルトでFlashは無効
            this.op.DisableFlash();
        }
Example #32
0
        public void Update()
        {
            GameObjectManager m = new GameObjectManager();

              m.Update(TimeSpan.FromSeconds(-0.1));
              m.Update(TimeSpan.FromSeconds(0.1));

              var a = new MyGameObject { Name = "A" };
              var aUpdateCount = a.Properties.Get<int>("UpdateCount");

              m.Objects.Add(a);
              Assert.AreEqual(0, aUpdateCount.Value);

              m.Update(TimeSpan.FromSeconds(0.1));
              Assert.AreEqual(1, aUpdateCount.Value);

              m.Update(TimeSpan.FromSeconds(0.1));
              Assert.AreEqual(2, aUpdateCount.Value);

              a.Update(TimeSpan.FromSeconds(0.1));  // Is ignored because NewFrame was not called.
              Assert.AreEqual(2, aUpdateCount.Value);
        }
            private void AddPaddleBToGameObjects()
            {
                MyTwoPlayerPongWorld Owner = (MyTwoPlayerPongWorld)this.Owner;

                if (Owner.m_gameObjects.Count < 3)
                {
                    MyGameObject paddleA = Owner.m_gameObjects[1];
                    MyGameObject paddleB = new MyGameObject()
                    {
                        pixelSize = new int2(paddleA.pixelSize.x, paddleA.pixelSize.y),
                        bitmap = paddleA.bitmap
                    };
                    Owner.m_gameObjects.Add(paddleB);
                }
            }
            protected void ResolveBallEvents(MyGameObject ball, MyGameObject paddle, MyGameObject paddleB)
            {
                MyTwoPlayerPongWorld Owner = GetTwoPlayerOwner();

                float2 futurePos = ball.position + ball.velocity;

                //leftSide
                if (futurePos.x < 0 && ball.velocity.x < 0)
                {
                    ball.velocity.x = -ball.velocity.x;
                }
                //rightSide
                if (futurePos.x + ball.pixelSize.x > Owner.Scene.Width && ball.velocity.x > 0)
                {
                    ball.velocity.x = -ball.velocity.x;
                }

                //bottom side
                if (futurePos.y + ball.pixelSize.y > Owner.Scene.Height && ball.velocity.y > 0)
                {
                    if (stepsFrozen == 0)
                    {
                        Owner.Event.Host[0] += LOST_LIFE; // take the life at the first freeze frame
                        Owner.EventB.Host[0] += OPPONENT_LOST_LIFE; // reward for the other player
                        Owner.BinaryEvent.Host[LOST_LIFE_I] = 1;
                        Owner.BinaryEventB.Host[OPPONENT_LOST_LIFE_I] = 1;
                        m_lastLost = PLAYER_A;
                    }
                    if (stepsFrozen == this.FreezeAfterFail)
                    {
                        stepsFrozen = 0;
                        ResetGame();
                    }
                    else
                    {
                        stepsFrozen++;
                        return;
                    }
                }

                //top side
                if (futurePos.y < 0 && ball.velocity.y < 0)
                {
                    if (stepsFrozen == 0)
                    {
                        Owner.EventB.Host[0] += LOST_LIFE; // take the life at the first freeze frame
                        Owner.Event.Host[0] += OPPONENT_LOST_LIFE; // reward for the other player
                        Owner.BinaryEventB.Host[LOST_LIFE_I] = 1;
                        Owner.BinaryEvent.Host[OPPONENT_LOST_LIFE_I] = 1;
                        m_lastLost = PLAYER_B;
                    }
                    if (stepsFrozen == this.FreezeAfterFail)
                    {
                        stepsFrozen = 0;
                        ResetGame();
                    }
                    else
                    {
                        stepsFrozen++;
                        return;
                    }
                }

                //paddle A
                if (futurePos.y + ball.pixelSize.y > paddle.position.y &&
                    futurePos.y + ball.pixelSize.y < paddle.position.y + paddle.pixelSize.y &&
                    futurePos.x + 10 > paddle.position.x &&
                    futurePos.x + ball.pixelSize.x < paddle.position.x + paddle.pixelSize.x + 10 &&
                    ball.velocity.y > 0)
                {
                    ball.velocity.y = -ball.velocity.y;
                    ball.velocity.x += paddle.velocity.x * 0.2f;

                    Owner.Event.Host[0] += BOUNCE_BALL;
                    Owner.BinaryEvent.Host[BOUNCE_BALL_I] = 1;
                }

                // paddle B
                if (futurePos.y < paddleB.position.y + paddleB.pixelSize.y &&
                    futurePos.y > paddleB.position.y &&
                    futurePos.x + 10 > paddleB.position.x &&
                    futurePos.x + ball.pixelSize.x < paddleB.position.x + paddleB.pixelSize.x + 10 &&
                    ball.velocity.y < 0)
                {
                    ball.velocity.y = -ball.velocity.y;
                    ball.velocity.x += paddleB.velocity.x * 0.2f;

                    Owner.EventB.Host[0] += BOUNCE_BALL;
                    Owner.BinaryEventB.Host[BOUNCE_BALL_I] = 1;
                }

                ball.position += ball.velocity * DELTA_T;
            }