Cat and ghosts moving
							parent
							
								
									4be05cff2d
								
							
						
					
					
						commit
						0229f9f055
					
				
											
												
													File diff suppressed because one or more lines are too long
												
											
										
									
								@ -1,68 +1,139 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    "name": "cat",
 | 
					    "name": "cat",
 | 
				
			||||||
    "image": "catsandghosts",
 | 
					    "image": "Master-no-background-01",
 | 
				
			||||||
    "width": 32,
 | 
					    "width": 32,
 | 
				
			||||||
    "height": 32,
 | 
					    "height": 32,
 | 
				
			||||||
    "animations": [
 | 
					    "animations": [
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            "id": 1,
 | 
					            "id": 1,
 | 
				
			||||||
            "name": "Idle",
 | 
					            "name": "Walk Left",
 | 
				
			||||||
            "frames": [
 | 
					            "frames": [
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    "id": 1,
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 32,
 | 
				
			||||||
 | 
					                    "y": 64,
 | 
				
			||||||
 | 
					                    "timer": 8
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 2,
 | 
				
			||||||
 | 
					                    "x": 64,
 | 
				
			||||||
 | 
					                    "y": 64,
 | 
				
			||||||
 | 
					                    "timer": 8
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 3,
 | 
				
			||||||
                    "x": 0,
 | 
					                    "x": 0,
 | 
				
			||||||
                    "y": 32,
 | 
					                    "y": 64,
 | 
				
			||||||
                    "timer": 0
 | 
					                    "timer": 8
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            "id": 2,
 | 
					            "id": 2,
 | 
				
			||||||
            "name": "Walk X",
 | 
					            "name": "Walk Right",
 | 
				
			||||||
            "frames": [
 | 
					            "frames": [
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    "id": 1,
 | 
					                    "id": 1,
 | 
				
			||||||
                    "x": 64,
 | 
					                    "x": 32,
 | 
				
			||||||
                    "y": 32,
 | 
					                    "y": 96,
 | 
				
			||||||
                    "timer": 8
 | 
					                    "timer": 8
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    "id": 2,
 | 
					                    "id": 2,
 | 
				
			||||||
                    "x": 32,
 | 
					                    "x": 64,
 | 
				
			||||||
                    "y": 32,
 | 
					                    "y": 96,
 | 
				
			||||||
                    "timer": 8
 | 
					                    "timer": 8
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    "id": 3,
 | 
					                    "id": 3,
 | 
				
			||||||
                    "x": 0,
 | 
					                    "x": 0,
 | 
				
			||||||
                    "y": 32,
 | 
					                    "y": 96,
 | 
				
			||||||
                    "timer": 8
 | 
					                    "timer": 8
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            "id": 3,
 | 
					            "id": 3,
 | 
				
			||||||
            "name": "Walk Y",
 | 
					            "name": "Walk Up",
 | 
				
			||||||
            "frames": [
 | 
					            "frames": [
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    "id": 1,
 | 
					                    "id": 1,
 | 
				
			||||||
                    "x": 32,
 | 
					                    "x": 32,
 | 
				
			||||||
                    "y": 64,
 | 
					                    "y": 128,
 | 
				
			||||||
                    "timer": 8
 | 
					                    "timer": 6
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    "id": 2,
 | 
					                    "id": 2,
 | 
				
			||||||
                    "x": 64,
 | 
					                    "x": 0,
 | 
				
			||||||
                    "y": 64,
 | 
					                    "y": 128,
 | 
				
			||||||
                    "timer": 8
 | 
					                    "timer": 6
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            "id": 4,
 | 
					            "id": 4,
 | 
				
			||||||
            "name": "Scared",
 | 
					            "name": "Walk Down",
 | 
				
			||||||
 | 
					            "frames": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 32,
 | 
				
			||||||
 | 
					                    "y": 160,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 2,
 | 
				
			||||||
 | 
					                    "x": 0,
 | 
				
			||||||
 | 
					                    "y": 160,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "id": 5,
 | 
				
			||||||
 | 
					            "name": "Scared Left",
 | 
				
			||||||
 | 
					            "frames": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 96,
 | 
				
			||||||
 | 
					                    "y": 64,
 | 
				
			||||||
 | 
					                    "timer": 0
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "id": 6,
 | 
				
			||||||
 | 
					            "name": "Scared Right",
 | 
				
			||||||
 | 
					            "frames": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 96,
 | 
				
			||||||
 | 
					                    "y": 96,
 | 
				
			||||||
 | 
					                    "timer": 0
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "id": 7,
 | 
				
			||||||
 | 
					            "name": "Scared Up",
 | 
				
			||||||
            "frames": [
 | 
					            "frames": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 64,
 | 
				
			||||||
 | 
					                    "y": 128,
 | 
				
			||||||
 | 
					                    "timer": 0
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "id": 8,
 | 
				
			||||||
 | 
					            "name": "Scared Down",
 | 
				
			||||||
 | 
					            "frames": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 64,
 | 
				
			||||||
 | 
					                    "y": 160,
 | 
				
			||||||
 | 
					                    "timer": 0
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,80 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "name": "ghost",
 | 
				
			||||||
 | 
					    "image": "Master-no-background-01",
 | 
				
			||||||
 | 
					    "width": 32,
 | 
				
			||||||
 | 
					    "height": 32,
 | 
				
			||||||
 | 
					    "animations": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "id": 1,
 | 
				
			||||||
 | 
					            "name": "Walk Left",
 | 
				
			||||||
 | 
					            "frames": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 0,
 | 
				
			||||||
 | 
					                    "y": 32,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 2,
 | 
				
			||||||
 | 
					                    "x": 32,
 | 
				
			||||||
 | 
					                    "y": 32,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "id": 2,
 | 
				
			||||||
 | 
					            "name": "Walk Right",
 | 
				
			||||||
 | 
					            "frames": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 0,
 | 
				
			||||||
 | 
					                    "y": 0,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 2,
 | 
				
			||||||
 | 
					                    "x": 32,
 | 
				
			||||||
 | 
					                    "y": 0,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "id": 3,
 | 
				
			||||||
 | 
					            "name": "Walk Up",
 | 
				
			||||||
 | 
					            "frames": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 64,
 | 
				
			||||||
 | 
					                    "y": 0,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 2,
 | 
				
			||||||
 | 
					                    "x": 64,
 | 
				
			||||||
 | 
					                    "y": 32,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "id": 4,
 | 
				
			||||||
 | 
					            "name": "Walk Down",
 | 
				
			||||||
 | 
					            "frames": [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 1,
 | 
				
			||||||
 | 
					                    "x": 96,
 | 
				
			||||||
 | 
					                    "y": 0,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "id": 2,
 | 
				
			||||||
 | 
					                    "x": 96,
 | 
				
			||||||
 | 
					                    "y": 32,
 | 
				
			||||||
 | 
					                    "timer": 6
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,66 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using Microsoft.Xna.Framework;
 | 
				
			||||||
 | 
					using Microsoft.Xna.Framework.Content;
 | 
				
			||||||
 | 
					using Microsoft.Xna.Framework.Graphics;
 | 
				
			||||||
 | 
					using SeeNoEvil.Level;
 | 
				
			||||||
 | 
					using SeeNoEvil.Tiled;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace SeeNoEvil.Character {
 | 
				
			||||||
 | 
					    public class GhostController {
 | 
				
			||||||
 | 
					        public List<Ghost> Ghosts {get; set;}
 | 
				
			||||||
 | 
					        public GhostController(IEnumerable<ObjectCoordinate> coordinates) {
 | 
				
			||||||
 | 
					            Ghosts = coordinates.Select(
 | 
				
			||||||
 | 
					                coord => new Ghost(new Vector2(coord.X, coord.Y))
 | 
				
			||||||
 | 
					            ).ToList();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void LoadAll(ContentManager content, PlayField playField) {
 | 
				
			||||||
 | 
					            Ghosts.ForEach(ghost => ghost.Load(content, playField));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void DrawAll(SpriteBatch spriteBatch) {
 | 
				
			||||||
 | 
					            Ghosts.ForEach(ghost => ghost.Draw(spriteBatch));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void UpdateAll() {
 | 
				
			||||||
 | 
					            Ghosts.ForEach(ghost => ghost.Update());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void MoveGhosts() {
 | 
				
			||||||
 | 
					            Ghosts.ForEach(ghost => ghost.DecideMove());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public class Ghost : Character {
 | 
				
			||||||
 | 
					        public Ghost(Vector2 position) : base(position) {
 | 
				
			||||||
 | 
					            AnimationController = new AnimationController(AnimationParser.ReadAnimationJson("SeeNoEvil/Animation/ghost.json"));
 | 
				
			||||||
 | 
					            Width = AnimationController.Width;
 | 
				
			||||||
 | 
					            Height = AnimationController.Height;
 | 
				
			||||||
 | 
					            Facing = Direction.Down;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void DecideMove() {
 | 
				
			||||||
 | 
					            Array values = Enum.GetValues(typeof(Direction));
 | 
				
			||||||
 | 
					            Random random = new Random();
 | 
				
			||||||
 | 
					            Direction randomDirection = (Direction)values.GetValue(random.Next(values.Length));
 | 
				
			||||||
 | 
					            switch(randomDirection) {
 | 
				
			||||||
 | 
					            case Direction.Up:
 | 
				
			||||||
 | 
					                AnimationController.ChangeAnimation(3);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case Direction.Down:
 | 
				
			||||||
 | 
					                AnimationController.ChangeAnimation(4);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case Direction.Left:
 | 
				
			||||||
 | 
					                AnimationController.ChangeAnimation(1);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case Direction.Right:
 | 
				
			||||||
 | 
					                AnimationController.ChangeAnimation(2);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            base.Move(randomDirection);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using Microsoft.Xna.Framework;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using SeeNoEvil.Tiled;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace SeeNoEvil.Level {
 | 
				
			||||||
 | 
					    public class PlayField {
 | 
				
			||||||
 | 
							private IEnumerable<TileLocation> Tiles {get; set;}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public PlayField(IEnumerable<TileLocation> tiles) {
 | 
				
			||||||
 | 
								Tiles = tiles;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public bool TryWalk(Vector2 newLocation) =>
 | 
				
			||||||
 | 
								Tiles.Any(tile => tile.location.Equals(newLocation));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//TODO Do all these need to be public?
 | 
				
			||||||
 | 
					namespace SeeNoEvil.Tiled {
 | 
				
			||||||
 | 
					    //TODO Can probably be a struct?
 | 
				
			||||||
 | 
					    public class ObjectLayer {
 | 
				
			||||||
 | 
					        public IEnumerable<ObjectCoordinate> Objects {get; private set;}
 | 
				
			||||||
 | 
					        public string Name {get; private set;}
 | 
				
			||||||
 | 
					        public ObjectLayer(MapLayerModel model) {
 | 
				
			||||||
 | 
					            Name = model.Name;
 | 
				
			||||||
 | 
					            Objects = model.Objects.Select(o => new ObjectCoordinate(o.Id,
 | 
				
			||||||
 | 
					                                                                     o.X,
 | 
				
			||||||
 | 
					                                                                     o.Y));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public struct ObjectCoordinate {
 | 
				
			||||||
 | 
					        public ObjectCoordinate(int id, float x, float y) {
 | 
				
			||||||
 | 
					            X = (int)Math.Round(x / 32)*32;
 | 
				
			||||||
 | 
					            Y = (int)Math.Round(y / 32)*32;
 | 
				
			||||||
 | 
					            Id = id;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public int X {get; set;}
 | 
				
			||||||
 | 
					        public int Y {get; set;}
 | 
				
			||||||
 | 
					        public int Id {get; set;}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
					Loading…
					
					
				
		Reference in New Issue