IEnumerator Start() { if (GameManager.Instance == null) { Instantiate(Resources.Load <GameObject>("Game")); } while (GameManager.Instance == null) { yield return(null); } if (introCam == null) { introCam = FindTaggedInScene <IntroCam>("K_INTRO_CAM"); } if (gameCam == null) { gameCam = FindTaggedInScene <GameCam>("K_GAMECAM"); } if (winCam == null) { winCam = FindTaggedInScene <KCam>("K_WIN_CAM"); } if (mapCam == null) { mapCam = FindTaggedInScene <DragCam>("K_MAP_CAM"); } GameManager.Instance.currentLevel = this; cameraController.RegisterCamera("Game", gameCam); cameraController.RegisterCamera("Map", mapCam); cameraController.RegisterCamera("Intro", introCam); cameraController.RegisterCamera("Win", winCam); cameraController.SwitchToCamera("Game"); }
// Use this for initialization void Start() { nametxt.text = popupName; GameObject gameObj = GameObject.Find("MainCamera"); if (gameObj) { this.transform.parent = gameObj.transform; if (positionOverride) { this.transform.localPosition = pos; this.transform.localEulerAngles = rot; } // adjust camera after attaching GameCam gameCamera = gameObj.GetComponent <GameCam>(); if (gameCamera) { if (lookUp) { gameCamera.LookUp(); } else if (lookPlayer) { gameCamera.LookPlayer(); } } } }
/// <summary> /// Create pointsOnScreen list in shape /// </summary> /// <param name="sh">shape object</param> /// <param name="cam">camera</param> public static void isonscreen(IShape sh, GameCam cam) { _pointsOnScreen = new List <MagicPoint>(); foreach (MagicPoint pnt in sh.Points) { if (pnt.OnScreen(cam, _pntSize)) { _pointsOnScreen.Add(pnt); } } }
/// <summary> /// Updates Each shape /// </summary> public static void Update(List <Entity> entities, GameCam cam, int lastPointClicked, int lastShapeClicked, bool movingPnt, Random _rand) { foreach (IShape sh in _shapes) { if (Shapes.IndexOf(sh) == lastShapeClicked && movingPnt) { UpdateEntity(entities, _pntSize, cam); UpdateShape(true, lastPointClicked, _rand, sh); } else { UpdateEntity(entities, _pntSize, cam); UpdateShape(false, 0, _rand, sh); } } }
/// <summary> /// Update Entity which shape is attached to /// </summary> /// <param name="entities"></param> /// <param name="pntsize"></param> /// <param name="cam"></param> public static void UpdateEntity(List <Entity> entities, Vector2 pntsize, GameCam cam) { foreach (IShape sh in _shapes) { if (sh.Target != null) { foreach (Entity ent in entities) { if (ent.Name == sh.Target.Name) { sh.Target = ent; } } if (sh.FinishedId.Contains(sh.PointAttachment)) { if (!sh.Points[sh.PointAttachment].intersects(sh.Target, pntsize, cam)) { sh.Target = null; } } } else { foreach (MagicPoint pnt in sh.Points) { if (sh.Target == null) { if (pnt.Location == pnt.MoveToLocation && sh.FinishedId.Contains(sh.Points.IndexOf(pnt))) { foreach (Entity ent in entities) { if (pnt.intersects(ent, pntsize, cam)) { sh.Target = ent; sh.PreviousLoc = ent.Location; sh.PointAttachment = sh.Points.IndexOf(pnt); } } } } } } } }
internal static void InterpolateCameraBack() { if (GameCam == null || Camera == null) { return; } CamInterpolate(Camera, GameCam, 1000, true, true, true); Camera.Active = false; Camera.Delete(); Camera = null; GameCam.Delete(); GameCam = null; SetLocalPlayerPropertiesWhileCamOn(false); }
public override void LoadContent() { _charTex = UniversalVariables.content.Load <Texture2D>("SpriteSheet Char"); _char = new Character("Char", new Vector2(0, 0), _charTex, Color.White, SpriteEffects.None, 0, new Vector2(19, 29), .5f, "Standing", 0, true, AddCharAnims(), true, new List <GameAttribute>(), new List <Perk>(), new CharacterInventory(), 5f); base.LoadContent(); cam = new GameCam(_char, new Rectangle(250, 0, UniversalVariables.graphics.PreferredBackBufferWidth, UniversalVariables.graphics.PreferredBackBufferHeight)); _char.CurrentAnimation = "Standing"; mp = new Map(UniversalVariables.spriteBatch); Tiles = UniversalVariables.content.Load <Texture2D>("SpriteSheet Tiles"); GenerateMap(); Mous = new CompMouse("mouse", UniversalVariables.content.Load <Texture2D>("SpriteSheet Misc"), CreateMouseAnimation()); Mous.CurrentAnimation = "neutral"; MagMan = new MagicManager(UniversalVariables.content.Load <Texture2D>("SpriteSheet Magic"), new Rectangle(0, 14, 6, 6), new Rectangle(0, 0, 12, 12), new Rectangle(0, 12, 2, 2)); GenerateBaseEntityList(); Interface.Add(0, Mous); MagMan.AddPrimalShapes(); }
public static bool intersectCon(CollidingAdvancedSprite CAS, Vector2 pointa, Vector2 pointb, Vector2 _magicPntSizeOnScreen, GameCam cam) { float x = (((CAS.BoundingBox.Y + cam.Location.Y) - pointa.Y) / ((pointb.Y - pointa.Y) / (pointb.X - pointa.X))) + pointa.X; if (x + (_magicPntSizeOnScreen.Y / 8) >= CAS.BoundingBox.X + cam.Location.X && x - (_magicPntSizeOnScreen.Y / 8) <= CAS.BoundingBox.X + cam.Location.X + CAS.BoundingBox.Width) { return(true); } x = (((CAS.BoundingBox.Y + cam.Location.Y + CAS.BoundingBox.Height) - pointa.Y) / ((pointb.Y - pointa.Y) / (pointb.X - pointa.X))) + pointa.X; if (x + (_magicPntSizeOnScreen.Y / 8) >= CAS.BoundingBox.X + cam.Location.X && x - (_magicPntSizeOnScreen.Y / 8) <= CAS.BoundingBox.X + cam.Location.X + CAS.BoundingBox.Width) { return(true); } x = ((pointb.Y - pointa.Y) / (pointb.X - pointa.X)) * (CAS.BoundingBox.X + cam.Location.X - pointa.X) + pointa.Y; if (x + (_magicPntSizeOnScreen.Y / 8) >= CAS.BoundingBox.Y + cam.Location.Y && x - (_magicPntSizeOnScreen.Y / 8) <= CAS.BoundingBox.Y + cam.Location.Y + CAS.BoundingBox.Height) { return(true); } return(false); }
/// <summary> /// Update based on input /// </summary> /// <param name="input">input manager</param> /// <param name="mous">mous</param> /// <param name="cam">Camera</param> /// <param name="entities">all entities</param> public void InputUpdate(CompMouse mous, GameCam cam, List <Entity> entities) { if (InputManager.CheckButtonDown("Cast Spell", false, false) && _lastShapeClicked >= 0) { Identify(ShapeRegistry.Shapes[_lastShapeClicked]); ShapeRegistry.Cast(_lastShapeClicked); ShapeRegistry.Shapes.RemoveAt(_lastShapeClicked); _lastShapeClicked = _lastPointClicked = -1; } InputManager.CheckButtonDown("Open Magic Mode", false, false, true); _magicMode = InputManager.getToggle("Open Magic Mode"); if (_movingPnt) { if (!InputManager.CheckButtonDown("Add/Select Spell Point", false, false)) { Identify(ShapeRegistry.Shapes[_lastShapeClicked]); //if (!_heldControl) // _lastPointClicked = -1; _movingPnt = false; _moveWait = 0; } } InputManager.CheckButtonDown("Speed Creation Mode", false, true); if (InputManager.CheckButtonDown("Add/Select Spell Point", false, false)) { if (!_movingPnt) { if (_lastPointClicked >= 0) { if (ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked].intersects(mous, ShapeRegistry.PointSize, cam)) { if (_moveWait < 5) { _moveWait++; } else { _moveWait = 0; _movingPnt = true; _lastMouseLoc = mous.Location; } } } } else { ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked]._location -= _lastMouseLoc - mous.Location; ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked].MoveToLocation = ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked]._location; if (ShapeRegistry.Shapes[_lastShapeClicked].Target == null) { foreach (Entity ent in entities) { if (ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked].intersects(ent, ShapeRegistry.PointSize, cam)) { ShapeRegistry.Shapes[_lastShapeClicked].Target = ent; ShapeRegistry.Shapes[_lastShapeClicked].PointAttachment = _lastPointClicked; } } } else { if (!ShapeRegistry.Shapes[_lastShapeClicked].Points[_lastPointClicked].intersects(ShapeRegistry.Shapes[_lastShapeClicked].Target, ShapeRegistry.PointSize, cam) && ShapeRegistry.Shapes[_lastShapeClicked].PointAttachment == _lastPointClicked) { ShapeRegistry.Shapes[_lastShapeClicked].Target = null; (ShapeRegistry.Shapes[_lastShapeClicked]).FirstTarget = false; } } _lastMouseLoc = mous.Location; } } if (InputManager.CheckButtonDown("Add/Select Spell Point", true, false) && _magicMode) { _clicked = false; _curCombineShpe = -1; _curCombinePnt = -1; foreach (IShape shpe in ShapeRegistry.Shapes) { _temSh = shpe; _tempindex = ShapeRegistry.Shapes.IndexOf(shpe); ShapeRegistry.isonscreen(shpe, cam); if (ShapeRegistry.PointsOnScreen.Count > 0) { foreach (MagicPoint pnt in ShapeRegistry.PointsOnScreen) { if (pnt.intersects(mous, ShapeRegistry.PointSize, cam)) { if (_lastPointClicked >= 0) { if (_lastShapeClicked == ShapeRegistry.Shapes.IndexOf(shpe)) { bool exists = false; if (shpe.Points[_lastPointClicked].Connections.Contains(pnt.ID)) { exists = true; } if (!exists && _lastPointClicked != shpe.Points.IndexOf(pnt)) { ShapeRegistry.AddInternalConnection(_lastPointClicked, pnt.ID, shpe); Identify(shpe); if (InputManager.isBeingHeld("Speed Creation Mode")) { _heldControl = true; _lastPointClicked = pnt.ID; } else { _lastPointClicked = -1; } } else { _lastPointClicked = pnt.ID; } } else { _curCombineShpe = ShapeRegistry.Shapes.IndexOf(shpe); _curCombinePnt = pnt.ID; } } else { _lastPointClicked = pnt.ID; _lastShapeClicked = ShapeRegistry.Shapes.IndexOf(shpe); } _clicked = true; } } } } if (_tempindex >= 0) { ShapeRegistry.Shapes[_tempindex] = _temSh; } if (!_clicked) { if (_heldControl && _lastPointClicked != -1) { ShapeRegistry.Addshape(mous.Location, _rand, entities, false); ShapeRegistry.CombineShape(new Shape(true), _lastShapeClicked, ShapeRegistry.Shapes.Count - 1, _lastPointClicked, 0, entities, false); } else { ShapeRegistry.Addshape(mous.Location, _rand, entities, true); } _lastShapeClicked = ShapeRegistry.Shapes.Count - 1; _lastPointClicked = 0; Identify(ShapeRegistry.Shapes[_lastShapeClicked]); if (InputManager.isBeingHeld("Speed Creation Mode")) { _heldControl = true; _lastPointClicked = ShapeRegistry.Shapes[_lastShapeClicked].Points.Count - 1; } else { _curCombinePnt = _curCombineShpe = _lastPointClicked = -1; } } if (_lastShapeClicked != -1 && _lastPointClicked != -1 && _curCombinePnt != -1 && _curCombineShpe != -1) { int i = _curCombinePnt + ShapeRegistry.Shapes[_lastShapeClicked].Points.Count; ShapeRegistry.CombineShape(new Shape(true), ShapeRegistry.Shapes[_lastShapeClicked], ShapeRegistry.Shapes[_curCombineShpe], _lastPointClicked, _curCombinePnt, entities, true); _lastShapeClicked = ShapeRegistry.Shapes.Count - 1; if (InputManager.isBeingHeld("Speed Creation Mode")) { _heldControl = true; _lastPointClicked = i; _curCombinePnt = _curCombineShpe = -1; } else { _curCombinePnt = _curCombineShpe = _lastPointClicked = -1; } Identify(ShapeRegistry.Shapes[_lastShapeClicked]); } } if (InputManager.CheckButtonDown("Remove Spell Points/Connections", true, false) && _magicMode) { _clicked = false; foreach (IShape shpe in ShapeRegistry.Shapes) { ShapeRegistry.isonscreen(shpe, cam); if (ShapeRegistry.PointsOnScreen.Count > 0) { foreach (MagicPoint pnt in ShapeRegistry.PointsOnScreen) { if (pnt.intersects(mous, ShapeRegistry.PointSize, cam)) { _removePnt = pnt.ID; _removeShape = ShapeRegistry.Shapes.IndexOf(shpe); Identify(shpe); _clicked = true; } } } } if (_removePnt != -1) { ShapeRegistry.Shapes[_removeShape] = ShapeRegistry.RemovePoint(_removePnt, ShapeRegistry.Shapes[_removeShape]); } if (ShapeRegistry.Shapes[_removeShape].Points.Count == 0) { if (_lastShapeClicked == _removeShape) { _lastShapeClicked = -1; } _lastPointClicked = -1; ShapeRegistry.Shapes.RemoveAt(_removeShape); } if (_removePnt != -1) { if (_lastPointClicked == _removePnt && _lastShapeClicked == _removeShape) { _lastPointClicked = -1; } _movingPnt = false; _moveWait = 0; _removePnt = -1; } if (!_clicked) { int temin = -1; foreach (Shape shpe in ShapeRegistry.Shapes) { int rem = -1; int pntID = -1; bool done = false; foreach (MagicPoint pnt in shpe.Points) { foreach (int i in pnt.Connections) { if (!done) { if (IShapeMethods.intersectCon(mous, shpe.Points[pnt.ID]._location, shpe.Points[i]._location, ShapeRegistry.PointSize, cam)) { _temSh = shpe; temin = ShapeRegistry.Shapes.IndexOf(_temSh); rem = i; _clicked = true; _lastPointClicked = -1; _movingPnt = false; _moveWait = 0; pntID = pnt.ID; if (InputManager.CheckButtonDown("Spell Separation", false, false)) { _lastShapeClicked = -1; } done = true; } } } } if (InputManager.CheckButtonDown("Spell Separation", false, false) && temin > -1) { _pointsInShape.RemoveAll(RemoveAllin); _pointsInShape.Add(rem); foreach (int i in shpe.Points[rem]._connections) { _pointsInShape.Add(rem); } if (_pointsInShape.Count > 1) { CheckforSeparation(_pointsInShape, _temSh, 1, rem); } if (_pointsInShape.Count < _temSh.Points.Count) { _pntDic = new Dictionary <int, int>(); _sh = new Shape(true); foreach (int i in _pointsInShape) { _sh.Points.Add(_temSh.Points[i]); } for (int i = 0; i < _pointsInShape.Count; i++) { _pntDic.Add(_pointsInShape[i], _sh.Points.IndexOf(_temSh.Points[_pointsInShape[i]])); } for (int i = 0; i < _pointsInShape.Count; i++) { _temSh.Points.RemoveAt(_pointsInShape[i]); for (int n = i; n < _pointsInShape.Count; n++) { if (_pointsInShape[n] > _pointsInShape[i]) { _pointsInShape[n]--; } } } } } if (rem != -1) { ShapeRegistry.removeConnection(rem, pntID, _temSh); } } if (temin > -1) { ShapeRegistry.Shapes[temin] = _temSh; Identify(_temSh); if (InputManager.CheckButtonDown("Spell Separation", false, false) && _sh != null) { Identify(_sh); ShapeRegistry.Shapes.Add(_sh); } } } if (!_clicked) { _lastPointClicked = _lastShapeClicked = -1; } else { if (_removeShape != -1) { ShapeRegistry.Shapes.RemoveAt(_removeShape); } _removeShape = -1; } } if (InputManager.CheckButtonDown("Clear Spells", true, false) && _magicMode) { _clicked = false; foreach (Shape shpe in ShapeRegistry.Shapes) { ShapeRegistry.isonscreen(shpe, cam); if (ShapeRegistry.PointsOnScreen.Count > 0) { foreach (MagicPoint pnt in ShapeRegistry.PointsOnScreen) { if (pnt.intersects(mous, ShapeRegistry.PointSize, cam)) { _removeShape = ShapeRegistry.Shapes.IndexOf(shpe); _clicked = true; } } } } if (!_clicked) { foreach (Shape shpe in ShapeRegistry.Shapes) { _temSh = shpe; _tempindex = ShapeRegistry.Shapes.IndexOf(shpe); ShapeRegistry.isonscreen(shpe, cam); if (ShapeRegistry.PointsOnScreen.Count > 0) { foreach (MagicPoint pnt in shpe.Points) { foreach (int i in pnt.Connections) { if (IShapeMethods.intersectCon(mous, shpe.Points[pnt.ID]._location, shpe.Points[i]._location, ShapeRegistry.PointSize, cam)) { _conClicked = true; _clicked = true; } } } if (_conClicked) { _conClicked = false; } } } if (_tempindex >= 0) { ShapeRegistry.Shapes[_tempindex] = _temSh; } } if (!_clicked) { ShapeRegistry.Shapes = new List <IShape>(); _lastShapeClicked = _lastPointClicked = -1; } else if (_removeShape != -1) { ShapeRegistry.Shapes.RemoveAt(_removeShape); if (_removeShape == _lastShapeClicked) { _lastShapeClicked = _lastPointClicked = -1; } _removeShape = -1; _movingPnt = false; _moveWait = 0; } } _tempindex = -1; }
/// <summary> /// Updates Each _shape /// </summary> public void Update(List <Entity> entities, GameCam cam) { ShapeRegistry.Update(entities, cam, _lastPointClicked, _lastShapeClicked, _movingPnt, _rand); }