public CowPiece(Texture2D texture, Texture2D tailTexture, Game1 game) { this.texture = texture; this.tailTexture = tailTexture; headPosition = startPoint; nextPiece = null; isTail = false; location = startPoint; this.game = game; }
public override void Update(GameTime gameTime, DirectionToMove moveDirection, Point newHeadPosition) { base.Update(gameTime, moveDirection, newHeadPosition); if (game.GetMapManager().getSquare(location.X,location.Y).isBlocking()) { dead = true; } else if (game.GetMapManager().containsFood(location)) { CowPiece newPiece = new CowPiece(standardTexture, standardTailTexture, game); AttachPiece(newPiece); game.GetMapManager().removeFood(location); game.addToScore(); } game.GetMapManager().getSquare(location.X, location.Y).SetBlocking(true); }
public MapManager(int size, MapTextures mapTex, CowPiece head, Game1 game) { this.size = size; map = new Square[size,size]; this.grassTexture = mapTex.grassTexture; this.hedgeTexture = mapTex.hedgeTexture; this.hedgeVertTexture = mapTex.hedgeVertTexture; this.hedgeCornerTexturetl = mapTex.hedgeCornerTexturetl; this.hedgeCornerTexturetr = mapTex.hedgeCornerTexturetr; this.hedgeCornerTexturebl = mapTex.hedgeCornerTexturebl; this.hedgeCornerTexturebr = mapTex.hedgeCornerTexturebr; this.hedgeCrossTexture = mapTex.hedgeCrossTexture; this.foodTexture = mapTex.foodTexture; headPiece = head; this.game = game; createMap(); }
public void drawFood(SpriteBatch spriteBatch, CowPiece head, GameTime gameTime) { if (food != null) { Game1 g = mapManager.getGame(); float sizeOfScale = Math.Min(g.score * 0.05f, 0.5f); float scale = (float)Math.Cos(((float)gameTime.TotalGameTime.TotalMilliseconds / 1000.0f) * Math.Log(Math.Log(g.score + 1))) * sizeOfScale; if (g.score < 2) { scale = 0.0f; } scale += 1.0f; Vector2 position = new Vector2((-head.headPosition.X + xlocation) * 50, (-head.headPosition.Y + ylocation) * 50) + new Vector2(350, 250) + new Vector2(400,300); float scaledWidth = food.Width * scale; float scaledHeight = food.Height * scale; Rectangle destRect = new Rectangle((int)(position.X - ((scaledWidth -food.Width) / 2.0f)), (int)(position.Y - ((scaledHeight - food.Height) / 2.0f)), (int)scaledWidth, (int)scaledHeight); spriteBatch.Draw(food, destRect, Color.White); //spriteBatch.Draw(food, position, null, Color.White, 0.0f, Vector2.Zero, scale, SpriteEffects.None, 0.0f); } }
public void AttachPiece(CowPiece newPiece) { if (nextPiece == null) { nextPiece = newPiece; Point newLocation = Point.Zero; switch (lastMoveDirection) { case DirectionToMove.down: newLocation = new Point(location.X, location.Y - 1); break; case DirectionToMove.up: newLocation = new Point(location.X, location.Y + 1); break; case DirectionToMove.left: newLocation = new Point(location.X + 1, location.Y); break; case DirectionToMove.right: newLocation = new Point(location.X - 1, location.Y); break; } newPiece.Move(newLocation); newPiece.SetAsTail(); newPiece.lastMoveDirection = lastMoveDirection; isTail = false; newPiece.headPosition = headPosition; } else { nextPiece.AttachPiece(newPiece); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); MapTextures mapTexs = new MapTextures(); Texture2D headTexture = Content.Load<Texture2D>("drawing//Cow_Head"); Texture2D mainTexture = Content.Load<Texture2D>("drawing//Cow_Middle"); Texture2D tailTexture = Content.Load<Texture2D>("drawing//Cow_Bum"); mapTexs.grassTexture = Content.Load<Texture2D>("drawing//grass"); mapTexs.hedgeTexture = Content.Load<Texture2D>("drawing//hedge"); mapTexs.hedgeVertTexture = Content.Load<Texture2D>("drawing/hedge_v"); mapTexs.foodTexture = Content.Load<Texture2D>("drawing//food"); mapTexs.hedgeCornerTexturetl = Content.Load<Texture2D>("drawing//hedge_corner_tl"); mapTexs.hedgeCornerTexturetr = Content.Load<Texture2D>("drawing//hedge_corner_tr"); mapTexs.hedgeCornerTexturebl = Content.Load<Texture2D>("drawing//hedge_corner_bl"); mapTexs.hedgeCornerTexturebr = Content.Load<Texture2D>("drawing//hedge_corner_br"); mapTexs.hedgeCrossTexture = Content.Load<Texture2D>("drawing//hedge_cross"); mapTexs.foodTexture = Content.Load<Texture2D>("drawing//mushroom"); font = Content.Load<SpriteFont>("DefaultFont"); head = new HeadPiece(headTexture, mainTexture, tailTexture, this); CowPiece tail = new CowPiece(mainTexture, tailTexture, this); CowPiece a = new CowPiece(mainTexture, tailTexture, this); CowPiece b = new CowPiece(mainTexture, tailTexture, this); CowPiece c = new CowPiece(mainTexture, tailTexture, this); CowPiece d = new CowPiece(mainTexture, tailTexture, this); head.AttachPiece(tail); /*head.AttachPiece(a); head.AttachPiece(b); head.AttachPiece(c); head.AttachPiece(d);*/ mapManager = new MapManager(40, mapTexs, head, this); // TODO: use this.Content to load your game content here }
public void Draw(SpriteBatch spriteBatch, CowPiece head, GameTime gameTime) { Vector2 position = new Vector2((-head.headPosition.X + xlocation) * 50, (-head.headPosition.Y + ylocation) * 50) + new Vector2(350, 250) + new Vector2(400,300); spriteBatch.Draw(texture, position, null, colour, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.0f); }