From dc380b2b89cdb37c9fbfc2abe2f78b6d903cf1b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dulski?= Date: Mon, 22 Apr 2019 10:39:00 +0200 Subject: [PATCH] Skalowanie tekstur --- .../DataModels/Interfaces/IDrawables.cs | 9 +++++ .../DataModels/Models/GarbageCollector.cs | 38 +++++++++++++++--- Trunk/MonoGameView/Game1.cs | 26 ++++++------ Trunk/MonoGameView/GarbageCollector.cs | 40 ------------------- Trunk/MonoGameView/MonoGameView.csproj | 4 +- 5 files changed, 56 insertions(+), 61 deletions(-) create mode 100644 Trunk/MonoGameView/DataModels/Interfaces/IDrawables.cs delete mode 100644 Trunk/MonoGameView/GarbageCollector.cs diff --git a/Trunk/MonoGameView/DataModels/Interfaces/IDrawables.cs b/Trunk/MonoGameView/DataModels/Interfaces/IDrawables.cs new file mode 100644 index 0000000..9d4bb4a --- /dev/null +++ b/Trunk/MonoGameView/DataModels/Interfaces/IDrawables.cs @@ -0,0 +1,9 @@ +using Microsoft.Xna.Framework.Graphics; + +namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces +{ + public interface IDrawables + { + void Draw(SpriteBatch spriteBatch, int size); + } +} diff --git a/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs b/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs index 00c570e..c51feca 100644 --- a/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs +++ b/Trunk/MonoGameView/DataModels/Models/GarbageCollector.cs @@ -1,14 +1,40 @@ -using System.Collections.Generic; -using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector; +using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector; using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans; -using CzokoŚmieciarka.MonoGameView.DataModels.Models; +using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace CzokoŚmieciarka.MonoGameView.DataModels.GeneralModels.Models +namespace CzokoŚmieciarka.MonoGameView.DataModels.Models { - public class GarbageCollector : AGarbageCollector + public class GarbageCollector : AGarbageCollector, IDrawables { - public GarbageCollector(Coords startPosition, IEnumerable trashContainers, int columns, int rows) : base(startPosition, trashContainers, columns, rows) + public Texture2D Image { get; set; } + public GarbageCollector(ContentManager content, Coords c, List l, int rows, int cols) : base(c,l,rows,cols) { + Image = content.Load("collector"); + } + public GarbageCollector(Texture2D image, Coords c, List l, int rows, int cols) : base(c, l, rows, cols) + { + Image = image; + } + + + public void Draw(SpriteBatch batch,int size) + { + batch.Draw(Image, new Rectangle(Coords.X*500/size, Coords.Y*500/size, 500/size, 500/size), Color.White); + } + + + public override object Clone() + { + var cloneList = new List(); + return new GarbageCollector(Image, new Coords(Coords.X,Coords.Y), cloneList, rows,columns); } } } diff --git a/Trunk/MonoGameView/Game1.cs b/Trunk/MonoGameView/Game1.cs index 2eb2b4a..8d36e9c 100644 --- a/Trunk/MonoGameView/Game1.cs +++ b/Trunk/MonoGameView/Game1.cs @@ -5,7 +5,6 @@ using CzokoŚmieciarka.MonoGameView.DataModels.Models; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; -using MonoGameView; using System; using System.Collections.Generic; using System.Linq; @@ -18,6 +17,7 @@ namespace CzokoŚmieciarka.MonoGameView /// public class Game1 : Game { + private static int size = 20; GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D road1; @@ -30,7 +30,7 @@ namespace CzokoŚmieciarka.MonoGameView int stepN; List steps; GarbageCollector collector; - object[,] grid = new object[10, 10]; + object[,] grid = new object[size, size]; public Game1() { graphics = new GraphicsDeviceManager(this); @@ -52,18 +52,18 @@ namespace CzokoŚmieciarka.MonoGameView // TODO: Add your initialization logic here roadPos = new Vector2(0, 0); timer = 0.2f; - for (int x=0;x<10;x++) + for (int x=0;x(), 10, 10); + collector = new GarbageCollector(Content,new Coords(0, 0), new List(), size, size); stepN = 0; @@ -137,17 +137,17 @@ namespace CzokoŚmieciarka.MonoGameView GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); - for (int x = 0; x < 10; x++) + for (int x = 0; x < size; x++) { - for (int y = 0; y < 10; y++) + for (int y = 0; y < size; y++) { - if (grid[x, y] is Road1) spriteBatch.Draw(road1, new Vector2(x*50,y*50), Color.White); - else if (grid[x,y] is Road2) spriteBatch.Draw(road2, new Vector2(x * 50, y * 50), Color.White); - else if (grid[x, y] is House) spriteBatch.Draw(house, new Vector2(x*50, y*50), Color.White); - else spriteBatch.Draw(grass, new Vector2(x * 50, y * 50), Color.White); + if (grid[x, y] is Road1) spriteBatch.Draw(road1, new Rectangle(x*500 / size, y*500 / size, 500/size, 500/size),Color.White); + else if (grid[x,y] is Road2) spriteBatch.Draw(road2, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White); + else if (grid[x, y] is House) spriteBatch.Draw(house, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White); + else spriteBatch.Draw(grass, new Rectangle(x * 500 / size, y * 500 / size, 500 / size, 500 / size), Color.White); } } - collector.Draw(spriteBatch); + collector.Draw(spriteBatch, size); spriteBatch.End(); // TODO: Add your drawing code here diff --git a/Trunk/MonoGameView/GarbageCollector.cs b/Trunk/MonoGameView/GarbageCollector.cs deleted file mode 100644 index 5d622e9..0000000 --- a/Trunk/MonoGameView/GarbageCollector.cs +++ /dev/null @@ -1,40 +0,0 @@ -using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.GarbageCollector; -using CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans; -using CzokoŚmieciarka.MonoGameView.DataModels.Models; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MonoGameView -{ - public class GarbageCollector : AGarbageCollector - { - public Texture2D Image { get; set; } - public GarbageCollector(ContentManager content, Coords c, List l, int rows, int cols) : base(c,l,rows,cols) - { - Image = content.Load("collector"); - } - public GarbageCollector(Texture2D image, Coords c, List l, int rows, int cols) : base(c, l, rows, cols) - { - Image = image; - } - - - public void Draw(SpriteBatch batch) - { - batch.Draw(Image, new Vector2(Coords.X*50, Coords.Y*50), Color.White); - } - - - public override object Clone() - { - var cloneList = new List(); - return new GarbageCollector(Image, new Coords(Coords.X,Coords.Y), cloneList, rows,columns); - } - } -} diff --git a/Trunk/MonoGameView/MonoGameView.csproj b/Trunk/MonoGameView/MonoGameView.csproj index 26e9658..944c79e 100644 --- a/Trunk/MonoGameView/MonoGameView.csproj +++ b/Trunk/MonoGameView/MonoGameView.csproj @@ -50,6 +50,7 @@ + @@ -64,7 +65,6 @@ - @@ -77,7 +77,7 @@ - +