public void Move(Map check,GameTime gameTime) { this.TimerForAnimation += gameTime.ElapsedGameTime.TotalMilliseconds; if(TimerForAnimation >= this.TimerMax){ this.TimerForAnimation = 0; if(ChangeSet == true){ this.ChangeSet = false; } else{ this.ChangeSet = true; } } if(check.Intersect(this.Sprites.DrawPictureAt)) { if(this.yPos > this.yOld) { this.yPos -= 2; this.yOld = this.yPos; } if(this.yPos < this.yOld) { this.yPos += 2; this.yOld = this.yPos; } if(this.xPos > this.xOld) { this.xPos -= 2; this.xOld = this.xPos; } if(this.xPos < this.xOld) { this.xPos += 2; this.xOld = this.xPos; } } else{ if(Keyboard.GetState().IsKeyDown(Keys.W)){ this.yOld = this.yPos; this.yPos -= 2;//Gå fram if(this.ChangeSet){ this.index = 4;//Bilden med liten mun uppåt } else{ this.index = 5;//Bilden med stor mun uppåt } } else if(Keyboard.GetState().IsKeyDown(Keys.S)) { this.yOld = this.yPos; this.yPos += 2;//Gå fram if(this.ChangeSet){ this.index = 6;//Bilden med liten mun neråt } else{ this.index = 7;//Bilden med stor mun neråt } } else if(Keyboard.GetState().IsKeyDown(Keys.A)) { this.xOld = this.xPos; this.xPos -= 2;//Gå fram if(this.ChangeSet){ this.index = 2;//Bilden med liten mun åt höger } else{ this.index = 3; } } else if(Keyboard.GetState().IsKeyDown(Keys.D)) { this.xOld = this.xPos; this.xPos += 2;//Gå fram if(this.ChangeSet){ this.index = 0;//Bilden med lite mun åt vänster } else{ this.index = 1; } } } this.Sprites.PicturePos.X = this.xPos; this.Sprites.PicturePos.Y = this.yPos; this.Sprites.PictureIndex = this.index; }
/// <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 graphics.PreferredBackBufferHeight = 609; graphics.PreferredBackBufferWidth = 800; graphics.IsFullScreen = false; graphics.ApplyChanges(); Window.Title = "Pac-Man Projekt IV - \"C# XNA\" - Kevin Jouper Dsv"; this.ScreenX = graphics.PreferredBackBufferWidth; this.ScreenY = graphics.PreferredBackBufferHeight; this.Textures = new Texture2D[2]; this.x = 540; this.y = 250; this.pointPos = new Vector2(); this.pointPos.X = 327; this.pointPos.Y = 250; this.CurrTime = 0; this.MaxTime = 1000; this.Map = new Map(); base.Initialize(); }
public void Move(Map check,GameTime gameTime, Player PacMan,int Nr) { int PathX = -1; int PathY = -1; bool Intersect = false; for(int i = 0; i<4; i++){ if(check.Intersect(this.Sprites.DrawGhostAt[i])){ Intersect = true; if(this.yPos > this.yOld) { PathY = 0; } else if(this.yPos < this.yOld) { PathY = 1; } else if(this.xPos > this.xOld) { PathX = 1; } else if(this.xPos < this.xOld) { PathX = 0; } } } int speed = 1; if(counter == 100 && Intersect != true){ this.colid = false; } if(PathX == -1 && PathY == -1 && this.colid != true){//Gå Mot pacMan//Gå bort mot spöke this.GhostPath(PacMan,out PathX, out PathY, Nr); if(this.colid == true) { this.CXPos = PathX; this.CYPos = PathY; this.counter = 0; } } if(colid == true && Intersect != true){ counter++; PathX = this.CXPos; PathY = this.CYPos; System.Console.WriteLine("HejHopp"); } if(PathY == 0) { this.yOld = this.yPos; this.yPos -= speed; this.index = 2; } if(PathY == 1) { this.yOld = this.yPos; this.yPos += speed; this.index = 1; } if(PathX == 0) { this.xOld = this.xPos; this.xPos -= speed; this.index = 3; } if(PathX == 1) { this.xOld = this.xPos; this.xPos += speed; this.index = 0; } }