예제 #1
0
        public override void Start()
        {
            base.Start();
            SpriteAsset sprite = new SpriteAsset("playerDefault.png");
			this.AddAnimation("blob_idle", new List<string> { "blob_0_0" }, 10);

			this.CurrentAnimation = "blob_idle";
		}
예제 #2
0
파일: Bullet.cs 프로젝트: luxkun/ggj2016
 public Bullet(Character owner, SpriteAsset bulletAsset, Vector2 direction, Func<Collision, bool> hitMask) :
     base(bulletAsset.Width, bulletAsset.Height, true)
 {
     this.owner = owner;
     CurrentSprite = bulletAsset;
     this.direction = direction;
     this.hitMask = hitMask;
 }
예제 #3
0
		public static void LoadAssets(Engine engine, string assetName, string pathName, int rows, int cols)
		{
			SpriteAsset spriteAsset = new SpriteAsset(pathName);
			int width = spriteAsset.Width / cols;
			int height = spriteAsset.Height / rows;
			for (int x = 0; x < cols; x++)
			{
				for (int y = 0; y < rows; y++)
				{
					engine.LoadAsset(assetName + "_" + x + "_" + y, new SpriteAsset(pathName, x * width, y * height, width, height));
				}
			}
		}
예제 #4
0
		public void LoadAssets(Engine engine)
		{
			SpriteAsset image = new SpriteAsset("../../assets/bar.png");
			int tileWidth = image.Width / rows;
			int tileHeight = image.Height / cols;
			for (int x = 0; x < cols; x++)
			{
				for (int y = 0; y < rows; y++)
				{
					engine.LoadAsset($"bar_{x}_{y}", new SpriteAsset("../../assets/bar.png", x * tileWidth, y * tileHeight, tileWidth, tileHeight));
				}
			}
		}
예제 #5
0
 public void SpawnBackgroundPart(int x, int y, SpriteAsset backgroundAsset, int order = 0, int width = -1,
     int height = -1, int paddingx = 0, int paddingy = 0)
 {
     width = width == -1 ? backgroundAsset.sprite.Width : width;
     height = height == -1 ? backgroundAsset.sprite.Height : height;
     var background = new SpriteObject();
     background.x = blockW + width*x + paddingx;
     background.y = blockH + height*y + paddingy;
     background.currentSprite = backgroundAsset;
     background.order = order;
     engine.SpawnObject(string.Format("{2}_bgblock_{0}.{1}_{3}", x, y, name, backgroundAsset.fileName),
         background);
 }
예제 #6
0
        static void Main(string[] args)
        {
            Engine engine = new Engine("test", 1024, 768, 60, false, false);
            engine.debugCollisions = true;

            // set default directory for assets, will be appened to all assets's path
            Asset.BasePath = "..\\..\\Assets";

            // load repeating texture
            var repeatingGoblins = new SpriteAsset("goblins.png", 100, 100, 150, 150, repeatx: true, repeaty: true);
            // auto hitbox and spriteasset with repeatx or/and repeaty are NOT compatible
            var obj = new SpriteObject(repeatingGoblins.Width + 20, repeatingGoblins.Height + 100);
            obj.CurrentSprite = repeatingGoblins;

            obj.OnUpdate += sender =>
            {
                var s = (SpriteObject)sender;
                s.SpriteOffset += new Vector2(10f, 0f) * s.DeltaTime;
            };

            // text
            TextConfig.Default = new TextConfig(new Asset("font.png"), charToSprite);
            var semiTransparentText = new TextObject(0.66f, Color.Red, 0.8f);
            semiTransparentText.Text = "SEMI TRANSPARENT";
            semiTransparentText.Y = obj.Height;
            var bigText = new TextObject(1.1f, Color.CadetBlue);
            bigText.Text = "BIG TEXT";
            var semiTransparentTextMeasure = semiTransparentText.Measure();
            bigText.Y = semiTransparentTextMeasure.Y + semiTransparentText.Y;
            var bigTextMeasure = bigText.Measure();

            // hitboxes
            var spriteSheet = new SpriteAsset("rob.png");
            var tileWidth = spriteSheet.Width/22;
            var tileHeight = spriteSheet.Height/1;
            var spriteAsset = new SpriteAsset("rob.png", 0, 0, tileWidth, tileHeight);
            var spriteH = new SpriteObject(spriteAsset.Width, spriteAsset.Height, true);
            spriteH.Y = bigText.Y + bigTextMeasure.Y;
            spriteH.CurrentSprite = spriteAsset;
            spriteH.Scale = new Vector2(5f, 5f);

            // spawn gameobjects
            engine.SpawnObject("obj", obj);

            engine.SpawnObject("semiTransparentText", semiTransparentText);
            engine.SpawnObject("bigText", bigText);

            engine.SpawnObject("spriteH", spriteH);

            engine.Run();
        }
예제 #7
0
파일: Utils.cs 프로젝트: luxkun/ggj2016
 public static void LoadAnimation(Engine engine, string name, string fileName, int xLen, int yLen)
 {
     var spriteAsset = new SpriteAsset(fileName);
     var blockSizeOnWall = new Vector2(spriteAsset.Width/(float) xLen, spriteAsset.Height/(float) yLen);
     for (var posX = 0; posX < xLen; posX++)
         for (var posY = 0; posY < yLen; posY++)
         {
             var animName = $"{name}_{posY}_{posX}";
             Debug.WriteLine("Loaded animations: " + animName);
             engine.LoadAsset(animName,
                 new SpriteAsset(fileName, (int) (posX*blockSizeOnWall.X), (int) (posY*blockSizeOnWall.Y),
                     (int) blockSizeOnWall.X, (int) blockSizeOnWall.Y));
         }
 }
예제 #8
0
        public static void LoadAssets(Engine engine) // Perche Static?
        {
            var startLevel = new SpriteAsset("../../Assets/StartLevel.png");
            engine.LoadAsset("startLevel", new SpriteAsset("../../Assets/StartLevel.png", 0, 0, startLevel.Width, startLevel.Height));

            //Load Asset Player
            int tileWidth;
            int tileHeight;
            SpriteAsset playerAsset = new SpriteAsset("../../Assets/player.png");
            tileWidth = playerAsset.Width / 22;
            tileHeight = playerAsset.Height;
            for (int i = 0; i < 22; i++)
            {
                engine.LoadAsset($"Player_{i}", new SpriteAsset("../../Assets/player.png", i * tileWidth, 0, tileWidth, tileHeight));
                engine.LoadAsset($"PlayerRight_{i}", new SpriteAsset("../../Assets/playerRight.png", i * tileWidth, 0, tileWidth, tileHeight));
            }
        }
예제 #9
0
        private void LoadAsset(Engine engine)
        {

            int tileWidth;
            int tileHeight;

            SpriteAsset jdComplete = new SpriteAsset("../../Assets/jd.png"); // carica la sprite completa
            tileWidth = jdComplete.Width / 3; // lunghezza della sprite = lunghezza sprite completa/ le colonne
            tileHeight = jdComplete.Height / 5; // altezza della sprite = altezza sprite completa / le righe

            //ciclo for per caricare ad ogni chiave la propria sprite
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    engine.LoadAsset($"jd_{j}_{i}", new SpriteAsset("../../Assets/jd.png", i * tileWidth, j * tileHeight, tileWidth, tileHeight)); //load asset = metodo che torna dictonary
                }
            }
        }
예제 #10
0
        public TruncatedObject(string name, SpriteAsset bottomSpriteAsset, SpriteAsset topSpriteAsset)
            : base(bottomSpriteAsset.Width, bottomSpriteAsset.Height)
        {
            topSprite = new SpriteObject(topSpriteAsset.Width, topSpriteAsset.Height);
            topSprite.CurrentSprite = topSpriteAsset;
            topSprite.Order = 9;
            bottomSprite = new SpriteObject(bottomSpriteAsset.Width, bottomSpriteAsset.Height);
            bottomSprite.CurrentSprite = bottomSpriteAsset;
            bottomSprite.Order = 1;
            AddHitBox(
                "bottomtree", (int) (bottomSprite.Width*0.33f),
                (int) topSprite.Height, (int) (bottomSprite.Width*0.33f),
                (int) bottomSprite.Height);
            this.bottomSpriteAsset = bottomSpriteAsset;
            this.topSpriteAsset = topSpriteAsset;
            Name = name;

            OnDestroy += DestroyEvent;
        }
예제 #11
0
		//public static EnemyAirEasy enemyAir;

		public static void Init()
		{
			engine = new Engine("Game", 1280, 720, 60, false);

			Asset.BasePath = "../../assets/";

			players = new Player[4];

			Utils.LoadAssets(engine, "playerDefault", "playerDefault.png", 1, 1);
			Utils.LoadAssets(engine, "startHub", "base.png", 1, 1);
			currentEnvironment = new StartEnvironment(1280, 720);
			Utils.LoadAssets(engine, "hero", "images.png", 4, 4);
			players[0] = new PlayerAir(60, 80, true, "hero", EnviromentType.StartEnviroment);
			players[0].X = 600;
			players[0].Y = 130;
			players[1] = new PlayerFire(60, 80, false, "hero", EnviromentType.StartEnviroment);
			players[1].X = 800;
			players[1].Y = 330;
			players[2] = new PlayerEarth(60, 80, true, "hero", EnviromentType.StartEnviroment);
			players[2].X = 600;
			players[2].Y = 530;
			players[3] = new PlayerWater(60, 80, true, "hero", EnviromentType.StartEnviroment);
			players[3].X = 400;
			players[3].Y = 330;

			SpriteAsset sprite = new SpriteAsset("Montagna.png", 0, 0);
			Utils.LoadAssets(engine, "PlayerFire", "PlayerFire.png", 6, 4);
			Utils.LoadAssets(engine, "LeftFire", "LeftFire.png", 2, 4);

			Utils.LoadAssets(engine, "backgroundEarth", "backgroundEarth.png", 1, 1);
			Utils.LoadAssets(engine, "backgroundFire", "backgroundFire.png", 1, 1);
			Utils.LoadAssets(engine, "backgroundAir", "Montagna.png", 1, 1);
			Utils.LoadAssets(engine, "backgroundWater", "Fondale.png", 1, 1);

			/*Utils.LoadAssets(engine, "background", "background.png", 1, 1);
			enviromentEarth = new EnviromentEarth(1280, 720);

			EnemyEarth[] enemyEarths = new EnemyEarth[Utils.Randomize(3, 7)];
			for (int i = 0; i < enemyEarths.Length; i++)
			{
				int rX, rY;
				do
				{
					rX = Utils.Randomize(1, 15);
					rY = Utils.Randomize(1, 32);
				} while (enviromentEarth.tiles[Utils.GetPos(rX, rY, 14)].tileType != TileType.None);
				if (Utils.Randomize(0, 100) < 25)
					enemyEarths[i] = new EnemyEarthMedium(engine, rX * 80, rY * 80);
				else
					enemyEarths[i] = new EnemyEarthMedium(engine, rX * 80, rY * 80);
			}

			Utils.LoadAssets(engine, "background", "background.png", 1, 1);
			enviromentEarth = new EnviromentEarth(1280, 720);*/

			Utils.LoadAssets(engine, "undestrWall", "undestrWall.png", 1, 1);
			Utils.LoadAssets(engine, "destrWall", "destrWall.png", 1, 1);
			Utils.LoadAssets(engine, "cloud", "cloud.png", 1, 1);
			Utils.LoadAssets(engine, "blob", "Blob.png", 2, 3);
			Utils.LoadAssets(engine, "bullet", "EnemyHeart.png", 1, 2);

#if DEBUG
            engine.debugCollisions = true;
#endif
			engine.SpawnObject("startHub", currentEnvironment);
			engine.SpawnObject("player0", players[0]);
			engine.SpawnObject("player1", players[1]);
			engine.SpawnObject("player2", players[2]);
			engine.SpawnObject("player3", players[3]);
			//engine.SpawnObject("enemy", enemy);
			/*for (int i = 0; i < enviromentEarth.tiles.Length; i++)
			{
				engine.SpawnObject("wall" + i, enviromentEarth.tiles[i]);
			}
			for (int i = 0; i < enemyEarths.Length; i++)
			{
				engine.SpawnObject("enemy" + Utils.Randomize(0, Int32.MaxValue), enemyEarths[i]);
			}
			//engine.SpawnObject("enemyAir", enemyAir);*/

		}
예제 #12
0
        private static void LoadAssets()
        {
            Asset.BasePath = "../../assets";
            //Utils.LoadAnimation(engine, "player", "player_sheet.png", 10, 10);
            // enemies
            engine.LoadAsset("genericBullet", new SpriteAsset("singleBullet.png"));
            Utils.LoadAnimation(engine, "playerIdle", "player/idle.png", 4, 2);
            Utils.LoadAnimation(engine, "playerMovingUp", "player/movingUp.png", 4, 2);
            Utils.LoadAnimation(engine, "playerMovingDown", "player/movingDown.png", 4, 2);
            Utils.LoadAnimation(engine, "playerMovingLeft", "player/movingLeft.png", 4, 2);
            Utils.LoadAnimation(engine, "playerMovingRight", "player/movingRight.png", 4, 2);
            //Utils.LoadAnimation(engine, "playerShottingUp", "player/shottingUp.png", 4, 2);
            //Utils.LoadAnimation(engine, "playerShootingDown", "player/shottingDown.png", 4, 2);

            engine.LoadAsset("background0", new SpriteAsset("background0.png"));
            engine.LoadAsset("swamp0", new SpriteAsset("swamp0.png"));
            var tree = new SpriteAsset("tree0.png");
            engine.LoadAsset("tree0_top", new SpriteAsset("tree0.png", 0, 0, tree.Width, (int) (tree.Height*0.75f)));
            engine.LoadAsset("tree0_bottom", new SpriteAsset("tree0.png", 0, (int)(tree.Height * 0.75f), tree.Width, (int)(tree.Height * 0.25f)));

            // enemies
            Utils.LoadAnimation(engine, "earthMinion", "earthMinion.png", 4, 4);
            Utils.LoadAnimation(engine, "demoniacMinion", "demoniacMinion.png", 4, 4);
            Utils.LoadAnimation(engine, "lifeMinion", "lifeMinion.png", 4, 4);

            Utils.LoadAnimation(engine, "ritual0", "ritual0.png", 5, 1);
            Utils.LoadAnimation(engine, "ritual1", "ritual1.png", 5, 1);
            Utils.LoadAnimation(engine, "ritual2", "ritual2.png", 5, 1);
            engine.LoadAsset("qteContainer", new SpriteAsset("QteContainer.png"));

            // animals (enemies)
            Utils.LoadAnimation(engine, "wolf", "wolf.png", 3, 4);
            Utils.LoadAnimation(engine, "rhyno", "rhyno.png", 3, 4);
            Utils.LoadAnimation(engine, "bearLeft", "bearLeft.png", 2, 2);
            Utils.LoadAnimation(engine, "bearDown", "bearDown.png", 2, 2);
            Utils.LoadAnimation(engine, "bearUp", "bearUp.png", 2, 2);
            Utils.LoadAnimation(engine, "bearRight", "bearRight.png", 2, 2);

            // SOUND
            engine.LoadAsset("sound_soundtrack", new AudioAsset("sound/soundtrack.ogg"));
            engine.LoadAsset("sound_ritual_intro", new AudioAsset("sound/ritual_intro.ogg"));
            engine.LoadAsset("sound_ritual_soundtrack", new AudioAsset("sound/ritual_soundtrack.ogg"));
            engine.LoadAsset("sound_damage", new AudioAsset("sound/damage.ogg"));
            engine.LoadAsset("sound_heal", new AudioAsset("sound/heal.ogg"));
            engine.LoadAsset("sound_bullet", new AudioAsset("sound/bullet.ogg"));

            // pregame
            engine.LoadAsset("logo", new SpriteAsset("preGame.png"));

            // pause
            engine.LoadAsset("pauseImage", new SpriteAsset("pauseImage.png"));

        }
예제 #13
0
 public virtual void UpdateAutomaticHitBox(SpriteAsset sprite)
 {
     if (AutomaticHitBox)
     {
         if (HitBoxes == null || !HitBoxes.ContainsKey(AutomaticHitBoxName)) { 
             AddHitBox(AutomaticHitBoxName, 0, 0, 1, 1);
             HitBoxes[AutomaticHitBoxName].UseScaling = false;
         }
         var hitBoxInfo = sprite.CalculateRealHitBox();
         var deltaW = (float)Sprite.Width/sprite.Width;
         var deltaH = (float)Sprite.Height/sprite.Height;
         HitBoxes[AutomaticHitBoxName].X = hitBoxInfo.Item1.X * deltaW * Scale.X;
         HitBoxes[AutomaticHitBoxName].Y = hitBoxInfo.Item1.Y * deltaW * Scale.Y;
         HitBoxes[AutomaticHitBoxName].Width = (int)(hitBoxInfo.Item2.X * deltaW * Scale.X);
         HitBoxes[AutomaticHitBoxName].Height = (int)(hitBoxInfo.Item2.Y * deltaH * Scale.Y);
     }
 }
예제 #14
0
 private void DrawSprite(SpriteAsset sprite)
 {
     Sprite.position.X = DrawX;
     Sprite.position.Y = DrawY;
     sprite.Texture.SetOpacity(Opacity);
     Sprite.DrawTexture(
         sprite.Texture,
         (int) (sprite.X + SpriteOffset.X), (int) (sprite.Y + SpriteOffset.Y), 
         sprite.Width, sprite.Height);
     UpdateAutomaticHitBox(sprite);
 }
예제 #15
0
 public override void Start()
 {
     base.Start();
     SpriteAsset sprite = new SpriteAsset("playerDefault.png");
 }
예제 #16
0
        public override void Start()
        {
            base.Start();
            // TODO: random (with seed) inside game
            var rnd = ((Game) engine.objects["game"]).random.GetRandom(name);
            blockAsset = (SpriteAsset) engine.GetAsset("block");
            blockW = blockAsset.sprite.Width; //(blockAsset).sprite.Width;
            blockH = blockAsset.sprite.Height; //(blockAsset).sprite.Height;
            doorAsset = (SpriteAsset) engine.GetAsset("door");

            // not block*2 because blocks could go outside the screen area
            var gameWidth = engine.width - blockW;
            var gameHeight = engine.width - blockH;
            SpriteAsset backgroundAsset;
            if (backgroundChosen == 0)
            {
                backgroundAsset = (SpriteAsset) engine.GetAsset("background_0");
                for (var x = 0; x <= gameWidth/backgroundAsset.sprite.Width; x++)
                    for (var y = 0; y <= gameHeight/backgroundAsset.sprite.Height; y++)
                    {
                        SpawnBackgroundPart(x, y, backgroundAsset);
                    }
            }
            else if (backgroundChosen == 1 || backgroundChosen == 2)
            {
                var backgroundParts =
                    ((Game) engine.objects["game"]).spritesAnimations["background_" + backgroundChosen];
                backgroundAsset = (SpriteAsset) engine.GetAsset(backgroundParts[0]);
                for (var x = 0; x < gameWidth/backgroundAsset.sprite.Width; x++)
                    for (var y = 0; y < gameHeight/backgroundAsset.sprite.Height; y++)
                    {
                        backgroundAsset =
                            (SpriteAsset) engine.GetAsset(backgroundParts[rnd.Next(0, backgroundParts.Count)]);
                        SpawnBackgroundPart(x, y, backgroundAsset);
                    }
            }

            // boss
            if (spawnSmallObj)
            {
                var bloodAsset = (SpriteAsset) engine.GetAsset("blood");
                var skullAsset = (SpriteAsset) engine.GetAsset("skull");
                var sadSkullAsset = (SpriteAsset) engine.GetAsset("sadskull");
                for (var x = 0; x < gameWidth/blockW; x++)
                    for (var y = 0; y < gameHeight/blockH; y++)
                    {
                        var chosen = rnd.Next(0, 6*(room.roomType == 1 ? 1 : 20));
                        var paddingx = rnd.Next(0, 16);
                        var paddingy = rnd.Next(0, 16);
                        if (chosen == 0)
                            SpawnBackgroundPart(x, y, bloodAsset, 1, blockW, blockH, paddingx, paddingy);
                        else if (chosen == 1)
                            SpawnBackgroundPart(x, y, sadSkullAsset, 1, blockW, blockH, paddingx, paddingy);
                        else if (chosen == 2)
                            SpawnBackgroundPart(x, y, skullAsset, 1, blockW, blockH, paddingx, paddingy);
                    }
            }

            // other rooms blocks
            SpawnBlock(engine.width/2/blockW, 0, new Door(), name + "_top_door");
            SpawnBlock(engine.width/2/blockW, (engine.height - 1)/blockH, new Door(), name + "_bottom_door");
            SpawnBlock(0, engine.height/2/blockH, new Door(), name + "_left_door");
            SpawnBlock((engine.width - 1)/blockW, engine.height/2/blockH, new Door(), name + "_right_door");

            SpawnBorders();
        }
예제 #17
0
 public SpriteAsset Clone()
 {
     var go = new SpriteAsset(BaseFileName, X, Y, Width, Height);
     return go;
 }