Пример #1
0
 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;
     }
 }
Пример #2
0
        /// <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);
            this.Textures[0] = Content.Load<Texture2D>(".\\Textures\\Path");//Hämtar .png av vägen
            this.Textures[1] = Content.Load<Texture2D>(".\\Textures\\Wall");//Hämtar .png av väggen
            //Laddar in hur banan ska se ut från .txt med "0 / 1 / 2" där 0 är väg 1 är vägg 2 är spawn
            //Detta läggs i en matris i Map objektet!
            this.Map.LoadMap("map1.txt");
            this.Cherry = Content.Load<Texture2D>(".\\Sprites\\Cherry");
            //Ladder in sprites! Pacman, spöken osv
            this.Sprites = Content.Load<Texture2D>(".\\Sprites\\Sprites");
            this.font = Content.Load<SpriteFont>("PointFont");

            this.spriteHandler = new SpriteHandler(this.Sprites,24,4,this.Cherry);//Laddar in sprite.png bilden och delar in den i 24 bilder! och säger att vi ska ha 4 spöken samt en cherry
            this.spriteHandler.PicturePos = new Vector2(100,100);//Ändrar pos på en bilden
            this.PacMan = new Player(spriteHandler);
            this.Ghosts = new Ghost[4];
            for(int i = 0; i<4; i++){
                   this.Ghosts[i] = new Ghost(i,spriteHandler);
            }
            // TODO: use this.Content to load your game content here
        }
Пример #3
0
 private void GhostPath(Player PacMan,out int x, out int y, int Nr)
 {
     int PacManX = PacMan.xPos;//Spöken ska följa efter pacman!
     int PacManY = PacMan.yPos;
     x = -1;
     y = -1;
     int XX;
     int YY;
        for(int i = 0;i<this.Sprites.nrOfGhost;i++) {
         if(Nr != i) {
             Random Rand = new Random((PacMan.xOld *this.yPos)+(PacMan.yOld *this.xPos));
             XX = Rand.Next(0,2);
             YY = Rand.Next(0,2);
             if(this.Sprites.GhostIntersect(this.Sprites.DrawGhostAt[Nr],i)) {
                 this.colid = true;
                 if(this.TextureSet == 0) {
                     if(i == 1) { if(PacMan.xPos >this.xPos) { x = XX; y = YY; } else { x = XX; y = YY; } }//Klar
                     else if(i == 2) { if(PacMan.yPos >this.yPos) { x = XX; y = YY; } else { x = XX; y = YY; } } //Klar
                     else if(i == 3) { if(PacMan.xPos >this.xPos) { x = XX; y = YY; } else { x = XX; y = YY; } }//Klar
                 } else if(this.TextureSet == 1) {
                     if(i == 0) { if(PacMan.yPos >this.yPos) { x = XX; y = YY; } else { x = XX; y = YY; } } //Klar
                     else if(i == 2) { if(PacMan.xPos >this.xPos) { x = XX; y = YY; } else { x = XX; y = YY; } } //Klar
                     else if(i == 3) { if(PacMan.xPos >this.xPos) { x = XX; y = YY; } else { x = XX; y = YY; } }//Klar
                 } else if(this.TextureSet == 2) {
                     if(i == 0) { if(PacMan.xPos >this.xPos) { x = XX; y = YY; } else { x = XX; y = YY; } } //Klar
                     else if(i == 1) { if(PacMan.yPos >this.yPos) { x = XX; y = YY; } else { x = XX; y = YY; } } //klar
                     else if(i == 3) { if(PacMan.yPos >this.yPos) { x = XX; y = YY; } else { x = XX; y = YY; } }//Klar
                 } else if(this.TextureSet == 3) {
                     if(i == 0) { if(PacMan.yPos >this.yPos) { x = XX; y = YY; } else { x = XX; y = YY; } } //Klar
                     else if(i == 1) { if(PacMan.yPos >this.yPos) { x = XX; y = YY; } else { x = XX; y = YY; } }//Klar
                     else if(i == 2) { if(PacMan.xPos >this.xPos) { x = XX; y = YY; } else { x = XX; y = YY; } }//Klar
                 }
             }
         }
     }
     if(x == -1 && y == -1){
         if(this.xPos < PacManX) {
             x = 1;
             if(this.yPos < PacManY) {
                 y = 1;
             } else {
                 y = 0;
             }
         } else {
             x = 0;
             if(this.yPos < PacManY) {
                 y = 1;
             } else {
                 y = 0;
             }
         }
     }
 }