コード例 #1
0
        public static void Play()
        {
            while (window.opened)
            {
                GfxTools.Clean();
                //Input

                shootCoutdown -= window.deltaTime;


                if (window.mouseLeft)
                {
                    MouseVector = new Vector2(GfxTools.Win.mouseX, GfxTools.Win.mouseY);
                }


                if (window.GetKey(KeyCode.Esc))
                {
                    break;
                }

                if (shootCoutdown <= 0)
                {
                    if (window.GetKey(KeyCode.A) && balls.Count > 0)
                    {
                        Ball ball = balls.Dequeue();
                        activeBalls.Add(ball);
                        ball.Shoot(cannonPos);
                    }

                    else if (window.GetKey(KeyCode.S) && speedBalls.Count > 0)
                    {
                        SpeedBall speedBall = speedBalls.Dequeue();
                        activeSpeedBalls.Add(speedBall);
                        speedBall.Shoot(cannonPos);
                    }

                    else if (window.GetKey(KeyCode.D) && magicBalls.Count > 0)
                    {
                        MagicBall magicBall = magicBalls.Dequeue();
                        activeMagicBalls.Add(magicBall);
                        magicBall.Shoot(cannonPos);
                    }

                    shootCoutdown = DEFAULT_SHOOT_CD;
                }
                //Update
                for (int i = activeBalls.Count - 1; i >= 0; i--)

                {
                    if (activeBalls[i].IsActive)
                    {
                        activeBalls[i].Update();
                    }

                    else
                    {
                        balls.Enqueue(activeBalls[i]);
                        activeBalls.Remove(activeBalls[i]);
                    }
                }

                for (int i = activeMagicBalls.Count - 1; i >= 0; i--)
                {
                    if (activeMagicBalls[i].IsActive)
                    {
                        activeMagicBalls[i].Update();
                    }

                    else
                    {
                        magicBalls.Enqueue(activeMagicBalls[i]);
                        activeMagicBalls.Remove(activeMagicBalls[i]);
                    }
                }

                for (int i = activeSpeedBalls.Count - 1; i >= 0; i--)

                {
                    if (activeSpeedBalls[i].IsActive)
                    {
                        activeSpeedBalls[i].Update();
                    }


                    else
                    {
                        speedBalls.Enqueue(activeSpeedBalls[i]);
                        activeSpeedBalls.Remove(activeSpeedBalls[i]);
                    }
                }


                for (int i = 0; i < activeBalls.Count; i++)
                {
                    if (activeBalls[i].IsActive)
                    {
                        activeBalls[i].Draw();
                    }
                }

                for (int i = 0; i < activeMagicBalls.Count; i++)
                {
                    if (activeMagicBalls[i].IsActive)
                    {
                        activeMagicBalls[i].Draw();
                    }
                }

                for (int i = 0; i < activeSpeedBalls.Count; i++)
                {
                    if (activeSpeedBalls[i].IsActive)
                    {
                        activeSpeedBalls[i].Draw();
                    }
                }

                window.Blit();
            }
        }