Пример #1
0
        public static void Initialize(Engine _engine)
        {
            runLoop = MacNative.CFRunLoopGetMain ();
            if (runLoop == IntPtr.Zero) {
                runLoop = MacNative.CFRunLoopGetCurrent ();
            }
            if (runLoop == IntPtr.Zero) {
                throw(new Exception ("[mac-input] unable to get a RunLoop"));
            }
            // avoid the RunLoop to be garbaged
            MacNative.CFRetain (runLoop);

            System.IntPtr hidManager = MacNative.IOHIDManagerCreate (IntPtr.Zero, IntPtr.Zero);
            if (hidManager == IntPtr.Zero) {
                throw(new Exception ("[mac-input] unable to get a HidManager()"));
            }

            DeviceAddedCallback = DeviceAdded;
            MacNative.IOHIDManagerRegisterDeviceMatchingCallback (hidManager, DeviceAddedCallback, IntPtr.Zero);

            DeviceRemovedCallback = DeviceRemoved;
            MacNative.IOHIDManagerRegisterDeviceRemovalCallback (hidManager, DeviceRemovedCallback, IntPtr.Zero);

            DeviceInputCallback = InputReceived;

            MacNative.IOHIDManagerScheduleWithRunLoop (hidManager, runLoop, defaultLoopMode);

            MacNative.IOHIDManagerSetDeviceMatching (hidManager, IntPtr.Zero);

            MacNative.IOHIDManagerOpen (hidManager, IntPtr.Zero);

            engine = _engine;
            engine.OnAfterUpdate += new Engine.AfterUpdateEventHandler (RunLoopStep);
        }
Пример #2
0
		public Game()
		{
			Engine engine = new Engine("Game", 1280, 720, fullscreen: true);
			Player player = new Player(64, 16, true);
			player.LoadAssets(engine);
			engine.SpawnObject("player", player);

			Ball ball = new Ball(12, 12, false);
			ball.LoadAssets(engine);
			engine.SpawnObject("ball", ball);

			Wall[] walls = {
				new Wall(0, 0, engine.Width, 10),
				new Wall(0, 0, 10, engine.Height),
				new Wall(engine.Width - 10, 0, 10, engine.Height), 
			};
			foreach (var wall in walls)
			{
				engine.SpawnObject("wall", wall);
			}
#if DEBUG
			engine.debugCollisions = true;
#endif
			engine.Run();
		}
Пример #3
0
        private static void AddAnimations(Engine engine)
        {
            bear.AddAnimation("idle", Utils.GetAssetName("bearDown", 0, 0), 5, engine);
            var bearAssets = Utils.GetAssetName("bearLeft", 0, 0, 2);
            bearAssets.AddRange(Utils.GetAssetName("bearLeft", 0, 1));
            bear.AddAnimation("movingLeft", bearAssets, 5, engine);
            bearAssets = Utils.GetAssetName("bearRight", 0, 0, 2);
            bearAssets.AddRange(Utils.GetAssetName("bearRight", 1, 1));
            bear.AddAnimation("movingRight", bearAssets, 5, engine);
            bearAssets = Utils.GetAssetName("bearUp", 0, 0, 2);
            bearAssets.AddRange(Utils.GetAssetName("bearUp", 0, 1));
            bear.AddAnimation("movingUp", bearAssets, 5, engine);
            bearAssets = Utils.GetAssetName("bearDown", 0, 0, 2);
            bearAssets.AddRange(Utils.GetAssetName("bearDown", 0, 1));
            bear.AddAnimation("movingDown", bearAssets, 5, engine);

            wolf.AddAnimation("idle", Utils.GetAssetName("wolf", 0, 0), 5, engine);
            wolf.AddAnimation("movingLeft", Utils.GetAssetName("wolf", 0, 1, 3), 5, engine);
            wolf.AddAnimation("movingRight", Utils.GetAssetName("wolf", 0, 2, 3), 5, engine);
            wolf.AddAnimation("movingUp", Utils.GetAssetName("wolf", 0, 3, 3), 5, engine);
            wolf.AddAnimation("movingDown", Utils.GetAssetName("wolf", 0, 0, 3), 5, engine);

            rhyno.AddAnimation("idle", Utils.GetAssetName("rhyno", 0, 0), 5, engine);
            rhyno.AddAnimation("movingLeft", Utils.GetAssetName("rhyno", 0, 1, 3), 5, engine);
            rhyno.AddAnimation("movingRight", Utils.GetAssetName("rhyno", 0, 2, 3), 5, engine);
            rhyno.AddAnimation("movingUp", Utils.GetAssetName("rhyno", 0, 3, 3), 5, engine);
            rhyno.AddAnimation("movingDown", Utils.GetAssetName("rhyno", 0, 0, 3), 5, engine);
        }
Пример #4
0
        //static GameManager()
        public static void Initialize()
        {
            engine = new Engine("A Shaman's Journey", 1280, 720, 60, false);
#if DEBUG
            engine.debugCollisions = true;
#endif

            Random = new Random();

            LoadAssets();
            LoadFonts();
        }
Пример #5
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));
				}
			}
		}
Пример #6
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));
				}
			}
		}
Пример #7
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();
        }
Пример #8
0
 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));
         }
 }
Пример #9
0
        public static void Initialize(Engine engine)
        {
            bear = new Enemy("bear", 70, 40, LevelUpModifiers)
            {
                Stats =
                {
                    MaxHp = 200f,
                    Speed = 100f,
                    Attack = 120f,
                    XpReward = 30,
                    XpForNextLevel = 60,
                    AttackSpeed = 1.3f
                },
                RangeRadius = 1000f,
                Scale = new Vector2(1.5f, 1.5f)
            };

            wolf = new Enemy("wolf", 50, 20, LevelUpModifiers)
            {
                Stats =
                {
                    MaxHp = 100f,
                    Speed = 150f,
                    Attack = 100f,
                    XpReward = 20,
                    XpForNextLevel = 60,
                    AttackSpeed = 0.66f
                },
                RangeRadius = 1000f,
                Scale = new Vector2(1.75f, 1.75f)
            };

            rhyno = new Enemy("rhyno", 60, 30, LevelUpModifiers)
            {
                Stats =
                {
                    MaxHp = 300f,
                    Speed = 100f,
                    Attack = 140f,
                    XpReward = 30,
                    XpForNextLevel = 60,
                    AttackSpeed = 1f
                },
                RangeRadius = 1000f,
                Scale = new Vector2(2.5f, 2.5f)
            };

            AddAnimations(engine);
        }
Пример #10
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));
            }
        }
Пример #11
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
                }
            }
        }
Пример #12
0
 public GameManager()
 {
     engine = new Engine("Game", 1280,768);          
 }
Пример #13
0
		public EnemyEarthEasy(Engine engine, int posX, int posY) : base(60, 40, true, "Enemy_Blob", posX, posY)
		{
			this.player = Game.players[2];

		}
Пример #14
0
 // optional engine param to add animations before spawning the SpriteObject
 public Animation AddAnimation(string name, IEnumerable<string> assets, int fps, Engine engine = null)
 {
     if (engine == null)
         engine = Engine;
     // allocate animations dictionary on demand
     if (Animations == null)
     {
         Animations = new Dictionary<string, Animation>();
     }
     var animation = new Animation();
     animation.Fps = fps;
     animation.Sprites = new List<SpriteAsset>();
     foreach (var asset in assets)
     {
         animation.Sprites.Add((SpriteAsset) engine.GetAsset(asset));
     }
     animation.CurrentFrame = 0;
     // force the first frame to be drawn
     animation.LastTick = 0;
     animation.Loop = true;
     animation.OneShot = false;
     animation.Owner = this;
     Animations[name] = animation;
     return animation;
 }
Пример #15
0
 public Enemy(Engine engine) : base (64,64,"Enemy")
 {
     LoadAsset(engine);
 }
Пример #16
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);*/

		}
Пример #17
0
 public Mouse(Engine engine)
 {
     this.engine = engine;
     this.engine.window.pbox.MouseDown += new MouseEventHandler (this.MouseDown);
     this.engine.window.pbox.MouseUp += new MouseEventHandler (this.MouseUp);
     this.engine.window.MouseWheel += new MouseEventHandler (this.MouseWheel);
 }
Пример #18
0
		//public static EnemyAirEasy enemyAir;


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

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

			Utils.LoadAssets(engine, "playerDefault", "playerDefault.png", 1, 1);
			/*player = new PlayerEarth(60, 80, true, "playerDefault");*/
            Utils.LoadAssets(engine, "startHub", "base.png", 1, 1);
            startEnvironment = new StartEnvironment(1280, 720);
            Utils.LoadAssets(engine, "hero", "images.png", 4, 4);
            player = new PlayerAir(60, 80, true, "hero");
            player.X = 600;
            player.Y = 130;
            player2 = new PlayerFire(60, 80, true, "hero");
            player2.X = 800;
            player2.Y = 330;
            player3 = new PlayerEarth(60, 80, true, "hero");
            player3.X = 600;
            player3.Y = 530;
            player4 = new PlayerWater(60, 80, true, "hero");
            player4.X = 400;
            player4.Y = 330;
            

			/*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);*/

#if DEBUG
			engine.debugCollisions = true;
#endif
            engine.SpawnObject("startHub", startEnvironment);
			engine.SpawnObject("player", player);
            engine.SpawnObject("player2", player2);
            engine.SpawnObject("player3", player3);
            engine.SpawnObject("player4", player4);
			//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);*/

		}
Пример #19
0
 public EnemyWaterMedium(Engine engine, int posX, int posY) : base(60, 80, false, "Enemy_", posX, posY)
 {
     this.player = Game.player;
     // Utils.LoadAssets(engine,);
 }
Пример #20
0
 public EnemyWaterEasy(Engine engine, int posX, int posY) : base(60, 40, true, "Enemy_", posX, posY) // change name
 {
     this.player = Game.player;
     // Utils.LoadAssets(engine,);
 }
Пример #21
0
 public TimerManager(Engine engine) : this()
 {
     this.engine = engine;
 }
Пример #22
0
		public EnemyEarthMedium(Engine engine, int posX, int posY) : base(60, 80, false, "Enemy_Mole", posX, posY)
		{
			this.player = Game.players[2];
		}
Пример #23
0
 public StartLevel(Engine engine, Player player) : base(engine.Width, engine.Height)
 {
     this.engine = engine;
     this.player = player;
 }
Пример #24
0
 public EnemyAirEasy(Engine engine,int posX,int posY) : base(60, 40, true, "Enemy_", posX,posY)
 {
     this.player = Game.player;
 }