Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using System.Collections.Generic;
- using System.Linq;
- using System;
- namespace Breakout
- {
- public class Main : Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Color bgColor = new Color(40, 42, 54);
- Color paddleColor = new Color(255, 121, 198);
- Paddle player;
- SpriteFont font;
- int xRes = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
- int yRes = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
- int boop;
- Rectangle screenRectangle;
- public int screenWidth = GraphicsDeviceManager.DefaultBackBufferWidth;
- public int screenHeight = GraphicsDeviceManager.DefaultBackBufferHeight;
- // Framerate averaging
- List<int> frames = new List<int>();
- int fps;
- int averageFramerate;
- public Main()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- // Place the window in a reasonable spot and make it a reasonable size
- this.Window.Position = new Point((screenWidth / 2) - (xRes / 20), (screenHeight / 2) - (yRes / 20));
- graphics.PreferredBackBufferWidth = (int)Math.Round(xRes / 1.33);
- graphics.PreferredBackBufferHeight = (int)Math.Round(yRes / 1.33);
- // Disable fixed timestep
- this.IsFixedTimeStep = false;
- // Disable Vsync
- this.graphics.SynchronizeWithVerticalRetrace = false;
- graphics.IsFullScreen = false;
- graphics.ApplyChanges();
- this.IsMouseVisible = true;
- screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
- }
- protected override void Initialize()
- {
- base.Initialize();
- }
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- font = Content.Load<SpriteFont>("Lives");
- // Create paddle named "player" (speed, lives, width, height, bounds)
- player = new Paddle(3, 3, (screenWidth / 5), (screenHeight / 25), screenRectangle);
- }
- protected override void UnloadContent()
- {
- }
- protected override void Update(GameTime gameTime)
- {
- if (Keyboard.GetState().IsKeyDown(Keys.Escape))
- Exit();
- MouseState mouseState = Mouse.GetState();
- boop = mouseState.X;
- // Do stuff while player is alive
- while (player.Lives() > 0)
- {
- Console.WriteLine(player.Lives());
- player.Score(1);
- player.Die();
- }
- // Average the framerate to make it readable
- fps = (int)(Math.Round(1 / gameTime.ElapsedGameTime.TotalSeconds));
- frames.Add(fps);
- if (frames.Count > 1000)
- frames.RemoveAt(0);
- averageFramerate = (int)frames.Average();
- if (mouseState.LeftButton == ButtonState.Pressed) Exit();
- System.Diagnostics.Debug.WriteLine("test");
- System.Diagnostics.Debug.WriteLine(boop.ToString());
- player.Update(gameTime);
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(bgColor);
- spriteBatch.Begin();
- spriteBatch.DrawString(font, boop.ToString(), new Vector2(100, 100), Color.White);
- player.Draw(spriteBatch, player.position, paddleColor);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement