public int changeLvl(Terrain[,,] t) { if (t[Game1.lvl, this.widthCase, this.heightCase].getType == Terrain.Type.Hole_Bot) { return 1; } if (t[Game1.lvl, this.widthCase, this.heightCase].getType == Terrain.Type.Hole_Top) { return 0; } return -1; }
public static void terrainDraw(Terrain[,,] t, int lvl, int nbrWidth, int nbrHeight, SpriteBatch sp, GraphicsDevice gd) { Texture2D p = new Texture2D(gd, 1, 1, true, SurfaceFormat.Color); p.SetData(new[] { Color.White }); for (int i = 0; i < nbrWidth; i++) { for (int j = 0; j < nbrHeight; j++) { sp.Draw(p, t[lvl, i, j].rec, t[lvl, i, j].color); } } }
public Terrain[,,] dig(int direction, int X, int Y, int taille, int nbrWidth, int nbrHeight, Terrain[,,] t, GraphicsDevice gd) { if (direction == 0) { if (t[0, X, Y].getType != Terrain.Type.Hole_Bot) nbrblock++; t[0, X, Y] = new Terrain(new Rectangle(X * taille, Y * taille, taille, taille), gd, Terrain.Type.Hole_Bot); t[1, X, Y] = new Terrain(new Rectangle(X * taille, Y * taille, taille, taille), gd, Terrain.Type.Hole_Top); } if (direction == 1 && this.heightCase > 0 && t[Game1.lvl, X, Y - 1].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X, Y - 1].getType != Terrain.Type.Hole_Top) { if (t[Game1.lvl, X, Y - 1].getType == Terrain.Type.Rock) nbrblock++; t[Game1.lvl, X, Y - 1] = new Terrain(new Rectangle(X * taille, Y * taille - taille, taille, taille), gd, Terrain.Type.Air); } if (direction == 2 && this.widthCase < nbrWidth * taille && t[Game1.lvl, X + 1, Y].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X + 1, Y].getType != Terrain.Type.Hole_Top) { if (t[Game1.lvl, X + 1, Y].getType == Terrain.Type.Rock) nbrblock++; t[Game1.lvl, X + 1, Y] = new Terrain(new Rectangle(X * taille + taille, Y * taille, taille, taille), gd, Terrain.Type.Air); } if (direction == 3 && this.heightCase < nbrHeight * taille && t[Game1.lvl, X, Y + 1].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X, Y + 1].getType != Terrain.Type.Hole_Top) { if (t[Game1.lvl, X, Y + 1].getType == Terrain.Type.Rock) nbrblock++; t[Game1.lvl, X, Y + 1] = new Terrain(new Rectangle(X * taille, Y * taille + taille, taille, taille), gd, Terrain.Type.Air); } if (direction == 4 && this.widthCase > 0 && t[Game1.lvl, X - 1, Y].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X - 1, Y].getType != Terrain.Type.Hole_Top) { if (t[Game1.lvl, X - 1, Y].getType == Terrain.Type.Rock && t[Game1.lvl, X, Y - 1].getType != Terrain.Type.Hole_Bot && t[Game1.lvl, X, Y - 1].getType != Terrain.Type.Hole_Top) nbrblock++; t[Game1.lvl, X - 1, Y] = new Terrain(new Rectangle(X * taille - taille, Y * taille, taille, taille), gd, Terrain.Type.Air); } return t; }
public void move(int flag, int speed, int nbrWidth, int nbrHeight, Terrain[,,] t) { if (flag == 0) { if (rec.Y - speed >= 0 && t[Game1.lvl, this.widthCase, this.heightCase - 1].getType != Terrain.Type.Rock) { rec.Y -= speed; heightCase--; } } if (flag == 1) { if (rec.X + speed < nbrWidth * speed && t[Game1.lvl, this.widthCase + 1, this.heightCase].getType != Terrain.Type.Rock) { rec.X += speed; widthCase++; } } if (flag == 2) { if (rec.Y + speed < nbrHeight * speed && t[Game1.lvl, this.widthCase, this.heightCase + 1].getType != Terrain.Type.Rock) { rec.Y += speed; heightCase++; } } if (flag == 3) { if (rec.X - speed >= 0 && t[Game1.lvl, this.widthCase - 1, this.heightCase].getType != Terrain.Type.Rock) { rec.X -= speed; widthCase--; } } }
public Terrain[,,] put(int direction, int X, int Y, int taille, int nbrWidth, int nbrHeight, Terrain[, ,] t, GraphicsDevice gd) { if (direction == 1 && this.heightCase > 0 && t[Game1.lvl, X, Y - 1].getType == Terrain.Type.Air) { t[Game1.lvl, X, Y - 1] = new Terrain(new Rectangle(X * taille, Y * taille - taille, taille, taille), gd, Terrain.Type.Rock); nbrblock--; } if (direction == 2 && this.widthCase < nbrWidth * taille && t[Game1.lvl, X + 1, Y].getType == Terrain.Type.Air) { t[Game1.lvl, X + 1, Y] = new Terrain(new Rectangle(X * taille + taille, Y * taille, taille, taille), gd, Terrain.Type.Rock); nbrblock--; } if (direction == 3 && this.heightCase < nbrHeight * taille && t[Game1.lvl, X, Y + 1].getType == Terrain.Type.Air) { t[Game1.lvl, X, Y + 1] = new Terrain(new Rectangle(X * taille, Y * taille + taille, taille, taille), gd, Terrain.Type.Rock); nbrblock--; } if (direction == 4 && this.widthCase > 0 && t[Game1.lvl, X - 1, Y].getType == Terrain.Type.Air) { t[Game1.lvl, X - 1, Y] = new Terrain(new Rectangle(X * taille - taille, Y * taille, taille, taille), gd, Terrain.Type.Rock); nbrblock--; } return t; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here player = new Player(new Rectangle(tailleCase * (int)(nbrCaseWidth / 2), tailleCase * (int)(nbrCaseHeight / 2), tailleCase, tailleCase), Color.Green * 0.5f, GraphicsDevice, (int)(nbrCaseWidth / 2), (int)(nbrCaseHeight / 2)); lvl = 0; debug = false; help = true; t = new Terrain[2, nbrCaseWidth, nbrCaseHeight]; for (int i = 0; i < nbrCaseWidth; i++) { for (int j = 0; j < nbrCaseHeight; j++) { t[1, i, j] = new Terrain(new Rectangle(tailleCase * i, tailleCase * j, Window.ClientBounds.Width, Window.ClientBounds.Height), GraphicsDevice, Terrain.Type.Rock); t[0, i, j] = new Terrain(new Rectangle(tailleCase * i, tailleCase * j, Window.ClientBounds.Width, Window.ClientBounds.Height), GraphicsDevice, Terrain.Type.Air); } } base.Initialize(); }