public Sprite(string assetName, float scale, bool flip, float offsetX = 0, float offsetY = 0) { this.texture = GraphicsEngine.GetInstance().textures[assetName]; this.scale = scale; this.flip = flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None; this.offsetX = offsetX; this.offsetY = offsetY; }
public override void Draw(GameTime gameTime, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch) { Rectangle destRectanle = new Rectangle(0, 0, (int)this.width, (int)this.height); spriteBatch.Draw(GraphicsEngine.GetInstance().textures["bullet"], new Vector2(this.x, this.y), destRectanle, Color.White, angle, new Vector2(0, 0), 1, SpriteEffects.None, 1); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Texture2D blankTexture = new Texture2D(GraphicsDevice, 1, 1); blankTexture.SetData(new[] { Color.White }); this.textures.Add("player", Content.Load <Texture2D>("player")); this.textures.Add("bloc", Content.Load <Texture2D>("bloc_tile")); this.textures.Add("bullet", Content.Load <Texture2D>("bullet")); this.textures.Add("grass", Content.Load <Texture2D>("grass_tile")); this.textures.Add("background", Content.Load <Texture2D>("background")); this.textures.Add("blank", blankTexture); this.textures.Add("knight_run_01", Content.Load <Texture2D>("knight_run_01")); this.textures.Add("knight_run_02", Content.Load <Texture2D>("knight_run_02")); this.textures.Add("knight_run_03", Content.Load <Texture2D>("knight_run_03")); this.textures.Add("knight_run_04", Content.Load <Texture2D>("knight_run_04")); this.textures.Add("knight_run_05", Content.Load <Texture2D>("knight_run_05")); this.textures.Add("knight_run_06", Content.Load <Texture2D>("knight_run_06")); this.textures.Add("knight_run_07", Content.Load <Texture2D>("knight_run_07")); this.textures.Add("knight_idle_01", Content.Load <Texture2D>("knight_idle_01")); this.textures.Add("knight_idle_02", Content.Load <Texture2D>("knight_idle_02")); this.textures.Add("knight_idle_03", Content.Load <Texture2D>("knight_idle_03")); this.textures.Add("knight_idle_04", Content.Load <Texture2D>("knight_idle_04")); this.textures.Add("knight_idle_05", Content.Load <Texture2D>("knight_idle_05")); this.textures.Add("knight_idle_06", Content.Load <Texture2D>("knight_idle_06")); this.textures.Add("knight_idle_07", Content.Load <Texture2D>("knight_idle_07")); this.textures.Add("knight_attack_01", Content.Load <Texture2D>("knight_attack_01")); this.textures.Add("knight_attack_02", Content.Load <Texture2D>("knight_attack_02")); this.textures.Add("knight_attack_03", Content.Load <Texture2D>("knight_attack_03")); this.textures.Add("knight_attack_04", Content.Load <Texture2D>("knight_attack_04")); this.textures.Add("knight_attack_05", Content.Load <Texture2D>("knight_attack_05")); this.textures.Add("knight_attack_06", Content.Load <Texture2D>("knight_attack_06")); this.textures.Add("knight_attack_07", Content.Load <Texture2D>("knight_attack_07")); this.fonts.Add("debug", Content.Load <SpriteFont>("debug")); PhysicsEngine.GetInstance().Init(); GraphicsEngine.GetInstance().Init(this.textures, this.fonts, this.windowHeight, this.windowWidth); this.world = new World(); }
public override void Draw(GameTime gameTime, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch) { // Rectangle destRectanle = new Rectangle(0, 0, (int)this.width, (int)this.height); // spriteBatch.Draw(GraphicsEngine.GetInstance().textures["player"], // new Vector2(this.x, this.y), // destRectanle, // Color.White, // angle, // new Vector2(0, 0), // 1, SpriteEffects.None, // 1); this.animator.Draw(gameTime, this.x, this.y, spriteBatch); spriteBatch.DrawString(GraphicsEngine.GetInstance().fonts["debug"], "Player information", new Vector2(this.x - 100, this.y - 100), Color.Black); spriteBatch.DrawString(GraphicsEngine.GetInstance().fonts["debug"], "Position: " + this.x + " - " + this.y, new Vector2(this.x - 100, this.y - 75), Color.Black); spriteBatch.DrawString(GraphicsEngine.GetInstance().fonts["debug"], "Velocity: " + this.body.speedX + " - " + this.body.speedY, new Vector2(this.x - 100, this.y - 50), Color.Black); }
public static void DrawEmptyRectangle(SpriteBatch spriteBatch, GraphicsDevice graphicsDevice, int x, int y, int width, int height, float angle, int bw = 2) { Texture2D t = GraphicsEngine.GetInstance().textures["blank"]; Rectangle destRectangle = new Rectangle(0, 0, width, height); spriteBatch.Draw(t, new Vector2(x, y), destRectangle, Color.LightGreen * 0.4f, angle, new Vector2(0, 0), 1, SpriteEffects.None, 1); // spriteBatch.Draw(t, new Rectangle(x, y, bw, height), Color.LightGreen); // Left // spriteBatch.Draw(t, new Rectangle(x + width, y, bw, height), Color.LightGreen); // Right // spriteBatch.Draw(t, new Rectangle(x, y, width, bw), Color.LightGreen); // Top // spriteBatch.Draw(t, new Rectangle(x, y + height, width, bw), Color.LightGreen); // Bottom }
public Player(float x, float y, float width, float height, float angle, World world) : base(x, y, width, height, angle, world, GameObject.Type.Player, true) { this.currentDirection = Direction.Left; this.absolute_x = GraphicsEngine.GetInstance().windowWidth / 2; this.absolute_y = GraphicsEngine.GetInstance().windowWidth / 2; string[] runAssets = new string[] { "knight_run_01", "knight_run_02", "knight_run_03", "knight_run_04", "knight_run_05", "knight_run_06", "knight_run_07" }; AnimatedSprite runRightSprite = new AnimatedSprite(runAssets, .06f, true, false); this.animator.AddAnimation("runRight", runRightSprite); AnimatedSprite runLeftSprite = new AnimatedSprite(runAssets, .06f, true, true, -30); this.animator.AddAnimation("runLeft", runLeftSprite); string[] idleAssets = new string[] { "knight_idle_01", "knight_idle_02", "knight_idle_03", "knight_idle_04", "knight_idle_05", "knight_idle_06", "knight_idle_07" }; AnimatedSprite idleRightSprite = new AnimatedSprite(idleAssets, .06f, true, false); this.animator.AddAnimation("idleRight", idleRightSprite); AnimatedSprite idleLeftSprite = new AnimatedSprite(idleAssets, .06f, true, true, -30); this.animator.AddAnimation("idleLeft", idleLeftSprite); string[] attackAssets = new string[] { "knight_attack_01", "knight_attack_02", "knight_attack_03", "knight_attack_04", "knight_attack_05", "knight_attack_06", "knight_attack_07" }; AnimatedSprite attackRightSprite = new AnimatedSprite(attackAssets, .06f, false, false); this.animator.AddAnimation("attackRight", attackRightSprite); AnimatedSprite attackLeftSprite = new AnimatedSprite(attackAssets, .06f, false, true, -30); this.animator.AddAnimation("attackLeft", attackLeftSprite); this.animator.SetCurrentAnimation("idleRight"); }
public override void Draw(GameTime gameTime, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch) { spriteBatch.Draw(GraphicsEngine.GetInstance().textures["grass"], new Vector2(x, y), Color.White); }
public void Draw(GameTime gameTime, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch) { GraphicsEngine.GetInstance().Draw(this.gameObjects, gameTime, graphicsDevice, spriteBatch); }