示例#1
0
            public static new HealthPack ReadFrom(System.IO.BinaryReader reader)
            {
                var result = new HealthPack();

                result.Health = reader.ReadInt32();
                return(result);
            }
示例#2
0
文件: Game.cs 项目: XShulerX/Project
        /// <summary>Обновление состояния объектов сцены</summary>
        public static void Update()
        {
            foreach (var visual_object in __GameObjects)
            {
                visual_object?.Update();
            }

            var bullets_to_remove = new List <Bullet>();

            foreach (var bullet in __Bullets)
            {
                bullet.Update();
                if (bullet.Position.X > Width)
                {
                    bullets_to_remove.Add(bullet);
                }
            }
            for (var i = 0; i < __GameObjects.Length; i++)
            {
                var obj = __GameObjects[i];
                if (obj is ICollision collision_object) // Применить "сопоставление с образцом"!
                {
                    collision_object = (ICollision)obj;
                    __Ship.CheckCollision(collision_object);
                    if (__Ship.CheckCollision(collision_object) && collision_object is HealthPack healthPack)
                    {
                        __GameObjects[i] = new HealthPack(
                            new Point(Width, new Random().Next(0, Height)),
                            new Point(-5),
                            new Size(20, 20));
                    }
                    foreach (var bullet in __Bullets.ToArray())
                    {
                        if (bullet.CheckCollision(collision_object))
                        {
                            bullets_to_remove.Add(bullet);
                            for (var j = 0; j < __Asteroids.Count; j++)
                            {
                                if (__Asteroids[j].Equals(__GameObjects[i]))
                                {
                                    __GameObjects[i] = null;
                                    __Asteroids.RemoveAt(j);
                                    break;
                                }
                            }

                            _Score += 10;
                        }
                    }
                }
            }
            foreach (var bullet in bullets_to_remove)
            {
                __Bullets.Remove(bullet);
            }
            if (__Asteroids.Count == 0)
            {
                AllAsteroidsDestroyed?.Invoke(__Ship, EventArgs.Empty);
            }
        }
示例#3
0
        private Entity MakeLifeSaver()
        {
            float  y = (float)((r.NextDouble()) * ScreenHelper.Viewport.Height);
            Sprite s = new Sprite(new Vector2(ScreenHelper.Viewport.Width, y), lifeSaver, AnimationType.None);

            Entity e = new HealthPack(5, s, 200f);

            return(e);
        }
示例#4
0
    void populateAllHPacks()
    {
        List <System.Object[]> read = DBAccess.instance.getPurchasedHealthpacks();

        for (int i = 0; i < read.Count; i++)
        {
            HealthPack h = new HealthPack(read[i]);
            allHPacks.Insert(i, h);
        }
    }
 void Start()
 {
     currentHealth         = fullHealth;
     myAnim                = GetComponent <Animator>();
     player                = GetComponent <player>();
     hp                    = GetComponent <HealthPack>();
     myAudioSource         = GetComponent <AudioSource>();
     healthSlider.maxValue = fullHealth;
     healthSlider.minValue = 0f;
     healthSlider.value    = currentHealth;
 }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        HealthPack healthPack = (HealthPack)target;

        if (GUILayout.Button("Generate ID"))
        {
            healthPack.healthPackID = System.Guid.NewGuid().ToString();
            EditorUtility.SetDirty(healthPack);
        }
    }
示例#7
0
 void Awake()
 {
     temp           = GameObject.FindGameObjectWithTag("Player");
     playerCollider = temp.GetComponent <BoxCollider2D> ();
     playerHealth   = temp.GetComponent <PlayerHealth> ();
     pack           = GameObject.Find("pack1").GetComponent <HealthPack> ();
     pack.enabled   = true;
     fader          = GameObject.Find("Fader").GetComponent <ScreenFader> ();
     textManager    = GameObject.Find("TextCanvas").GetComponent <TextManager> ();
     textManager.RoundStarting();
     fader.gameStarting = true;
 }
示例#8
0
 public void receiveHealth(HealthPack pack)
 {
     if (stats.curHP < stats.maxHP)
     {
         stats.curHP += pack.healAmount;
         if (stats.curHP > stats.maxHP)
         {
             stats.curHP = stats.maxHP;
         }
         pack.destroyPack();
     }
 }
示例#9
0
        private void CreateObject(TmxObject obj, Rectangle source, TmxTileset tileset, Texture2D tilesetTexture)
        {
            var    random        = new Random();
            var    type          = tileset.Tiles[obj.Tile.Gid - tileset.FirstGid].Type;
            var    rotation      = MathHelper.ToRadians((float)obj.Rotation);
            var    spawnPosition = GetObjectPosition(obj, source);
            Entity entity;

            switch (type)
            {
            case "Car":
                entity = new Car(this, tilesetTexture, (int)obj.Width, (int)obj.Height, spawnPosition,
                                 rotation, source);
                break;

            case "Enemy_Spawn":
                entity = new Enemy(tilesetTexture, spawnPosition, (int)obj.Width, (int)obj.Height, this,
                                   rotation, source);
                break;

            case "Dungeon_Entrance":
                entity = new DungeonEntrance(new ShooterScreen(), screenManager, tilesetTexture, (int)obj.Width,
                                             (int)obj.Height, spawnPosition, rotation, source);
                break;

            case "Collectable":
                entity = new Collectable(tilesetTexture, spawnPosition, (int)obj.Width, (int)obj.Height, rotation, source);
                break;

            case "Ammo":
                var randomBulletType = (BulletType)random.Next(Enum.GetNames(typeof(BulletType)).Length);
                entity = new AmmoPack(randomBulletType, random.Next(15, 30), tilesetTexture, spawnPosition,
                                      (int)obj.Width, (int)obj.Height, rotation, source);
                break;

            case "Health":
                entity = new HealthPack(random.Next(15, 30), tilesetTexture, spawnPosition, (int)obj.Width,
                                        (int)obj.Height, rotation, source);
                break;

            case "Gas":
                entity = new GasPump(tilesetTexture, (int)obj.Width, (int)obj.Height, spawnPosition, rotation, source);
                break;

            default:
                entity = new Entity(tilesetTexture, (int)obj.Width, (int)obj.Height, spawnPosition, rotation,
                                    source);
                break;
            }

            EntityManager.Instance.AddEntity(entity);
        }
示例#10
0
 public void findHealthPackAndSetAsPurchased(HealthPack hp)
 {
     Debug.Log("findHealthPackAndSetAsPurchased");
     for (int i = 0; i < _allHPacks.Count; i++)
     {
         if (hp.hpackID == _allHPacks[i].hpackID)
         {
             hPacks.Add(_allHPacks[i]);
             hPacks[hPacks.IndexOf(_allHPacks[i])].quantity++;
             CommitToDB(true);
         }
     }
 }
示例#11
0
    // Use this for initialization
    void Awake()
    {
        nav                = GetComponent <NavMeshAgent>();
        anim               = GetComponent <Animator>();
        hitParticles       = GetComponentInChildren <ParticleSystem>();
        capsuleCollider    = GetComponent <CapsuleCollider>();
        healthPack         = GetComponent <HealthPack>();
        enemyAttack        = GetComponent <EnemyAttack>();
        enemyManager       = GameObject.FindGameObjectWithTag("Respawn");
        enemyManagerScript = enemyManager.GetComponent <EnemyManager>();

        currentHealth = startingHealth;
    }
示例#12
0
        public static Item ReadFrom(System.IO.BinaryReader reader)
        {
            switch (reader.ReadInt32())
            {
            case HealthPack.TAG:
                return(HealthPack.ReadFrom(reader));

            case Weapon.TAG:
                return(Weapon.ReadFrom(reader));

            case Mine.TAG:
                return(Mine.ReadFrom(reader));

            default:
                throw new System.Exception("Unexpected discriminant value");
            }
        }
示例#13
0
 void Awake()
 {
     playerHealth   = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHealth> ();
     healthCollider = GetComponent <BoxCollider2D> ();
     sliderTemp     = GameObject.FindGameObjectWithTag("PlayerHealth");
     if (sliderTemp != null)
     {
         slider = sliderTemp.GetComponent <Slider> ();
     }
     scoreTemp = GameObject.FindGameObjectWithTag("Score");
     if (scoreTemp != null)
     {
         score = scoreTemp.GetComponent <ScoreManager> ();
     }
     pack         = GetComponent <HealthPack> ();
     pack.enabled = true;
 }
        public override void OnStart()
        {
            float minDist = Mathf.Infinity;

            for (int i = 0; i < healthPacks.Length; i++)
            {
                float curDist = (healthPacks[i].transform.position - transform.position).sqrMagnitude;
                if (curDist < minDist)
                {
                    minDist   = curDist;
                    minHealth = healthPacks[i];
                }
            }

            if (minHealth != null)
            {
                target.Value = minHealth.transform;
            }
        }
示例#15
0
 void PickupHealth()
 {
     if (Input.GetKeyDown(KeyCode.E))
     {
         HealthPack healthPackScript = hit.transform.GetComponent <HealthPack>();
         float      healthAmount     = healthPackScript.healthAmount;
         if (PlayerHealth.singleton.currentHealth + healthAmount > PlayerHealth.singleton.maxHealth)
         {
             PlayerHealth.singleton.currentHealth = PlayerHealth.singleton.maxHealth;
             PlayerHealth.singleton.UpdateHealthUI();
         }
         else
         {
             PlayerHealth.singleton.AddHealth(healthAmount);
         }
         Destroy(hit.transform.gameObject);
         pickupAS.PlayOneShot(pickupHealthAC);
         pickupText.enabled = false;
     }
 }
示例#16
0
        protected virtual void PopulateWithHealthPacks(Level level, LevelGenerationSettings settings)
        {
            var totalFreeCells       = level.Field.GetCellsOfType(CellType.Empty).Count();
            var cellsWithHealthPacks = new HashSet <Location>();

            while ((double)cellsWithHealthPacks.Count / totalFreeCells < settings.HealthPacks.Density)
            {
                var location = new Location(Random.Next(1, level.Field.Width - 1), Random.Next(1, level.Field.Height - 1));

                if (level.Field[location] != CellType.Empty || level.GetEntity <Entity>(location) != null)
                {
                    continue;
                }

                cellsWithHealthPacks.Add(location);

                var healthPack = new HealthPack("Healing fruit");

                level.Spawn(location, healthPack);
            }
        }
示例#17
0
文件: Item.cs 项目: gjrfytn/MLG360
        public static Item ReadFrom(System.IO.BinaryReader reader)
        {
            if (reader == null)
            {
                throw new System.ArgumentNullException(nameof(reader));
            }

            switch (reader.ReadInt32())
            {
            case HealthPack.TAG:
                return(HealthPack.ReadFrom(reader));

            case Weapon.TAG:
                return(Weapon.ReadFrom(reader));

            case Mine.TAG:
                return(new Mine());

            default:
                throw new System.Exception("Unexpected discriminant value");
            }
        }
        //bool bought = false;
        public override void InitScreen(ScreenType screenType)
        {
            Shop.PurchaseScreenSelected += new EventHandler(Shop_PurchaseScreenSelected);
            Texture2D image = GameContent.Assets.Images.NonPlayingObjects.Planet;
            Texture2D EMP = GameContent.Assets.Images.SecondaryWeapon[SecondaryWeaponType.EMP, TextureDisplayType.ShopDisplay];
            Texture2D RayGun = GameContent.Assets.Images.SecondaryWeapon[SecondaryWeaponType.ShrinkRay, TextureDisplayType.ShopDisplay];
            Texture2D Bomb = GameContent.Assets.Images.SecondaryWeapon[SecondaryWeaponType.SpaceMine, TextureDisplayType.ShopDisplay];
            Texture2D HealthPack = GameContent.Assets.Images.Equipment[EquipmentType.HealthPack, TextureDisplayType.ShopDisplay];

            SpaceBucksAmount = new TextSprite(Sprites.SpriteBatch, Vector2.Zero, GameContent.Assets.Fonts.NormalText, string.Format("You have {0} credits", StateManager.SpaceBucks), Color.White);
            //SpaceBucksAmount.Position = new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width / 2 - SpaceBucksAmount.Width, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .1f);

            ItemAmount = new TextSprite(Sprites.SpriteBatch, Vector2.Zero, GameContent.Assets.Fonts.NormalText, string.Format("You have x{0} EMPs", StateManager.PowerUps[2].Count), Color.White);
            ItemAmount.Position = new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width / 2 - SpaceBucksAmount.Width, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * .15f);

            AdditionalSprites.Add(SpaceBucksAmount);
            AdditionalSprites.Add(ItemAmount);

            SpriteFont font = GameContent.Assets.Fonts.NormalText;

            //EMP
            EMP weapon1 = new EMP(EMP, new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * 0.75f, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * 0.3f), Sprites.SpriteBatch);
            TextSprite text1 = new TextSprite(Sprites.SpriteBatch, new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * 0.01f, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * 0.1f), font, "\n\nAn electro magnetic pulse. \nThis device disables all \nnearby enemy ships \nwithin your ship's range. \n\ncost: 1000 credits", Color.White);

            weapon1.Scale = new Vector2(0.5f, 0.5f);

            itemsShown.Add(weapon1);

            //Ray Gun
            ShrinkRay weapon2 = new ShrinkRay(RayGun, new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * 0.64f, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * 0.2f), Sprites.SpriteBatch);
            weapon2.Scale = new Vector2(0.5f, 0.5f);

            itemsShown.Add(weapon2);

            //Space Mine
            SpaceMine weapon3 = new SpaceMine(Bomb, new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * 0.69f, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * 0.3f), Sprites.SpriteBatch);
            weapon3.Scale = new Vector2(2f, 2f);

            itemsShown.Add(weapon3);

            TextSprite text2 = new TextSprite(Sprites.SpriteBatch, new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * 0.01f, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * 0.1f), font, "\n\nThis weapon causes the targeted enemy\nto shrink losing 33% of their health. \nThis does not affect bosses.\n\ncost: 2000 credits", Color.White);
            TextSprite text3 = new TextSprite(Sprites.SpriteBatch, new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * 0.01f, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * 0.1f), font, "\n\nYou place this mine anywhere in space \nand when an enemy crashes into it the mine \nexplodes \n\ncost: 500 credits.", Color.White);

            items.Add(new KeyValuePair<Sprite, TextSprite>(weapon2, text2));
            items.Add(new KeyValuePair<Sprite, TextSprite>(weapon3, text3));

            //HealthPack

            HealthPack weapon4 = new HealthPack(HealthPack, new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * 0.74f, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * 0.3f), Sprites.SpriteBatch);
            TextSprite text4 = new TextSprite(Sprites.SpriteBatch, new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * 0.1f, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * 1.5f), font, "\n\n\nThis power up regenerates\nyour health up\nby 50%\n\nCost: " + weapon4.Cost, Color.White);
            text4.Position = new Vector2(Sprites.SpriteBatch.GraphicsDevice.Viewport.Width * 0.01f, Sprites.SpriteBatch.GraphicsDevice.Viewport.Height * 0.05f);
            weapon4.Scale = new Vector2(0.5f, 0.5f);

            items.Add(new KeyValuePair<Sprite, TextSprite>(weapon4, text4));
            itemsShown.Add(weapon4);

            ChangeItem += new EventHandler(WeaponSelectScreen_ChangeItem);

            items.Add(new KeyValuePair<Sprite, TextSprite>(weapon1, text1));

            base.InitScreen(screenType);

            acceptLabel.Text = "Buy";
            //In clicked code
            this.nextButtonClicked += new EventHandler(WeaponSelectScreen_nextButtonClicked);
        }
示例#19
0
 public HealthPackView(HealthPack healthPack)
 {
     this.healthPack = healthPack;
 }
示例#20
0
 public void AddHealth(HealthPack pack)
 {
     AddHealth(pack.getHealthValue());
 }
示例#21
0
    void onPurchasing(SuppliesUIObject item, GameObject tag)
    {
        if (tag.tag == "BuyButton")
        {
            Type t = item.GetType();

            AmmoUIObject   a;
            HealthUIObject h;
            GunUIObject    g;

            if (tag.name == "Button Background")
            {
                tweenIn();

                if (t == typeof(AmmoUIObject))
                {
                    a = (AmmoUIObject)item;
                    itemInQuestion.spriteName = a.ammo.spriteName;
                    itemDescription.text      = a.ammo.ammoName;
                    s = a;
                    p = a.ammo;
                }
                if (t == typeof(GunUIObject))
                {
                    g = (GunUIObject)item;
                    itemInQuestion.spriteName = g.gunObj.model + "_Icon";
                    itemDescription.text      = g.gunObj.model;
                    s = g;
                    p = g.gunObj;
                }
                if (t == typeof(HealthUIObject))
                {
                    h = (HealthUIObject)item;
                    itemInQuestion.spriteName = "HealthIcon";
                    itemDescription.text      = h.hPack.model;
                    s = h;
                    p = h.hPack;
                }
            }
            if (tag.name == "Label OK")
            {
                if (p.GetType() == typeof(Ammo))
                {
                    Ammo a2 = (Ammo)p;

                    if (DBAccess.instance.userPrefs.Gold >= a2.price)
                    {
                        DBAccess.instance.userPrefs.findAmmoAndSetAsPurchased(a2);
                        DBAccess.instance.userPrefs.Gold -= a2.price;
                    }
                }
                if (p.GetType() == typeof(Gun))
                {
                    Gun g2 = (Gun)p;

                    if (DBAccess.instance.userPrefs.Gold >= g2.price)
                    {
                        DBAccess.instance.userPrefs.findGunAndSetAsPurchased((Gun)p);
                        DBAccess.instance.userPrefs.Gold -= g2.price;
                    }
                }
                if (p.GetType() == typeof(HealthPack))
                {
                    HealthPack h2 = (HealthPack)p;

                    if (DBAccess.instance.userPrefs.Gold >= h2.price)
                    {
                        DBAccess.instance.userPrefs.findHealthPackAndSetAsPurchased((HealthPack)p);
                        DBAccess.instance.userPrefs.Gold -= h2.price;
                    }
                }

                if (onPurchased != null)
                {
                    Debug.Log("onPurchased");
                    onPurchased(s);
                }

                tweenOut();
            }
            if (tag.name == "Label Back")
            {
                tweenOut();
            }
        }
    }
示例#22
0
 public void DestroyHealthPack(HealthPack _hp)
 {
     _hp.enabled = false;
     itemPool.Return(_hp);
 }
示例#23
0
	public void findHealthPackAndSetAsPurchased( HealthPack hp )
	{
		Debug.Log("findHealthPackAndSetAsPurchased");
		for( int i = 0; i < _allHPacks.Count; i++ )
		{
			if( hp.hpackID == _allHPacks[i].hpackID )
			{
				hPacks.Add(_allHPacks[i]);
				hPacks[hPacks.IndexOf(_allHPacks[i])].quantity++;
				CommitToDB(true);
			}
		}
	}
示例#24
0
	void populateAllHPacks()
	{
		List<System.Object[]> read = DBAccess.instance.getPurchasedHealthpacks();
			
		for( int i = 0; i < read.Count; i++ )
		{
			HealthPack h = new HealthPack( read[i] );
			allHPacks.Insert( i, h );
		}
	}