예제 #1
0
        // ISSUE Player is not positioning at the beginning
        public Player(Game game, Level level)
        {
            this.level = level;

            Texture2D playerAnimationTexture;

            playerAnimationTexture = game.Content.Load<Texture2D>("reimu");
            animation = new Effect.AnimatedTexture(playerAnimationTexture, position, 18, 0.1);
            // Setup final animation sets
            animation.animationSets = new Dictionary<string, List<int>>()
            {
                {"Fly", playerAnimationFly},
                {"Left Accel", playerAnimationLeftAccel},
                {"Left", playerAnimationLeft},
                {"Right Accel", playerAnimationRightAccel},
                {"Right", playerAnimationRight},
            };
            animation.animationSet = "Fly";

            soundShoot = game.Content.Load<SoundEffect>("playershoot");

            bulletTexture = game.Content.Load<Texture2D>("bullet1");

            X = level.width / 2;
            Y = level.height / 2;
        }
예제 #2
0
        public Enemy(Game game, Level level, int x, int radius, int speedX, int speedY, int health)
        {
            this.game = game;
            this.level = level;

            this.radius = radius;

            this.health = health;

            Texture2D animationTexture;
            animationTexture = game.Content.Load<Texture2D>("enemy1fly");
            bulletTexture = game.Content.Load<Texture2D>("testbullet");

            position.X = x;
            position.Y = -animationTexture.Height;
            velocity.X = speedX;
            velocity.Y = speedY;

            animation = new Effect.AnimatedTexture(animationTexture, position, 4, 0.2);
        }
예제 #3
0
        protected override void Initialize()
        {
            base.Initialize();

            if (fullscreen == true)
            {
                List<int> optimalHeights = new List<int>();

                // Find the best full screen resolution to use to maintain a consistant aspect ratio
                GraphicsAdapter e = graphics.GraphicsDevice.Adapter;
                foreach (DisplayMode c in e.SupportedDisplayModes)
                {
                    int width = c.Width;
                    int height = c.Height;
                    double aspectRatio = (double)width / (double)height;
                    if (aspectRatio == primaryAspectRatio)
                    {
                        optimalHeights.Add(height);
                    }
                }

                // Our preferred height at a consistant aspect ratio would be 720.
                // Let's try and get as close to that as possible
                int minimalValue = -1;
                int heightValue = 0;
                int minimalIndex = -1;
                for (int i = 0; i < optimalHeights.Count; i++)
                {
                    int diff = Math.Abs(optimalHeights[i] - 480);
                    if (minimalValue < 0)
                    {
                        minimalValue = diff;
                        minimalIndex = i;
                        heightValue = optimalHeights[i];
                    }
                    else
                    {
                        if (diff < minimalValue)
                        {
                            minimalValue = diff;
                            minimalIndex = i;
                            heightValue = optimalHeights[i];
                        }
                    }
                }

                graphics.PreferredBackBufferWidth = (int)(heightValue * primaryAspectRatio);
                graphics.PreferredBackBufferHeight = heightValue;
                graphics.IsFullScreen = true;
                graphics.SynchronizeWithVerticalRetrace = false;

                graphics.ApplyChanges();

                // Our new height will MATCH the screen resolution now
                // Our width will be at that screen resolution height adjusted to the aspect ratio
                viewportHeight = heightValue;
                viewportWidth = (int)((4.0d / 3.0d) * (double)heightValue);
                int screenWidth = graphics.PreferredBackBufferWidth;
                int screenHeight = graphics.PreferredBackBufferHeight;
                int viewportX = (screenWidth - viewportWidth) / 2;
                int viewportY = (screenHeight - viewportHeight) / 2;

                graphics.ApplyChanges();

                scalingRatio = (double)heightValue / (double)gameHeight;

                targetRectangle = new Rectangle(viewportX, viewportY, viewportWidth, viewportHeight);
                screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
            }
            else
            {
                graphics.PreferredBackBufferWidth = gameWidth;
                graphics.PreferredBackBufferHeight = gameHeight;
                graphics.ApplyChanges();
                targetRectangle = new Rectangle(0, 0, gameWidth, gameHeight);
                screenRectangle = new Rectangle(0, 0, gameWidth, gameHeight);
            }

            target = new RenderTarget2D(GraphicsDevice, gameWidth, gameHeight);
            targetBatch = new SpriteBatch(GraphicsDevice);
            level = new Battle.Level(this);
        }