/// <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. MediaPlayer.IsRepeating = true; MediaPlayer.Play(Content.Load<Song>("EpicsaxGuy")); spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("Font"); pacMan = new PacMan(Content.Load<Texture2D>("Characters/bushHead"), new Vector2(300,300)); unicornSheet = Content.Load<Texture2D>("Characters/unicornSprites"); introScreen = Content.Load<Texture2D>("IntroScreen"); thankyou = Content.Load<Texture2D>("Thankyou"); wallBox = new CollisionBoxes(Content.Load<Texture2D>("wall"), Content.Load<Texture2D>("money")); coinSound = Content.Load<SoundEffect>("chomp"); readFile(0); // TODO: use this.Content to load your game content here }
public void UpdateAI(GameTime gameTime, Random random, int time, CollisionBoxes box) { //0 = down //1 = left //2 = right //3 = up bool[] collision = getOuterWalls(box.walls); if (currentMove > 1) { currentMove -= speed; switch (currentDirection) { case 0: destRect.Y += speed; break; case 1: destRect.X -= speed; break; case 2: destRect.X += speed; break; case 3: destRect.Y -= speed; break; } }else if( currentMove == 1 && !collision[currentDirection]){ currentMove -= 1; switch (currentDirection) { case 0: destRect.Y += 1; break; case 1: destRect.X -= 1; break; case 2: destRect.X += 1; break; case 3: destRect.Y -= 1; break; } } else { if (currentMove == 1) { switch (currentDirection) { case 0: destRect.Y += 1; break; case 1: destRect.X -= 1; break; case 2: destRect.X += 1; break; case 3: destRect.Y -= 1; break; } collision = getOuterWalls(box.walls); } int newDir= (time + gameTime.ElapsedGameTime.Milliseconds + random.Next()) % 4; for (int i = 0; i < 3; i++) { newDir = (newDir+1) % 4; if (!collision[newDir]) break; } currentDirection = newDir; currentMove = 45; } animate(gameTime, currentDirection); time += random.Next(); }
public void Update(GameTime gameTime, KeyboardState prev, KeyboardState curr, CollisionBoxes coll) { timer += gameTime.ElapsedGameTime.Milliseconds; if (timer > maxTimer) { timer = 0f; current++; if (current >= frames) { current = 0; } source.X = current * width; } //movement if (prev.IsKeyUp(Keys.Space) && curr.IsKeyDown(Keys.Space)) movement = Vector2.Zero; else if(prev.IsKeyUp(Keys.Up) && curr.IsKeyDown(Keys.Up)){ movement.Y = -speed; movement.X = 0; flip = true; rotate = 90.0f; } else if (prev.IsKeyUp(Keys.Down) && curr.IsKeyDown(Keys.Down)) { movement.Y = speed; movement.X = 0; flip = false; rotate = 90.0f; } else if (prev.IsKeyUp(Keys.Right) && curr.IsKeyDown(Keys.Right)) { movement.X = speed; movement.Y = 0; rotate = 0.0f; flip = false; } else if (prev.IsKeyUp(Keys.Left) && curr.IsKeyDown(Keys.Left)) { movement.X = -speed; movement.Y = 0; rotate = 0.0f; flip = true; } //collision variables bool collision = false; Rectangle possibleMovement = new Rectangle(dest.X + (int)movement.X, dest.Y + (int)movement.Y, dest.Width,dest.Height); //check to see if collision stuff is happening foreach (Rectangle wall in coll.walls) { if (wall.Intersects(possibleMovement)) { collision = true; break; } } //if there is not collision don't move if (!collision) dest = possibleMovement; }