public GameObject(Vector2 spritePosition, string textureName, DrawManager.Layer drawLayer = DrawManager.Layer.Playground, int spriteWidth = 0, int spriteHeight = 0) { Tuple <Texture, List <Animation> > ss = GfxManager.GetSpritesheet(textureName); texture = ss.Item1; animations = ss.Item2; Animation = animations[0]; //texture = GfxManager.GetTexture(textureName); if (texture == null) { texture = GfxManager.GetSpritesheet(textureName).Item1; } sprite = new Sprite(Animation.FrameWidth > 0 ? Animation.FrameWidth : texture.Width, Animation.FrameHeight > 0 ? Animation.FrameHeight : texture.Height); //texture = GfxManager.GetTexture(textureName); sprite = new Sprite(spriteWidth > 0 ? spriteWidth : texture.Width, spriteHeight > 0 ? spriteHeight : texture.Height); sprite.pivot = new Vector2(sprite.Width / 2, sprite.Height / 2); sprite.position = spritePosition; layer = drawLayer; IsActive = true; UpdateManager.AddItem(this); DrawManager.AddItem(this); }
public Tank(Vector2 spritePosition, string textureName) : base(spritePosition, textureName, DrawManager.Layer.Playground) { tracksTexture = GfxManager.GetTexture("tracks"); turretTexture = GfxManager.GetTexture("turret"); tracks = new Sprite(tracksTexture.Width, tracksTexture.Height); turret = new Sprite(turretTexture.Width, turretTexture.Height); tracks.pivot = new Vector2(tracks.Width / 2, 0); turret.pivot = new Vector2(0, turret.Height / 2); tracksOffset = new Vector2(-3, sprite.pivot.Y - 4 - tracks.Height / 2); turretOffset = new Vector2(-4, -20); minAngle = 0; maxAngle = -(float)Math.PI; turretLength = turretTexture.Width; shakeOffset = new Vector2(0, 0); float boxH = sprite.Height + (tracks.Height / 2) - 4; float yOff = (boxH - sprite.Height) / 2; float circleRadius = (float)Math.Sqrt(sprite.Width * sprite.Width + boxH * boxH) / 2; Circle bCircle = new Circle(new Vector2(0, yOff), null, circleRadius); Rect bBox = new Rect(new Vector2(0, yOff), null, sprite.Width, boxH); RigidBody = new RigidBody(sprite.position, this, bCircle, bBox); RigidBody.Type = (uint)PhysicsManager.ColliderType.Actor; RigidBody.SetCollisionMask((uint)PhysicsManager.ColliderType.Tile); RigidBody.IsGravityAffected = true; }
public WeaponsGUI(Vector2 position, int width = 0, int height = 0) : base(position, "weapons_GUI_frame", DrawManager.Layer.GUI, width, height) { sprite.pivot = Vector2.Zero; sprite.Camera = CameraManager.GetCamera("GUI"); weapons = new BulletGUIitem[(int)BulletManager.BulletType.Rocket + 1]; float yPos = this.Position.Y + this.Height / 2; for (int i = 0; i < weapons.Length; i++) { weapons[i] = new BulletGUIitem(new Vector2(this.Position.X + 7 + (itemWidth / 2) + i * (itemWidth + 4), yPos), textureNames[i], this, 2, (int)itemWidth, (int)itemWidth); if (i == 0) {//first standard weapon //weapons[i].NumBullets = 1; weapons[i].IsSelected = true; weapons[i].IsAvailable = true; weapons[i].IsInfinite = true; } } selectionTexture = GfxManager.GetTexture("weapon_GUI_selection"); selection = new Sprite(selectionTexture.Width, selectionTexture.Height); selection.pivot = new Vector2(selection.Width / 2, selection.Height / 2); SelectedWeapon = 0; selection.Camera = CameraManager.GetCamera("GUI"); }
public override void Start() { base.Start(); Vector2 screenCenter = new Vector2(Game.window.Width / 2, Game.window.Height / 2); GfxManager.Load(); UpdateManager.Init(); DrawManager.Init(); PhysicsManager.Init(); BulletManager.Init(); CameraManager.Init(screenCenter, screenCenter); CameraManager.AddCamera("bg", 0.2f); CameraManager.AddCamera("GUI", 0); playersName = new List <TextObject>(); MinY = Game.window.Height - 25; AudioManager.Load(); FontManager.Init(); FontManager.AddFont("stdFont", "Assets/textSheet.png", 15, 32, 20, 20); FontManager.AddFont("comics", "Assets/comics.png", 10, 32, 61, 65); timer = new Timer(); Vector2 positionFrame = new Vector2(50, 550); Vector2 bulletFrame = new Vector2(82, 550); GfxManager.LoadTiledMap("Assets/Map/map_lv1.tmx"); players = new List <Player>(); Player player1 = new Player("playerTank", new Vector2(Game.window.Width / 2 + 250 + space, 10)); playersName.Add(new TextObject(new Vector2(50, 20), "player 1")); players.Add(player1); Player player2 = new Player("enemyTank", new Vector2(200, 20), 1); playersName.Add(new TextObject(new Vector2(50 + 250, 20), "player 2")); players.Add(player2); CurrentPlayer = player1; currentPlayerIndex = 0; CurrentPlayer.Play(); //controllorare se inseguito da errori bg_far = new Background("bg", new Vector2(0, 0), 0); bg_far.SetCamera(CameraManager.GetCamera("bg0")); weaponsGUI = new List <WeaponsGUI>(); CameraManager.SetTarget(player1); }
public override void OnExit() { UpdateManager.RemoveAll(); DrawManager.RemoveAll(); PhysicsManager.RemoveAll(); GfxManager.RemoveAll(); BulletManager.RemoveAll(); }
public Font(string textureName, string texturePath, int numColumns, int firstCharacterASCIIvalue, int charWidth, int charHeight) { TextureName = textureName; Texture = GfxManager.AddTexture(TextureName, texturePath); firstVal = firstCharacterASCIIvalue; CharacterWidth = charWidth; CharacterHeight = charHeight; numCol = numColumns; }
public override void OnExit() { UpdateManager.RemoveAll(); DrawManager.RemoveAll(); PhysicsManager.RemoveAll(); GfxManager.RemoveAll(); BulletManager.RemoveAll(); CameraManager.ResetCamera(); AudioManager.Clear(); }
public GameObject(Vector2 spritePosition, string textureName, DrawManager.Layer drawLayer = DrawManager.Layer.Playground, int spriteWidth = 0, int spriteHeight = 0) { texture = GfxManager.GetTexture(textureName); sprite = new Sprite(spriteWidth > 0 ? spriteWidth : texture.Width, spriteHeight > 0 ? spriteHeight : texture.Height); sprite.pivot = new Vector2(sprite.Width / 2, sprite.Height / 2); sprite.position = spritePosition; layer = drawLayer; IsActive = true; UpdateManager.AddItem(this); DrawManager.AddItem(this); }
public Font(string textureName, string texturePath, int numColumns, int firstCharASCIIvalue, int charWidth, int charHeight) { TextureName = textureName; numCol = numColumns; firstVal = firstCharASCIIvalue; charW = charWidth; charH = charHeight; GfxManager.AddTexture(textureName, texturePath); Texture = GfxManager.GetTexture(textureName); }
//AudioSource source002; //AudioClip shootMusic; public Tank(Vector2 spritePosition, string textureName) : base(spritePosition, textureName, DrawManager.Layer.Playground) { //tracksTexture = GfxManager.GetTexture("tracks"); //turretTexture = GfxManager.GetTexture("turret"); Tuple <Texture, List <Animation> > track = GfxManager.GetSpritesheet("tracks"); tracksTexture = track.Item1; Tuple <Texture, List <Animation> > torretta = GfxManager.GetSpritesheet("turret"); turretTexture = torretta.Item1; tracks = new Sprite(tracksTexture.Width, tracksTexture.Height); turret = new Sprite(turretTexture.Width, turretTexture.Height); tracks.pivot = new Vector2(tracks.Width / 2, 0); turret.pivot = new Vector2(0, turret.Height / 2); tracksOffset = new Vector2(-3, sprite.pivot.Y - 4 - tracks.Height / 2); turretOffset = new Vector2(-4, -20); minAngle = 0; maxAngle = -(float)Math.PI; turretLength = turretTexture.Width; shakeOffset = new Vector2(0, 0); float boxH = sprite.Height + (tracks.Height / 2) - 4; float yOff = (boxH - sprite.Height) / 2; float circleRadius = (float)Math.Sqrt(sprite.Width * sprite.Width + boxH * boxH) / 2; Circle bCircle = new Circle(new Vector2(0, yOff), null, circleRadius); Rect bBox = new Rect(new Vector2(0, yOff), null, sprite.Width, boxH); RigidBody = new RigidBody(sprite.position, this, bCircle, bBox); RigidBody.Type = (uint)PhysicsManager.ColliderType.Actor; RigidBody.SetCollisionMask((uint)PhysicsManager.ColliderType.Tile | (uint)PhysicsManager.ColliderType.Bullet | (uint)PhysicsManager.ColliderType.PowerUp); RigidBody.IsGravityAffected = true; //source002 = new AudioSource(); //shootMusic = new AudioClip("Assets/Music/shoot.wav"); }
public override void Start() { base.Start(); Vector2 screenCenter = new Vector2(Game.window.Width / 2, Game.window.Height / 2); GfxManager.Init(); //GfxManager.AddTexture("bg", "Assets/bg_cartoon.jpg"); GfxManager.AddTexture("bg0", "Assets/cyberpunk-street3.png"); GfxManager.AddTexture("bg1", "Assets/cyberpunk-street2.png"); GfxManager.AddTexture("bg2", "Assets/cyberpunk-street1.png"); GfxManager.AddTexture("greenTank", "Assets/tanks_tankGreen_body1.png"); GfxManager.AddTexture("tracks", "Assets/tanks_tankTracks1.png"); GfxManager.AddTexture("turret", "Assets/tanks_turret2.png"); GfxManager.AddTexture("bullet", "Assets/tank_bullet1.png"); GfxManager.AddTexture("rocket", "Assets/tank_bullet3.png"); GfxManager.AddTexture("crate", "Assets/crate.png"); GfxManager.AddTexture("playerBar", "Assets/loadingBar_bar.png"); GfxManager.AddTexture("barFrame", "Assets/loadingBar_frame.png"); GfxManager.AddTexture("weapon_GUI_selection", "Assets/weapon_GUI_selection.png"); GfxManager.AddTexture("weapons_GUI_frame", "Assets/weapons_GUI_frame.png"); GfxManager.AddTexture("bullet_ico", "Assets/bullet_ico.png"); GfxManager.AddTexture("missile_ico", "Assets/missile_ico.png"); UpdateManager.Init(); DrawManager.Init(); PhysicsManager.Init(); BulletManager.Init(); //SpawnManager.Init(); CameraManager.Init(screenCenter, screenCenter); CameraManager.AddCamera("bg0", 0.2f); CameraManager.AddCamera("bg1", 0.4f); //CameraManager.AddCamera("bg2", 0.8f); CameraManager.AddCamera("GUI", 0); playersName = new List <TextObject>(); MinY = Game.window.Height - 20; FontManager.Init(); FontManager.AddFont("stdFont", "Assets/textSheet.png", 15, 32, 20, 20); Font comics = FontManager.AddFont("comics", "Assets/comics.png", 10, 32, 61, 65); timer = new TextObject(new Vector2(Game.window.Width / 2, 60), "", comics, -20); Tile crate4 = new Tile(new Vector2(200, 400)); Tile crate3 = new Tile(new Vector2(200, 300)); Tile crate2 = new Tile(new Vector2(200, 200)); Tile crate = new Tile(new Vector2(200, 100)); Tile crate1000 = new Tile(new Vector2(900, 200)); Tile crate1001 = new Tile(new Vector2(830, 200)); Tile crate1002 = new Tile(new Vector2(760, 200)); Tile crate1003 = new Tile(new Vector2(690, 200)); Tile crate1004 = new Tile(new Vector2(620, 200)); players = new List <Player>(); weaponsGUI = new List <WeaponsGUI>(); for (int i = 0; i < 2; i++) { CreatePlayer(i); } CurrentPlayer = players[0]; currentPlayerIndex = 0; CurrentPlayer.Play(); bg_far = new Background("bg0", new Vector2(-640, -60), 0); bg_far.SetCamera(CameraManager.GetCamera("bg0")); bg_medium = new Background("bg1", new Vector2(-640, 0), 0); bg_medium.SetCamera(CameraManager.GetCamera("bg1")); bg_near = new Background("bg2", new Vector2(-640, 0), 0); //bg_near.SetCamera(CameraManager.GetCamera("bg2")); CameraManager.SetTarget(CurrentPlayer); }