public override void Update() { List <SpriteClass> collidable = gs.Collidable; int oldX = X; int oldY = Y; if (switched) { Sprite = switchedSprite; } else { if (Velocity.X > 0) { Sprite = rightSprite; } else if (Velocity.X < 0) { Sprite = leftSprite; } } lastPressedJump += 0.01f; CheckLevelFinished(); CheckFellDown(); if (!dead) { Move(); } bool onGround = false; #region MOVEMENT AND COLLISION if (Math.Abs(Velocity.Y) <= maxFallSpeed) { Velocity.Y += Gravity; } bool xCollided = false; bool yCollided = false; bool canJump = false; canWallJumpLeft = false; canWallJumpRight = false; //check movement collision then move foreach (SpriteClass sprite in collidable) { if (IsTouching(sprite, 3) && sprite is Refuel) { var refuel = (Refuel)sprite; if (!refuel.used && energy < energyMax) { energy = energyMax; gs.screenShakeEffect(7); gs.playRefuelEffect(); refuel.setUsed(true); } } if (IsTouching(sprite, 1) && sprite is Spike) { dead = true; } if (IsTouchingRight(sprite, 3) && Jumping && sprite is Wall) { canWallJumpRight = true; } if (IsTouchingLeft(sprite, 3) && Jumping && sprite is Wall) { canWallJumpLeft = true; } if (IsTouchingBottom(sprite, 1) && sprite is TempBlock) { var temp = (TempBlock)sprite; if (!temp.triggered) { gs.screenShakeEffect(2); gs.playBlockBreakEffect(); } temp.triggered = true; } if (sprite is TempBlock) { var tempCol = new TempBlock(sprite.Sprite, sprite.X, sprite.Y); tempCol.EnableCollision(GameScreen.howBigIs16Pixels, GameScreen.howBigIs16Pixels); if (!IsTouching(tempCol, 1)) { var temp = (TempBlock)sprite; temp.canRecover = true; } else if (IsTouching(tempCol, 1)) { var temp = (TempBlock)sprite; temp.canRecover = false; } } if (IsTouchingBottom(sprite, 1) && sprite is Wall) //|| IsTouchingLeft(sprite, 1) || IsTouchingRight(sprite, 1)) { { if (switched) { if (!Jumped) { Switch(); } } else { /* * if (energy < 40) { * energy += rechargeRate; * } */ } onGround = true; canJump = true; jumpGraceTimer = 0; } else { canJump = false; } if (lastPressedJump <= lastPressGrace) { if (jumpGraceTimer <= jumpGracePeriod) //if just a little off edge and still jumped, allow jump { if (!Jumping) { gs.playJumpEffect(); } if (!switched) { Jumped = true; } lastPressedJump += lastPressGrace; Velocity.Y = JumpSpeed; Jumping = true; } else { if (canWallJumpLeft && lastPressedJump < 0.001f) { Velocity.X = 12.3f; Velocity.Y = JumpSpeed * 0.8f; } else if (canWallJumpRight && lastPressedJump < 0.001f) { Velocity.X = -12.3f; Velocity.Y = JumpSpeed * 0.8f; } } //if just pressed K, then jump only a little bit if (switched) { Velocity.Y *= 0.3f; } } if (Velocity.X > 0 && IsTouchingRight(sprite, Velocity.X) && sprite is Wall) { while (!IsTouchingRight(sprite, 1)) { X += 1; } xCollided = true; Velocity.X = 0; } if (Velocity.X < 0 && IsTouchingLeft(sprite, Velocity.X) && sprite is Wall) { while (!IsTouchingLeft(sprite, 1)) { X -= 1; } xCollided = true; Velocity.X = 0; } if (Velocity.Y > 0 && IsTouchingBottom(sprite, Velocity.Y) && sprite is Wall) { while (!IsTouchingBottom(sprite, 1)) { Y += 1; } Jumping = false; yCollided = true; } if (Velocity.Y < 0 && IsTouchingTop(sprite, Velocity.Y) && sprite is Wall) { while (!IsTouchingTop(sprite, 1)) { Y -= 1; } yCollided = true; } } Jumped = false; if (!canJump) { jumpGraceTimer += 0.1; } if (!xCollided) { X += (int)Velocity.X; } if (!yCollided) { Y += (int)Velocity.Y; } else { Velocity.Y = 0; } #endregion MOVEMENT AND COLLISION Jumping = !onGround; if (energy <= 0 && switched) { Switch(); energy = 0; } if (switched && !dead) { var moveFactor = Math.Abs(Velocity.Y) + Math.Abs(Velocity.X); if (moveFactor > 0) { if (Input.IsPressed(Keys.A) || Input.IsPressed(Keys.D) || Input.IsPressed(Keys.W) || Input.IsPressed(Keys.S)) { energy -= depletionRate * moveFactor; } else { energy -= passiveDepRate; } } else { energy -= passiveDepRate; } } if (dead) { X = oldX; Y = oldY; //show = false; if (deathCounter == 0) { if (gs.blackAlpha != 1) { gs.screenShakeEffect(20); } gs.playDeadEffect(); } deathCounter += 1; if (deathCounter >= deathReset) { deathCounter = 0; gs.Restart(); } } }
protected void FieldValueChanged() { TempBlock.Execute(); OutputTextBox.Text = TempBlock.GeneratedData == null ? "" : TempBlock.GeneratedData.ToString(); }
private void UpdateGraph() { var pane = GraphControl.GraphPane; if (pane.CurveList.Count > 0) { pane.CurveList.Clear(); } TempBlock.Execute(); var outputNode = TempBlock.OutputNodes.FirstOrDefault(it => it.Name == ShowOutputList.Text); if (outputNode == null || outputNode.Object == null || outputNode.Object.Count == 0) { NoDataLabel.Visible = true; GraphControl.Invalidate(); GraphControl.Refresh(); return; } NoDataLabel.Visible = false; var index = ShowOutputSignal.SelectedIndex; if (index == -1 || index > outputNode.Object.Count - 1) { index = 0; } var signal = outputNode.Object[index]; var samples = signal.GetSamplesPair().ToList(); var yAxys = new ZedGraph.PointPairList(); yAxys.AddRange(samples.Select(it => new ZedGraph.PointPair(it[1], it[0]))); pane.AddCurve(outputNode.Name, yAxys, Color.Red, ZedGraph.SymbolType.None); if (signal.CustomPlot != null && signal.CustomPlot.Length > 0) { if (signal.CustomPlot.Length == 2) { var minValue = signal.Samples.Min() * 1.1; var maxValue = signal.Samples.Max() * 1.1; var area = new ZedGraph.PointPairList { { signal.CustomPlot[0], minValue }, { signal.CustomPlot[0], maxValue }, { signal.CustomPlot[0], maxValue }, { signal.CustomPlot[1], maxValue }, { signal.CustomPlot[1], maxValue }, { signal.CustomPlot[1], minValue }, { signal.CustomPlot[1], minValue }, { signal.CustomPlot[0], minValue } }; pane.AddCurve(DesignerResources.PreviousSize, area, Color.Orange, ZedGraph.SymbolType.None); } } pane.Legend.IsVisible = false; pane.Title.Text = ApplicationUtils.GetResourceString(outputNode.Name); pane.XAxis.Title.IsVisible = false; pane.YAxis.Title.IsVisible = false; if (!pane.IsZoomed && samples.Count() != 0) { pane.XAxis.Scale.Min = samples.ElementAt(0)[1]; pane.XAxis.Scale.Max = samples.ElementAt(samples.Count() - 1)[1]; } GraphControl.AxisChange(); GraphControl.Invalidate(); GraphControl.Refresh(); }
IEnumerator ConnectAsynchronously() { string serverUrl = FixURL(ServerField.text); GameSession.Login = LoginField.text; GameSession.ServerUrl = serverUrl; TextureAtlas.Init(); LoadingScreen.SetActive(true); // Download and parse main json ResourcesInfo resourcesInfo; using (var request = UnityWebRequest.Get("http://" + serverUrl + "/main.json")) { request.SendWebRequest(); while (!request.isDone) { Slider.value = request.downloadProgress; yield return(null); } if (request.isHttpError || request.isNetworkError) { LoadingScreen.SetActive(false); yield break; } resourcesInfo = JsonUtility.FromJson <ResourcesInfo>('{' + request.downloadHandler.text + '}'); resourcesInfo.resourcesUrl = FixURL(resourcesInfo.resourcesUrl); } // Download and parse remapper json RemapperInfo remapperInfo; using (var request = resourcesInfo.DownloadText(resourcesInfo.remapper)) { request.SendWebRequest(); while (!request.isDone) { Slider.value = request.downloadProgress; yield return(null); } if (request.isHttpError || request.isNetworkError) { LoadingScreen.SetActive(false); yield break; } remapperInfo = JsonUtility.FromJson <RemapperInfo>('{' + request.downloadHandler.text + '}'); GameSession.SetRemapper(remapperInfo.GetFlattenBlocks()); } // Download and apply foliage colormap using (var request = resourcesInfo.DownloadTexture(resourcesInfo.foliageColormap)) { request.SendWebRequest(); while (!request.isDone) { Slider.value = request.downloadProgress; yield return(null); } if (request.isHttpError || request.isNetworkError) { LoadingScreen.SetActive(false); yield break; } GameSession.FoliageColormap.Load(DownloadHandlerTexture.GetContent(request)); } // Download and apply grass colormap using (var request = resourcesInfo.DownloadTexture(resourcesInfo.grassColormap)) { request.SendWebRequest(); while (!request.isDone) { Slider.value = request.downloadProgress; yield return(null); } if (request.isHttpError || request.isNetworkError) { LoadingScreen.SetActive(false); yield break; } GameSession.GrassColormap.Load(DownloadHandlerTexture.GetContent(request)); } // Download and parse blocks json BlocksInfo blocksInfo; using (var request = resourcesInfo.DownloadText(resourcesInfo.blocks)) { request.SendWebRequest(); while (!request.isDone) { Slider.value = request.downloadProgress; yield return(null); } if (request.isHttpError || request.isNetworkError) { LoadingScreen.SetActive(false); yield break; } blocksInfo = JsonUtility.FromJson <BlocksInfo>('{' + request.downloadHandler.text + '}'); } // Load all blocks GameSession.Palette = new Block[blocksInfo.list.Length + 1]; for (int i = 1; i < blocksInfo.list.Length + 1; i++) { TempBlock block = blocksInfo.list[i - 1]; Vector3[] faces = new Vector3[block.textures.Length]; for (int j = 0; j < faces.Length; j++) { string textureName = block.textures[j]; using (var request = resourcesInfo.DownloadTexture(textureName)) { request.SendWebRequest(); while (!request.isDone) { Slider.value = request.downloadProgress; yield return(null); } if (request.isHttpError || request.isNetworkError) { LoadingScreen.SetActive(false); yield break; } faces[j] = TextureAtlas.AddTexture(textureName, DownloadHandlerTexture.GetContent(request), null); } } RenderType renderType = block.renderType == null ? RenderType.Block : (RenderType)Enum.Parse(typeof(RenderType), block.renderType); ShaderType shaderType = block.shaderType == null ? ShaderType.Block : (ShaderType)Enum.Parse(typeof(ShaderType), block.shaderType); BiomedType biomed = block.biomed == null ? BiomedType.None : (BiomedType)Enum.Parse(typeof(BiomedType), block.biomed); ColliderType colliderType = block.colliderType == null ? ColliderType.Block : (ColliderType)Enum.Parse(typeof(ColliderType), block.colliderType); Vector3 colliderMin = new Vector3(block.colliderMinX, block.colliderMinY, block.colliderMinZ); Vector3 colliderMax = new Vector3(block.colliderMaxX, block.colliderMaxY, block.colliderMaxZ); Block grassOverlay = null; if (block.grassOverlay != null) { using (var request = resourcesInfo.DownloadTexture(block.grassOverlay)) { request.SendWebRequest(); while (!request.isDone) { Slider.value = request.downloadProgress; yield return(null); } if (request.isHttpError || request.isNetworkError) { LoadingScreen.SetActive(false); yield break; } grassOverlay = new Block("", new Vector3[] { TextureAtlas.AddTexture( block.grassOverlay, DownloadHandlerTexture.GetContent(request), null) }, ColliderType.None, colliderMin, colliderMax); } } GameSession.Palette[i] = new Block(block.name, faces, colliderType, colliderMin, colliderMax, renderType, shaderType, biomed, grassOverlay, block.renderParam); } AsyncOperation operation = SceneManager.LoadSceneAsync("GameScene"); while (!operation.isDone) { float progress = Mathf.Clamp01(operation.progress / 0.9f); Slider.value = progress; yield return(null); } }