示例#1
0
 public SpaceShip(GameCore gameRef, Sprite sprite)
 {
     this.game = gameRef;
     this.sprite = sprite;
     health = new Health(10);
     guns = new Gun[1];
     guns[0] = new Gun(game,77,27);
 }
示例#2
0
 public Gun(GameCore gameRef, int x, int y)
 {
     this.game = gameRef;
     sprite = game.resources.LoadSprite("resources/gfx/bullet.png");
     fireRate = 150;
     this.x = x;
     this.y = y;
 }
示例#3
0
 public Sprite LoadSprite(string filePath)
 {
     Sprite sprite = GetSprite(filePath);
     if (sprite != null)
     {
         sprite.loadCount += 1;
         return sprite;
     }
     else
     {
         sprite = new Sprite(filePath);
         sprites.Add(sprite);
         return sprite;
     }
 }
示例#4
0
        public static bool HasHit(Point point1, Point point2, Sprite sprite1, Sprite sprite2)
        {
            Rectangle rec1 = new Rectangle(point1, sprite1.imageRec.Size);
            Rectangle rec2 = new Rectangle(point2, sprite2.imageRec.Size);

            if (rec1.IntersectsWith(rec2))
            {
                return CheckCollisionData(rec1, rec2, sprite1, sprite2);
                //return true;
            }

            return false;
        }
示例#5
0
        private static bool CheckCollisionData(Rectangle rec1, Rectangle rec2, Sprite sprite1, Sprite sprite2)
        {
            Rectangle inter = rec1;
            inter.Intersect(rec2);

            for (int ix = inter.X; ix < inter.X + inter.Width; ix++)
            {
                for (int iy = inter.Y; iy < inter.Y + inter.Height; iy++)
                {
                    if (sprite1.collisionData[ix - rec1.X, iy - rec1.Y] >= 96)
                    {
                        if (sprite2.collisionData[ix - rec2.X, iy - rec2.Y] >= 150)
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
示例#6
0
 public Bullet(Sprite sprite, bool playerIsOwner)
 {
     dead = false;
     this.sprite = sprite;
     this.playerIsOwner = playerIsOwner;
 }
示例#7
0
        public void Load(string filePath)
        {
            string platformPath = Globals.MakePathPlatformSpecific(filePath);
            if (!File.Exists(platformPath))
            { throw new FileNotFoundException("File not found.", platformPath); }

            StreamReader sr = new StreamReader(platformPath);

            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
                if (line.Contains("="))
                {
                    string[] split = line.Split(Convert.ToChar("="));

                    switch (split[0])
                    {
                        case "name":
                            name = split[1];
                            break;
                        case "image":
                            sprite = game.resources.LoadSprite(split[1]);
                            break;
                        case "health":
                            health = new Health(int.Parse(split[1]));
                            break;
                        case "guntype":
                            ReadGun(split[1]);
                            break;
                    }
                }
            }
            sr.Close();
            sr.Dispose();
        }
示例#8
0
 public Gun(GameCore gameRef)
 {
     this.game = gameRef;
     sprite = game.resources.LoadSprite("resources/gfx/bullet.png");
     fireRate = 150;
 }