public override void SetUp() { Params.Load("default.properties"); List<Entity> children = XNAGame.Instance.Children; Fighter leader = new Fighter(); leader.Position = new Vector3(10, 120, 20); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wander); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); children.Add(leader); Fighter camFighter = new Fighter(); camFighter.Leader = leader; camFighter.Position = new Vector3(10, 120, 0); camFighter.offset = new Vector3(0, 5, 10); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.offset_pursuit); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); XNAGame.Instance.CamFighter = camFighter; children.Add(camFighter); Ground ground = new Ground(); children.Add(ground); XNAGame.Instance.Ground = ground; XNAGame.Instance.Camera.Position = new Vector3(10, 120, 50); foreach (Entity child in children) { child.LoadContent(); } }
public void Fillmap() { for(int i = 0; i < 24; i++) { for(int k = 0; k < 24; k++) { map[i, k] = new Ground(new OpenTK.Vector3(k * 50, i * 50, 0), new OpenTK.Vector2(50, 50), System.Drawing.Color.White); } } //testsmap = new WorldSection(map); int c = 0; int widh; int hight; for(int i = 0; i < 4; i++) { widh = i * 6; // NEED TO BE CHANGED, WILL NOT WORK ON ARRAYS BIGGER THAN 2; hight = 0; for(int u = 0; u < 4; u++) { Smap[c] = new WorldSection(); Smap[c].FillSection(widh, hight, map, "templates/testfile1.txt"); c++; hight = hight + 6; } } //Smap[0, 0] = new WorldSection(0, 6, 0, 6, map); //Smap[0, 1] = new WorldSection(6, 12, 0, 6, map); //Smap[1, 0] = new WorldSection(0, 6, 6, 12, map); //Smap[1, 1] = new WorldSection(6, 12, 6, 12, map); }
public override void SetUp() { Params.Load("default.properties"); List<Entity> children = XNAGame.Instance.Children; Ground ground = new Ground(); children.Add(ground); XNAGame.Instance.Ground = ground; Fighter fighter = new Fighter(); fighter.ModelName = "cobramk1"; fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.arrive); fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); fighter.Position = new Vector3(2, 20, -50); fighter.TargetPos = fighter.Position * 2; XNAGame.Instance.Leader = fighter; children.Add(fighter); Fighter fighter1 = new Fighter(); fighter1.ModelName = "viper"; fighter1.Target = fighter; fighter1.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.pursuit); fighter1.Position = new Vector3(-20, 20, -20); children.Add(fighter1); foreach (Entity child in children) { child.LoadContent(); } }
void Start () { Control = GameObject.FindGameObjectWithTag("GroundControl").GetComponent<Ground>(); collider = this.gameObject.transform.GetChild(0).gameObject.collider; // rigidbody = this.gameObject.transform.GetChild(0).gameObject.rigidbody; light = this.gameObject.transform.GetChild(0).transform.FindChild("GroundLight").light; //IsActiveGround = false; }
public void Restart() { ground = new Ground(); player = new Player(); started = true; }
void Awake() { controller = GetComponent<CharacterController>(); changeScale = GetComponent<ChangeScale>(); ground = GetComponent<Ground>(); jump = GetComponent<Jump>(); antigravityEffect = GetComponent<AntigravityEffect>(); }
public static void Hitdetecion(Moveable player1, Ground[,] objlist) { foreach(Ground obj in objlist) { if(player1.Bounds.IntersectsWith(obj.Bounds) && obj.Isfilled) { //middle region if(((player1.CenterY) > (obj.CenterY - (obj.Height / 2))) && ((player1.CenterY) < (obj.CenterY + (obj.Height / 2)))) { //left region if(player1.CenterX < obj.CenterX) { player1.Position = player1.Position + new OpenTK.Vector3(-1, 0, 0); } //rigth region if(player1.CenterX > obj.CenterX) { player1.Position = player1.Position + new OpenTK.Vector3(1, 0, 0); } } //upper region else if(player1.CenterY > obj.CenterY) { ////left region //if(player1.Center.X < obj.X + obj.X){ // player1.Position = player1.Position + new OpenTK.Vector3(-1, 1, 0); //} //middle region if(((player1.CenterX) > (obj.CenterX - (obj.Height / 2))) && ((player1.CenterX) < (obj.CenterX + (obj.Width / 2)))) { player1.Position = player1.Position + new OpenTK.Vector3(0, 1, 0); } ////rigth region //if(player1.Center.X < (obj.X + obj.Width)){ // player1.Position = player1.Position + new OpenTK.Vector3(1, -1, 0); //} } //lower region else if(player1.CenterY < obj.CenterY) { ////left region //if(player1.Center.X < obj.X + obj.X){ // player1.Position = player1.Position + new OpenTK.Vector3(-1, -1, 0); //} //middle region if(((player1.CenterX) > (obj.CenterX - (obj.Height / 2))) && ((player1.CenterX) < (obj.CenterX + (obj.Width / 2)))) { player1.Position = player1.Position + new OpenTK.Vector3(0, -1, 0); } ////rigth region //if(player1.Center.X < (obj.X + obj.Width)){ // player1.Position = player1.Position + new OpenTK.Vector3(1, -1, 0); //} } } } }
public void AddMap(int node, Vector2 start, int num, Ground groundKind, Vector3 rotation) { if(maps == null) maps = new List<GroundMap>(); GroundMap map = new GroundMap(); map.start = start; map.num = num; map.groundKind = groundKind; map.rotation = rotation; maps.Insert(node, map); }
void Start() { Ground = GameObject.FindGameObjectWithTag("Ground").GetComponent<Ground>(); LoadCollectable (); mid = Ground.GetMid(); xBound = Ground.GetXBound(); yBound = Ground.GetYBound(); zBound = Ground.GetZBound(); }
public GroundProperties(Ground gr) { InitializeComponent(); _ground = gr; lbCoor.Text = gr.coordn._x + ", " + gr.coordn._y; lbGroundType.Text = gr.groundtype; lbNumberOfPlants.Text = gr.ListPlant.Count.ToString(); dgPlantList.DataSource = gr.ListPlant; dgPlantList.Columns["dna"].Visible = false; cbGeneration.DataSource = gr.ListPlant.Select(S=>S.Generation).Distinct().ToList(); }
public TerrainWalker( LarvContent lcontent, IVEffect effect, Ground ground) : base(effect) { _sphere = lcontent.Sphere; _texture = lcontent.Load<Texture2D>(@"models/frogskin"); _ground = ground; _position1 = new Vector3(11, 0, -3); }
public Frog( LarvContent lcontent, IVEffect effect, Serpents serpents) : base(effect) { _model = lcontent.Load<Model>(@"Models/frog"); _modelRotation = Matrix.RotationY(MathUtil.Pi)*Matrix.Scaling(0.1f); _texture = lcontent.Load<Texture2D>(@"models/frogskin"); _serpents = serpents; _ground = lcontent.Ground; Restart(); }
Object findResource(Ground groundKind) { string name = PREFABBRICKDIR; if(groundKind == Ground.brick) { name += "/brick"; }else if(groundKind == Ground.brickWithWood) { name += "/brickWithWood"; }else if(groundKind == Ground.halfBrickWithWood){ name += "/halfBrickWithWood"; }else if(groundKind == Ground.towHalfBrickWithWood){ name += "/2halfBrickWithWood"; } return Resources.Load(name); }
//Test for the Class Ground public void testGround() { try { MapMatrix m = new MapMatrix(); Ground g = new Ground(m, "W",new Point(0,0)); } catch (Exception e) { MessageBox.Show(e.ToString()); } finally { MessageBox.Show("testGround Completed"); } }
public LarvContent(GraphicsDevice graphicsDevice, ContentManager content, IEnumerable<string> sceneDescription) : base(graphicsDevice, content) { SpriteBatch = new SpriteBatch(graphicsDevice); Font = Load<SpriteFont>("fonts/BlackCastle"); SignTextEffect = LoadEffect("effects/signtexteffect"); TextureEffect = LoadEffect("effects/simpletextureeffect"); BumpEffect = LoadEffect("effects/simplebumpeffect"); Sphere = new SpherePrimitive<VertexPositionNormalTangentTexture>(GraphicsDevice, (p, n, t, tx) => new VertexPositionNormalTangentTexture(p, n, t, tx), 2, 10); Sky = new SkySphere(this, Load<TextureCube>(@"Textures\clouds")); Ground = new Ground(this); ShadowMap = new ShadowMap(this, 800, 800, 1, 50); ShadowMap.UpdateProjection(50, 30); HallOfFame = HofStorage.Load(); PlayingFieldInfos = PlayingFieldsDecoder.Create(sceneDescription); }
void Start() { rb = this.GetComponent<Rigidbody>(); Ground = GameObject.FindGameObjectWithTag("Ground").GetComponent<Ground>(); xBound = Ground.GetXBound(); yBound = Ground.GetYBound(); mid = Ground.GetMid(); pos = 0; this.transform.position = new Vector3(xBound * mid, yBound + 0.5f, 3.0f); // delete "yBound + 4" and put "yBound" dTimeToIncreaseSpead = Time.time; rb.velocity = new Vector3(0.0f, 0.0f, 5.0f); directionChosen = false; }
public override void SetUp() { Params.Load("default.properties"); List<Entity> children = XNAGame.Instance.Children; Ground ground = new Ground(); children.Add(ground); XNAGame.Instance.Ground = ground; AIFighter aiFighter = new AIFighter(); aiFighter.Position = new Vector3(-20, 50, 50); aiFighter.ModelName = "cobramk1"; aiFighter.maxSpeed = 16.0f; aiFighter.SwicthState(new IdleState(aiFighter)); aiFighter.Path.DrawPath = true; children.Add(aiFighter); Fighter fighter = new Fighter(); fighter.ModelName = "viper"; fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.arrive); fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); fighter.Position = new Vector3(10, 50, 0); fighter.TargetPos = aiFighter.Position + new Vector3(-50, 0, -80); children.Add(fighter); Fighter camFighter = new Fighter(); camFighter.Leader = fighter; camFighter.offset = new Vector3(0, 5, 10); camFighter.Position = fighter.Position + camFighter.offset; camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.offset_pursuit); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); XNAGame.Instance.CamFighter = camFighter; children.Add(camFighter); XNAGame.Instance.Leader = fighter; Camera camera = XNAGame.Instance.Camera; camera.Position = new Vector3(0.0f, 60.0f, 100.0f); foreach (Entity child in children) { child.LoadContent(); } }
public IFlyweight provide(string key) { if (meshes.ContainsKey(key)) { return(meshes[key]); } else { IFlyweight flyweight = null; switch (key) { case "tree": flyweight = new Tree(); break; case "ground": flyweight = new Ground(); break; } meshes.Add(key, flyweight); return(flyweight); } }
// ====================================================================================== private Vector3 CheckCollision(Vector3 _startPos, Vector3 _endPos) { RaycastHit hitInfo; Vector3 direction = _endPos - _startPos; Vector3 finalEndPos = _endPos; if (direction.y < 0) { if (Physics.Raycast(_startPos, direction + m_collisionEpsilon * direction.normalized, out hitInfo, direction.magnitude + m_collisionEpsilon, ~(1 << this.gameObject.layer))) { Ground gnd = hitInfo.collider.gameObject.GetComponent <Ground>(); if (gnd != null) { finalEndPos.y = gnd.SurfaceY() + m_collisionEpsilon; } } } finalEndPos.x = Mathf.Clamp(finalEndPos.x, SceneMgr.MinX + m_width / 2, SceneMgr.MaxX - m_width / 2); finalEndPos.y = Mathf.Clamp(finalEndPos.y, SceneMgr.MinY, SceneMgr.MaxY - m_height); return(finalEndPos); }
public Maze(int width, int height) { Width = width; Height = height; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if ((y % 2 != 0 && x % 2 != 0) && (y < height - 1 && x < width - 1)) { var cell = new Ground(x, y); Cells.Add(cell); } else { var cell = new Wall(x, y); Cells.Add(cell); } } } }
//Makes a regular room public static Block[,] Room(Random rng, Orientation[] orientations, Orientation enterance) { Block[,] blocks = Walls(); //Gets the pattern used for the floor int[,] pattern = RoomPattern(rng); for (int x = 0; x < 19; ++x) { for (int y = 0; y < 11; ++y) { if (pattern[x, y] == 1) { blocks[1 + x, 1 + y] = new Carpet(new Vector2(1 + x, 1 + y)); } else { blocks[1 + x, 1 + y] = new Ground(new Vector2(1 + x, 1 + y)); } } } return(blocks); }
public void CheckPassThrough(Collider2D collider) { Ground ground = collider.GetComponent <Ground>(); //CheckLastPassedThrough(); if (!m_IsPassing) { if (ground != null && ground.IsPassThrough) { foreach (Collider2D gc2d in ground.Colliders) { foreach (Collider2D myC2d in m_MyColliders) { Physics2D.IgnoreCollision(gc2d, myC2d, true); } } m_LastPassThrough = ground.Colliders; m_IsPassing = true; StartCoroutine(TimedCheckColliders(m_Collidertimer)); } } }
// Update is called once per frame void Update() { if (inBoat) { transform.position = boat.GetComponent <Boat>().navigationPlaceTransform.position; Collider2D[] listCollider = Physics2D.OverlapCircleAll(transform.position, 5); Ground groundNearTemp = null; foreach (Collider2D collider in listCollider) { if (collider.CompareTag("Ground")) { groundNearTemp = collider.GetComponent <Ground>(); } } if (groundNearTemp == null) { groundNear = null; UIManager.instance.SetActiveButtonGoOutOfBoat(false); } else if (!inShop) { groundNear = groundNearTemp; UIManager.instance.SetActiveButtonGoOutOfBoat(true); } } else if (!inBoat) { if (!CheckIfColliderAround(5, "Boat")) { UIManager.instance.SetActiveButtonGoInBoat(false); } else if (!inShop) { UIManager.instance.SetActiveButtonGoInBoat(true); } } }
// Save a tileMap public static void SaveTileMap(TileMap map, string path) { StreamWriter writer = new StreamWriter(path); writer.WriteLine(map.Size.X); writer.WriteLine(map.Size.Y); for (int i = 0; i < map.Size.X; i++) { for (int j = 0; j < map.Size.Y; j++) { Vector2 Position = map.Position + new Vector2(MainGame.TILE_SIZE.X * j, MainGame.TILE_SIZE.Y * i); Ground ground = null; for (int k = 0; k < map.GameObjects.Count; k++) { if (map.GameObjects[k] is Ground temp) { if (temp.Position == Position) { ground = temp; } } } if (ground != null) { writer.Write((int)ground.GroundType); } else { writer.Write("*"); } } writer.Write("\n"); } writer.Close(); }
private void GenerateMap() { int gridWidth = MapManager.GetWidth * MapMultiplicator; int gridHeight = MapManager.GetHeight * MapMultiplicator; GroundObjectsMap = new MyGrid <GameObject>(gridWidth, gridHeight); GroundsMap = new MyGrid <Ground>(gridWidth, gridHeight); Ground.SetGroundSize(gridWidth, gridHeight); for (int h = 0; h < gridHeight; h++) { for (int w = 0; w < gridWidth; w++) { GroundObjectsMap.Grid[w, h] = Instantiate(GroundObj); GroundObjectsMap.Grid[w, h].transform.position = new Vector3((float)w / MapMultiplicator + GroundObj.transform.position.x, 0, (float)h / MapMultiplicator + GroundObj.transform.position.z); GroundObjectsMap.Grid[w, h].GetComponent <Ground>().Init(w, h); GroundObjectsMap.Grid[w, h].transform.SetParent(MapThings.transform); GroundsMap.Grid[w, h] = GroundObjectsMap.Grid[w, h].GetComponent <Ground>(); SetGroundBlocked(w, h, false); } } }
public void GenerateGrounds(Ground ground) { _currentGround = ground; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i == 0 && j == 0) { continue; } var currentPosition = ground.GetPosition() + new Vector2Int(j, i); if (!_map.ContainsKey(currentPosition)) { var generatePosition = new Vector3(transform.localScale.x * currentPosition.x, 0, transform.localScale.z * currentPosition.y) * 100; var nextGround = Instantiate(Grounds.Instance.GetRandomGround(), generatePosition, Quaternion.identity); nextGround.SetPosition(currentPosition); _map.Add(currentPosition, nextGround); } } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (GUILayout.Button("Refresh Cell References")) { Ground ground = (Ground)target; ground.cells.cellReferences = new List <CellData.CellReference>(); foreach (Transform groundCell in ground.transform) { Cell cell = groundCell.GetComponent <Cell>(); if (cell != null) { Vector3 cellPosition = groundCell.position; Vector2Int cellIndices = new Vector2Int(Mathf.RoundToInt(cellPosition.x), Mathf.RoundToInt(cellPosition.z)); ground.cells.cellReferences.Add(new CellData.CellReference(cellIndices, cell)); } } } }
public override void SetUp() { Params.Load("default.properties"); List <Entity> children = XNAGame.Instance.Children; Fighter leader = new Fighter(); leader.ModelName = "boa"; leader.Position = new Vector3(-10, 20, 20); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.arrive); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); leader.TargetPos = new Vector3(10, 30, 20); children.Add(leader); XNAGame.Instance.Leader = leader; Fighter camFighter = new Fighter(); camFighter.Leader = leader; camFighter.offset = new Vector3(0, 5, 10); camFighter.Position = leader.Position + camFighter.offset; camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.offset_pursuit); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); XNAGame.Instance.CamFighter = camFighter; children.Add(camFighter); Ground ground = new Ground(); children.Add(ground); XNAGame.Instance.Ground = ground; foreach (Entity child in children) { child.LoadContent(); } }
void WaterfallHit() { float rayCastXPos; Debug.Log("transform.eulerAngles.z: " + transform.eulerAngles.z); if (transform.eulerAngles.z > 0 && transform.eulerAngles.z < 180) { waterParticlesL.Play(); rayCastXPos = myBounds.min.x - raycastOffset; } else { waterParticlesR.Play(); rayCastXPos = myBounds.max.x + raycastOffset; } RaycastHit2D hit = Physics2D.Raycast(new Vector3(rayCastXPos, myBounds.min.y + raycastOffset, transform.position.z), -Vector2.up, Mathf.Infinity, waterHitLayer); if (hit.collider != null) { if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ground")) { Debug.Log("The ground was hit"); Ground groundScript = hit.transform.gameObject.GetComponent <Ground> (); groundOrigin = groundScript; // test SetFillingOrder(); } else if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Channel")) { Debug.Log("A channel was hit"); WaterSource waterSourceScript = hit.transform.gameObject.GetComponent <WaterSource>(); // add some delay related to the length of the channel waterSourceScript.openChannel = true; } } }
public void CreateGround(GroundTypes newGroundType) { bool hay = false; if (gameObject.name.EndsWith("_b")) { hay = true; } groundType = newGroundType; if (ground != null) { DestroyImmediate(ground.gameObject); } if (groundType != GroundTypes.Void) { Ground prefab = GridManager.Instance.GetGroundPrefab(groundType); if (prefab != null) { // prefab.transform.GetChild(0).GetComponent<Renderer>().material = alternative_tile_material; ground = Instantiate(prefab, transform.position, prefab.transform.rotation, transform); // ground.transform.GetChild(0).GetComponent<Renderer>().material = alternative_tile_material; if (hay) { ground.GetComponent <Renderer>().material = alternative_tile_material; } canPlantOnIt = prefab.canPlantOnIt; } } }
public void GenerateMap() { ground = new Ground[terrainWidth, terrainHeight]; groundGameObjects = new GameObject[terrainWidth, terrainHeight]; for (int y = 0; y < terrainHeight; y++) { for (int x = 0; x < terrainWidth; x++) { if (Random.value < spawnPercentage && artifactcount < MapManager.Instance.artifacts.Length) { ArtifactPiece artifactPiece = new ArtifactPiece("Artifact" + artifactcount, 2); MapManager.Instance.artifacts[artifactcount].artifactPiece = artifactPiece; ground[x, y] = MapManager.Instance.artifacts[artifactcount]; ground[x, y].position = new Vector2Int(x, -y); artifactcount++; } else { ground[x, y] = new Ground(1, 1, MapManager.Instance.groundPrefabs[0], true, new Vector2Int(x, -y), GroundType.ground); } } } }
/// Returns TRUE if we can do a far-fall hop or just-ate-happy-hop. private bool MayDoAFunHop() { if (!DoesFunHop) { return(false); } // No, I don't do that sort of thing. //if (!IsGrounded()) { return false; } // Not on ground? Can't hop. Collidable collOn = myWhiskers.TEMP_GetFloorCollidable(); if (collOn != null) { Ground g = collOn as Ground; if (g != null && g.PreventHappyHop) { return(false); } // This Ground specifically says we can't. DispGround dg = collOn as DispGround; if (dg != null && dg.DieFromPlayerLeave) { return(false); } // DispGround that'll disappear if we leave it? Don't hop! } return(true); // Looks good! }
public override void Initialize() { bg = new Ground(this.game, this.screenWidth, this.screenHeight, this.sceneNum); for (int i = 0; i < NUM_OF_PLAYERS; i++) { players[i] = new Player(game, i); players[i].Position = new Vector2(); players[i].Position.X = this.screenWidth / (NUM_OF_PLAYERS + 1) * (i + 1); int[] terrainContour = bg.getTerrainContour(); players[i].Position.Y = bg.terrainContour[(int)players[i].Position.X]; } //for (int i = 0; i < NUM_OF_PLAYERS; i++) //{ //} bg.setupGround(players); //bg.FlattenTerrainBelowPlayers(players); _rocket = new Rocket(game, this.screenWidth, this.screenHeight); _explosion = new Explosion(game); flock = new Flock(game, this.screenWidth, this.screenHeight, this.sceneNum); //generateFlock(); //bird = new Bird(this.game, this.screenWidth, this.screenHeight); //goal1Rect = new Rectangle(125, Consts.GoalYline, 200, 1); //goal2Rect = new Rectangle(125, screenHeight - Consts.GoalYline - 5, 200, 1); //State = 0; //P1Score = 0; //P2Score = 0; //endScene = false; //ballSprite.InitBallParam(); }
public GroundView(Ground ground) : base(ground) { PickType = PickType.PickGroundTiles; m_NoDraw = (Entity.LandDataID < 3 || (Entity.LandDataID >= 0x1AF && Entity.LandDataID <= 0x1B5)); if (Entity.LandData.TextureID <= 0) { DrawFlip = false; m_DrawAs3DStretched = false; IResourceProvider provider = ServiceRegistry.GetService <IResourceProvider>(); DrawTexture = provider.GetLandTexture(Entity.LandDataID); DrawArea = new Rectangle(0, Entity.Z * 4, IsometricRenderer.TILE_SIZE_INTEGER, IsometricRenderer.TILE_SIZE_INTEGER); } else { DrawFlip = false; m_DrawAs3DStretched = true; IResourceProvider provider = ServiceRegistry.GetService <IResourceProvider>(); DrawTexture = provider.GetTexmapTexture(Entity.LandData.TextureID); } }
public static Block[,] Entrance(Random rng, Orientation[] orientations) { //Creates the object and all the walls with doors Block[,] blocks = Walls(); //Making all the floor blocks randomising if they are regular floor or carpet for (int x = 1; x < 20; ++x) { for (int y = 1; y < 12; ++y) { if (rng.Next(0, 2) != 1) { blocks[x, y] = new Ground(new Vector2(x, y)); } else { blocks[x, y] = new Carpet(new Vector2(x, y)); } } } blocks[10, 6] = new Staircase(new Vector2(10, 6), true); return(blocks); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); effect = new BasicEffect(GraphicsDevice); // setup sound engineSound = Content.Load <SoundEffect>("Running"); Song song = Content.Load <Song>("1944 UST - Opening"); MediaPlayer.Play(song); soundeffectInstance = engineSound.CreateInstance(); soundeffectInstance.IsLooped = true; soundeffectInstance.Volume = 0.3f; soundeffectInstance.Play(); MediaPlayer.Volume = 0.5f; MediaPlayer.IsRepeating = true; // setup effect this.camera = new Camera(GraphicsDevice, new Vector3(-10, 25, 10)); effect.VertexColorEnabled = true; effect.Projection = camera.ViewProjectionMatrix; // Set cullmode to none //rs.CullMode = CullMode.None; GraphicsDevice.RasterizerState = rs; // add objects ground = new Ground(GraphicsDevice); houses = new Houses(GraphicsDevice); airplane = new Airplane(GraphicsDevice, new Vector3(25, 5, 25), .1f); }
public void LoadStatics(TileMatrixData tileData, Map map) { // get data from the tile Matrix byte[] groundData = tileData.GetLandChunk(ChunkX, ChunkY); int staticLength; byte[] staticsData = tileData.GetStaticChunk(ChunkX, ChunkY, out staticLength); // load the ground data into the tiles. int groundDataIndex = 0; for (int i = 0; i < 64; i++) { int tileID = groundData[groundDataIndex++] + (groundData[groundDataIndex++] << 8); int tileZ = (sbyte)groundData[groundDataIndex++]; Ground ground = new Ground(tileID, map); ground.Position.Set((int)ChunkX * 8 + i % 8, (int)ChunkY * 8 + (i / 8), tileZ); } // load the statics data into the tiles int countStatics = staticLength / 7; int staticDataIndex = 0; for (int i = 0; i < countStatics; i++) { int iTileID = staticsData[staticDataIndex++] + (staticsData[staticDataIndex++] << 8); int iX = staticsData[staticDataIndex++]; int iY = staticsData[staticDataIndex++]; int iTileZ = (sbyte)staticsData[staticDataIndex++]; int hue = staticsData[staticDataIndex++] + (staticsData[staticDataIndex++] * 256); StaticItem item = new StaticItem(iTileID, hue, i, map); item.Position.Set((int)ChunkX * 8 + iX, (int)ChunkY * 8 + iY, iTileZ); } }
// Load TileMap public static TileMap LoadTileMap(GameScreen screen, string path, Vector2 position) { TileMap map = new TileMap(screen); map.Position = position; StreamReader reader = new StreamReader(path); int xPos = (int)position.X; int yPos = (int)position.Y; map.Size.X = int.Parse(reader.ReadLine()); map.Size.Y = int.Parse(reader.ReadLine()); string line; while ((line = reader.ReadLine()) != null) { xPos = (int)position.X; for (int i = 0; i < line.Length; i++) { if (line[i] != '*') { Ground.GROUND_TYPE groundType = (Ground.GROUND_TYPE) int.Parse(line[i].ToString()); Ground ground = Ground.MakeGround(screen, map, groundType); map.GameObjects.Add(ground); ground.Position.X = xPos; ground.Position.Y = yPos; } xPos += (int)MainGame.TILE_SIZE.X; } yPos += (int)MainGame.TILE_SIZE.Y; } reader.Close(); return(map); }
// check grid to retrieve the neighbour tiles private List <Ground> GetNeighbourTiles(Ground currentTile) { List <Ground> neighbours = new List <Ground>(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { //self if (i == 0 && j == 0) { continue; } int xIndex = i + (int)currentTile.index.x; int yIndex = j + (int)currentTile.index.y; if (xIndex >= 0 && xIndex < tilemap.GetLength(0) && yIndex >= 0 && yIndex < tilemap.GetLength(1)) { neighbours.Add(tilemap[xIndex, yIndex].GetComponent <Ground>()); } } } return(neighbours); }
IEnumerator GetFinish(RaycastHit hit) { yield return(0); if (hit.transform.GetComponent <Ground>()) { Vector2 pos = GetPosition(); Ground finish = hit.transform.GetComponent <Ground>(); List <mapPoint> road = AStar.find(GameManage.Instance.groundList[(int)pos.x][(int)pos.y], finish); if (road != null) { road.Reverse(); foreach (mapPoint point in road) { GameManage.Instance.groundList[point.x][point.y].ChangeMaterial(); } StartCoroutine(GoToFinish(road)); } else { Debug.LogError("不可走"); } } }
//void OnGUI() //{ // GUI.BeginGroup(new Rect((1718*Scale.x ), (24*Scale.y ), (180 * Scale.x), (160 * Scale.y))); // if (GUI.Button(new Rect((0*Scale.x), (0*Scale.y), (180*Scale.x), (40*Scale.y)), MainGuiContent[0]) || Input.GetKeyDown(KeyCode.Escape)) // { // Application.LoadLevel("MainMenu"); // } // if (GUI.Button(new Rect((0 * Scale.x), (60 * Scale.y), (80 * Scale.x), (40 * Scale.y)), MainGuiContent[1])) // { // scrolling.SwitchScrollingStatus(); // } // if (GUI.Button(new Rect((100 * Scale.x), (60 * Scale.y), (80 * Scale.x), (40 * Scale.y)), MainGuiContent[2])) // { // MiniMap.SwitchActive(); // } // if (GUI.Button(new Rect((0 * Scale.x), (120 * Scale.y), (47 * Scale.x), (40 * Scale.y)), MainGuiContent[3])) // { // Ground.Switch(0); // } // if (GUI.Button(new Rect((68 * Scale.x), (120 * Scale.y), (47 * Scale.x), (40 * Scale.y)), MainGuiContent[4])) // { // Ground.Switch(1); // } // if (GUI.Button(new Rect((134 * Scale.x), (120 * Scale.y), (47 * Scale.x), (40 * Scale.y)), MainGuiContent[5])) // { // Ground.Switch(2); // } // GUI.enabled = true; // GUI.EndGroup(); //} private void CheckKeyboardInput() { if (Input.GetKeyDown(KeyCode.Alpha1)) { Ground.Switch(0); } if (Input.GetKeyDown(KeyCode.Alpha2)) { Ground.Switch(1); } if (Input.GetKeyDown(KeyCode.Alpha3)) { Ground.Switch(2); } if (Input.GetKeyDown(KeyCode.M)) { MiniMap.SwitchActive(); } if (Input.GetKeyDown(KeyCode.T)) { if (InGameText.ShowDebugText) { InGameText.ShowDebugText = false; guiText.text = ""; } else { InGameText.ShowDebugText = true; } } /* Space Key Switch Camera */ if (Input.GetKeyDown(KeyCode.Space)) { Camera.main.GetComponent <Cam>().SwitchCam(); } }
public void EnterTile(Ground ground) { CurrentGrounds.Add(ground); }
public void ExitTile(Ground ground) { CurrentGrounds.Remove(ground); }
// Use this for initialization void Start() { inst = this; }
void ProbeGroundRecursive(Vector3 origin, float distanceTraveled) { PushIgnoredColliders(); // Add a small amount of Tolerance before casting downwards Vector3 o = origin + (up * Tolerance); RaycastHit hit; if (Physics.SphereCast(o, radius, down, out hit, Mathf.Infinity, Walkable)) { var wall = hit.collider.gameObject.GetComponent<SuperCollisionType>(); if (wall == null) { // TODO: just use some derived default values? Debug.LogError("[SuperCharacterComponent]: Object on SuperCharacterController walkable layer does not have SuperCollisionType component attached"); } Vector3 newOrigin = o + down * (hit.distance + TinyTolerance + Tolerance); hit.distance = Mathf.Clamp(hit.distance - Tolerance, 0, Mathf.Infinity); hit.distance += distanceTraveled; // If the StandAngle is not satisfactory, adjust our origin to be slightly below where we last hit // and SphereCast again if (Vector3.Angle(hit.normal, up) > wall.StandAngle) { PopIgnoredColliders(); ProbeGroundRecursive(newOrigin, hit.distance + TinyTolerance); return; } // Because when SphereCast hits an edge on a surface it returns the interpolation of the two normals of the // two triangles joined to that edge, we need to retrieve the actual normal of both of the triangles Vector3 toCenter = Math3d.ProjectVectorOnPlane(up, (transform.position - hit.point).normalized * TinyTolerance); if (toCenter == Vector3.zero) { currentGround = new Ground(hit, hit, hit, wall, hit.transform); PopIgnoredColliders(); return; } Vector3 awayFromCenter = Quaternion.AngleAxis(-80.0f, Vector3.Cross(toCenter, up)) * -toCenter; Vector3 nearPoint = hit.point + toCenter + (up * TinyTolerance); Vector3 farPoint = hit.point + (awayFromCenter * 3); RaycastHit nearHit; RaycastHit farHit; // Retrieve the normal of the point nearest to the center of the base of the controller Physics.Raycast(nearPoint, down, out nearHit, Mathf.Infinity, Walkable); // Retrieve the normal of the point furthest to the center of the base of the controller Physics.Raycast(farPoint, down, out farHit, Mathf.Infinity, Walkable); currentGround = new Ground(hit, nearHit, farHit, wall, hit.transform); } else { // Debug.LogError("[SuperCharacterComponent]: No ground was found below the player; player has escaped level"); } PopIgnoredColliders(); }
public override void SetUp() { Params.Load("default.properties"); List<Entity> children = XNAGame.Instance.Children; Fighter leader = new Fighter(); leader.ModelName = "viper"; leader.Position = new Vector3(10, 20, 20); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.arrive); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.separation); leader.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); leader.TargetPos = new Vector3(0, 100, -450); children.Add(leader); XNAGame.Instance.Leader = leader; // Add some Obstacles Obstacle o = new Obstacle(4); o.Position = new Vector3(0, 10, -10); children.Add(o); o = new Obstacle(17); o.Position = new Vector3(-10, 16, -80); children.Add(o); o = new Obstacle(10); o.Position = new Vector3(10, 15, -120); children.Add(o); o = new Obstacle(12); o.Position = new Vector3(5, -10, -150); children.Add(o); o = new Obstacle(20); o.Position = new Vector3(-2, 5, -200); children.Add(o); o = new Obstacle(10); o.Position = new Vector3(-25, -20, -250); children.Add(o); o = new Obstacle(10); o.Position = new Vector3(20, -20, -250); children.Add(o); o = new Obstacle(35); o.Position = new Vector3(-10, -30, -300); children.Add(o); // Now make a fleet int fleetSize = 5; float xOff = 6; float zOff = 6; for (int i = 2; i < fleetSize; i++) { for (int j = 0; j < i; j++) { float z = (i - 1) * +zOff; Fighter fleet = new Fighter(); fleet.Leader = leader; fleet.ModelName = "cobramk1"; fleet.offset = new Vector3((xOff * (-i / 2.0f)) + (j * xOff), 0, z); fleet.Position = leader.Position + fleet.offset; fleet.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.offset_pursuit); fleet.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.separation); fleet.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); fleet.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); children.Add(fleet); } } Fighter camFighter = new Fighter(); camFighter.Leader = leader; camFighter.Position = new Vector3(0, 15, fleetSize * zOff); camFighter.offset = new Vector3(0, 5, fleetSize * zOff); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.offset_pursuit); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); XNAGame.Instance.CamFighter = camFighter; children.Add(camFighter); Ground ground = new Ground(); children.Add(ground); XNAGame.Instance.Ground = ground; foreach (Entity child in children) { child.Position.Y += 100; child.LoadContent(); } }
/// <summary> /// Inits the velocity constraints using the specified step /// </summary> /// <param name="step">The step</param> internal override void InitVelocityConstraints(TimeStep step) { Body body1 = Body1; Body body2 = Body2; Vec2 mulR1 = Box2DXMath.Mul(body1.GetXForm().R, LocalAnchor1 - body1.GetLocalCenter()); Vec2 mulR2 = Box2DXMath.Mul(body2.GetXForm().R, LocalAnchor2 - body2.GetLocalCenter()); Vec2 body1SweepC = body1.Sweep.C + mulR1; Vec2 body2SweepC = body2.Sweep.C + mulR2; Vec2 groundAnchor1 = Ground.GetXForm().Position + GroundAnchor1; Vec2 groundAnchor2 = Ground.GetXForm().Position + GroundAnchor2; // Get the pulley axes. U1 = body1SweepC - groundAnchor1; U2 = body2SweepC - groundAnchor2; float length1 = U1.Length(); float length2 = U2.Length(); if (length1 > Settings.LinearSlop) { U1 *= 1.0f / length1; } else { U1.SetZero(); } if (length2 > Settings.LinearSlop) { U2 *= 1.0f / length2; } else { U2.SetZero(); } float c = Constant - length1 - Ratio * length2; if (c > 0.0f) { State = LimitState.InactiveLimit; Impulse = 0.0f; } else { State = LimitState.AtUpperLimit; } if (length1 < MaxLength1) { LimitState1 = LimitState.InactiveLimit; LimitImpulse1 = 0.0f; } else { LimitState1 = LimitState.AtUpperLimit; } if (length2 < MaxLength2) { LimitState2 = LimitState.InactiveLimit; LimitImpulse2 = 0.0f; } else { LimitState2 = LimitState.AtUpperLimit; } // Compute effective mass. float cr1U1 = Vec2.Cross(mulR1, U1); float cr2U2 = Vec2.Cross(mulR2, U2); LimitMass1 = body1.InvMass + body1.InvI * cr1U1 * cr1U1; LimitMass2 = body2.InvMass + body2.InvI * cr2U2 * cr2U2; PulleyMass = LimitMass1 + Ratio * Ratio * LimitMass2; Box2DxDebug.Assert(LimitMass1 > Settings.FltEpsilon); Box2DxDebug.Assert(LimitMass2 > Settings.FltEpsilon); Box2DxDebug.Assert(PulleyMass > Settings.FltEpsilon); LimitMass1 = 1.0f / LimitMass1; LimitMass2 = 1.0f / LimitMass2; PulleyMass = 1.0f / PulleyMass; if (step.WarmStarting) { // Scale impulses to support variable time steps. Impulse *= step.DtRatio; LimitImpulse1 *= step.DtRatio; LimitImpulse2 *= step.DtRatio; // Warm starting. Vec2 p1 = -(Impulse + LimitImpulse1) * U1; Vec2 p2 = (-Ratio * Impulse - LimitImpulse2) * U2; body1.LinearVelocity += body1.InvMass * p1; body1.AngularVelocity += body1.InvI * Vec2.Cross(mulR1, p1); body2.LinearVelocity += body2.InvMass * p2; body2.AngularVelocity += body2.InvI * Vec2.Cross(mulR2, p2); } else { Impulse = 0.0f; LimitImpulse1 = 0.0f; LimitImpulse2 = 0.0f; } }
public void BuildLips(Ground ground) { BuildLips(ground.Chunks); }
public void InitOverlay() { /** * 创建自定义overlay */ mOverlay = new MyOverlay(this, Resources.GetDrawable(Resource.Drawable.icon_marka), mMapView); /** * 准备overlay 数据 */ GeoPoint p1 = new GeoPoint((int)(mLat1 * 1E6), (int)(mLon1 * 1E6)); OverlayItem item1 = new OverlayItem(p1, "覆盖物1", ""); /** * 设置overlay图标,如不设置,则使用创建ItemizedOverlay时的默认图标. */ item1.Marker = Resources.GetDrawable(Resource.Drawable.icon_marka); GeoPoint p2 = new GeoPoint((int)(mLat2 * 1E6), (int)(mLon2 * 1E6)); OverlayItem item2 = new OverlayItem(p2, "覆盖物2", ""); item2.Marker = Resources.GetDrawable(Resource.Drawable.icon_markb); GeoPoint p3 = new GeoPoint((int)(mLat3 * 1E6), (int)(mLon3 * 1E6)); OverlayItem item3 = new OverlayItem(p3, "覆盖物3", ""); item3.Marker = Resources.GetDrawable(Resource.Drawable.icon_markc); GeoPoint p4 = new GeoPoint((int)(mLat4 * 1E6), (int)(mLon4 * 1E6)); OverlayItem item4 = new OverlayItem(p4, "覆盖物4", ""); item4.Marker = Resources.GetDrawable(Resource.Drawable.icon_gcoding); /** * 将item 添加到overlay中 * 注意: 同一个itme只能add一次 */ mOverlay.AddItem(item1); mOverlay.AddItem(item2); mOverlay.AddItem(item3); mOverlay.AddItem(item4); /** * 保存所有item,以便overlay在reset后重新添加 */ mItems = new List<OverlayItem>(); mItems.AddRange(mOverlay.AllItem); // 初始化 ground 图层 mGroundOverlay = new GroundOverlay(mMapView); GeoPoint leftBottom = new GeoPoint((int)(mLat5 * 1E6), (int)(mLon5 * 1E6)); GeoPoint rightTop = new GeoPoint((int)(mLat6 * 1E6), (int)(mLon6 * 1E6)); Drawable d = Resources.GetDrawable(Resource.Drawable.ground_overlay); Bitmap bitmap = ((BitmapDrawable)d).Bitmap; mGround = new Ground(bitmap, leftBottom, rightTop); /** * 将overlay 添加至MapView中 */ mMapView.Overlays.Add(mOverlay); mMapView.Overlays.Add(mGroundOverlay); mGroundOverlay.AddGround(mGround); /** * 刷新地图 */ mMapView.Refresh(); mResetBtn.Enabled = false; mClearBtn.Enabled = true; /** * 向地图添加自定义View. */ viewCache = LayoutInflater.Inflate(Resource.Layout.custom_text_view, null); popupInfo = viewCache.FindViewById<View>(Resource.Id.popinfo); popupLeft = viewCache.FindViewById<View>(Resource.Id.popleft); popupRight = viewCache.FindViewById<View>(Resource.Id.popright); popupText = viewCache.FindViewById<TextView>(Resource.Id.textcache); button = new Button(this); button.SetBackgroundResource(Resource.Drawable.popup); /** * 创建一个popupoverlay */ IPopupClickListener popListener = new IPopupClickListenerImpl(this); pop = new PopupOverlay(mMapView, popListener); }
public Mark(int pupilId_, Ground ground_) { pupilId = pupilId_; ground = ground_; }
void FindGround(float clampEpsilon) { bool wasFalling = HasGround && !CurrentGround.IsTouching; RaycastHit[] above; RaycastHit[] below; FindGroundPoints(target.position, out above, out below); if (HasGround && above.Length > 0) { for (int i = ReferenceEquals(above[0].transform, CurrentGround.Transform) ? 1 : 0; i < above.Length; ++i) { if ((target.position - above[i].point).magnitude <= clampEpsilon) { CurrentGround = new Ground(above[i], true); goto done; } } for (int i = 0; i < above.Length; ++i) { // This means we have stepped through or fallen through a piece of ground if (ReferenceEquals(above[i].transform, CurrentGround.Transform) && (target.position - above[i].point).magnitude < 0.5) { CurrentGround = new Ground(above[i], true); goto done; } } } if (below.Length > 0) { CurrentGround = new Ground(below[0], (target.position - below[0].point).magnitude <= clampEpsilon); } else { CurrentGround = null; } done: if (HasGround && CurrentGround.IsTouching) { if (wasFalling && OnLand != null) { OnLand(); } if (IsJumping) { JumpDone(null); } ClampToGround(); RemoveForce("FallMomentum"); lastGroundTouch = Time.time; } }
// Use this for initialization void Start () { rb = GetComponent<Rigidbody2D>(); ground = GetComponent<Ground>(); }
public void InitTest() { Ground ground = new Ground() { ScaleVertical = 500f, Octaves = 8, Persistence = 128, Frequency = 4 }; ground.Init(); }
public Cat(Ground ground, int x, int y) : base(ground, x, y) { }
void Start() { Player = GameObject.FindGameObjectWithTag("Player"); Barrier = new GameObject("Barrier"); Barrier.tag = "Barrier"; Collectables = new GameObject("Collectables"); Collectables.tag = "Collectable"; Ground = GameObject.FindGameObjectWithTag("Ground").GetComponent<Ground>(); LoadCollectable (); boxes = Ground.GetBoxes(); mid = Ground.GetMid(); xBound = Ground.GetXBound(); yBound = Ground.GetYBound(); zBound = Ground.GetZBound(); hightOfBarrier_atLeast = Ground.hight * 3 + 20; finalHight = 0; int lastIndex = boxes.GetLength(0) - 1; style = new int[] {lastIndex - 2, lastIndex - 1, lastIndex}; bars1 = new List<GameObject>(); bars2 = new List<GameObject>(); bars3 = new List<GameObject>(); InstantiateBoxesForBarriers(); barriersNum = new int[] {10, 10, 1, 1, 2, 2, 3, 3, 3, 4, 5, 6, 7, 8}; collectableNumIfNoBarrier = new int[] {1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 7, 8, 9, 10}; StartCoroutine(WaitTime(timeToIncreaseBarrierDeffeculty)); // increase difficulty for barrier }
public void BuildMesh(Ground ground) { BuildMesh(ground.Chunks); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here //initialisation //Terrain Ground = new Ground(); //Joueur (NBanimation, TailleX,TailleY) Player = new Player(1, 20, 20); //ennemis //Création des ennemis de base for (int i = 0; i < inbEnnemisBase; i++) { Enemies.Add(new Enemy(1, 20, 20)); Enemies[i].Position.X = 800 - Rand.Next(200); Enemies[i].Position.Y = 480 - Rand.Next(480); } base.Initialize(); }
/// <summary> /// Describes whether this instance solve position constraints /// </summary> /// <param name="baumgarte">The baumgarte</param> /// <returns>The bool</returns> internal override bool SolvePositionConstraints(float baumgarte) { Body body1 = Body1; Body body2 = Body2; Vec2 groundAnchor1 = Ground.GetXForm().Position + GroundAnchor1; Vec2 groundAnchor2 = Ground.GetXForm().Position + GroundAnchor2; float linearError = 0.0f; if (State == LimitState.AtUpperLimit) { Vec2 mulR1 = Box2DXMath.Mul(body1.GetXForm().R, LocalAnchor1 - body1.GetLocalCenter()); Vec2 mulR2 = Box2DXMath.Mul(body2.GetXForm().R, LocalAnchor2 - body2.GetLocalCenter()); Vec2 body1SweepC = body1.Sweep.C + mulR1; Vec2 body2SweepC = body2.Sweep.C + mulR2; // Get the pulley axes. U1 = body1SweepC - groundAnchor1; U2 = body2SweepC - groundAnchor2; float length1 = U1.Length(); float length2 = U2.Length(); if (length1 > Settings.LinearSlop) { U1 *= 1.0f / length1; } else { U1.SetZero(); } if (length2 > Settings.LinearSlop) { U2 *= 1.0f / length2; } else { U2.SetZero(); } float c = Constant - length1 - Ratio * length2; linearError = Box2DXMath.Max(linearError, -c); c = Box2DXMath.Clamp(c + Settings.LinearSlop, -Settings.MaxLinearCorrection, 0.0f); float impulse = -PulleyMass * c; Vec2 p1 = -impulse * U1; Vec2 p2 = -Ratio * impulse * U2; body1.Sweep.C += body1.InvMass * p1; body1.Sweep.A += body1.InvI * Vec2.Cross(mulR1, p1); body2.Sweep.C += body2.InvMass * p2; body2.Sweep.A += body2.InvI * Vec2.Cross(mulR2, p2); body1.SynchronizeTransform(); body2.SynchronizeTransform(); } if (LimitState1 == LimitState.AtUpperLimit) { Vec2 mulR1 = Box2DXMath.Mul(body1.GetXForm().R, LocalAnchor1 - body1.GetLocalCenter()); Vec2 body1SweepC = body1.Sweep.C + mulR1; U1 = body1SweepC - groundAnchor1; float length1 = U1.Length(); if (length1 > Settings.LinearSlop) { U1 *= 1.0f / length1; } else { U1.SetZero(); } float c = MaxLength1 - length1; linearError = Box2DXMath.Max(linearError, -c); c = Box2DXMath.Clamp(c + Settings.LinearSlop, -Settings.MaxLinearCorrection, 0.0f); float impulse = -LimitMass1 * c; Vec2 p1 = -impulse * U1; body1.Sweep.C += body1.InvMass * p1; body1.Sweep.A += body1.InvI * Vec2.Cross(mulR1, p1); body1.SynchronizeTransform(); } if (LimitState2 == LimitState.AtUpperLimit) { Vec2 mulR2 = Box2DXMath.Mul(body2.GetXForm().R, LocalAnchor2 - body2.GetLocalCenter()); Vec2 body2SweepC = body2.Sweep.C + mulR2; U2 = body2SweepC - groundAnchor2; float length2 = U2.Length(); if (length2 > Settings.LinearSlop) { U2 *= 1.0f / length2; } else { U2.SetZero(); } float c = MaxLength2 - length2; linearError = Box2DXMath.Max(linearError, -c); c = Box2DXMath.Clamp(c + Settings.LinearSlop, -Settings.MaxLinearCorrection, 0.0f); float impulse = -LimitMass2 * c; Vec2 p2 = -impulse * U2; body2.Sweep.C += body2.InvMass * p2; body2.Sweep.A += body2.InvI * Vec2.Cross(mulR2, p2); body2.SynchronizeTransform(); } return(linearError < Settings.LinearSlop); }
void Start() { Player = GameObject.FindGameObjectWithTag("Player"); Barrier = new GameObject("Barrier"); Barrier.tag = "Barrier"; Ground = GameObject.FindGameObjectWithTag("Ground").GetComponent<Ground>(); boxes = Ground.GetBoxes(); mid = Ground.GetMid(); xBound = Ground.GetXBound(); yBound = Ground.GetYBound(); zBound = Ground.GetZBound(); hightOfBarrier_atLeast = Ground.hight * 3 + 20; finalHight = 0; bars = new List<GameObject>(); InstantiateBoxesForBarriers(); barriersNum = new int[] {10, 10, 1, 1, 2, 2, 3, 3, 3, 4, 5, 6, 7, 8}; // 10 means difference in length of rows noBarriersNum = new int[] {1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 7, 8, 9, 10, 14}; // if appear 10 StartCoroutine(WaitTime(timeToIncreaseBarrierDeffeculty)); // increase difficulty for barrier }