private void UpdateAnimation(bool moving, WalkDirection direction) { OTAnimatingSprite sprite = GetComponent<OTAnimatingSprite>(); if(isCurrentlySwinging) { return; } if(moving && currentWalkDirection != direction) { if(direction == WalkDirection.LEFT) { sprite.PlayLoop("walkLeft"); } else { sprite.PlayLoop("walkRight"); } } if(moving) { if(!sprite.isPlaying) { sprite.Play(); } } else { sprite.Pauze(); sprite.frameIndex = 1; if (direction == WalkDirection.LEFT) { sprite.frameIndex += 4; } } if(falling) { sprite.Pauze(); sprite.frameIndex = 0; if (direction == WalkDirection.LEFT) { sprite.frameIndex += 4; } } }
private void OnSwingDone(OTObject owner) { if(!isCurrentlySwinging) { return; } isCurrentlySwinging = false; OTAnimatingSprite sprite = GetComponent<OTAnimatingSprite>(); if(currentWalkDirection == WalkDirection.LEFT) { sprite.PlayLoop("walkLeft"); } else { sprite.PlayLoop("walkRight"); } sprite.onAnimationFinish = null; }
// The OnAnimationFinish delegate will be called when an animation or animation frameset // finishes playing. public void OnAnimationFinish(OTObject owner) { if (owner == gun) { // Because the only animation that finishes will be the gun's 'shoot' animation frameset // we know that we have to switch to the gun's looping 'idle' animation frameset gun.PlayLoop("idle"); } }
void OnTriggerEnter(Collider collider) { EnemyBehavior enemyBehavior = collider.GetComponent <EnemyBehavior>(); if (enemyBehavior != null) { // Enter on Cooldown this.timeBeforeNextFire = this.fireRateOnSeconds; // Disable collision. Enable when bullet dies. this.collider.enabled = false; Sprite.PlayLoop("Attack"); // Create bullet GameObject firedBullet = (GameObject)Instantiate(this.bullet, this.transform.position, Quaternion.identity); firedBullet.GetComponent <BulletBehavior>().target = collider.gameObject; firedBullet.GetComponent <BulletBehavior>().parent = this.gameObject; firedBullet.GetComponent <BulletBehavior>().damage = this.damage; this.missile = firedBullet; } }
// Use this for initialization void Start() { OT.view.position = new Vector2(0.0f, 900f); Camera.mainCamera.GetComponent <FadeController>().FadeIn(Time.time, 2f); Rect pos = new Rect(Screen.width / 2 - 300f, Screen.height / 2 - 32f, 600f, 64f); Color color = new Color(1f, 1f, 1f); style = new GUIStyle(); style.alignment = TextAnchor.MiddleCenter; style.normal.textColor = color; allDialog.Add(new Dialog(pos, "Good work, son.", color, style, Time.time, 5.0f + Time.time)); allDialog.Add(new Dialog(pos, "End.", color, style, Time.time + 5.0f, 10000000.0f + Time.time)); firefly = (OTAnimatingSprite)OT.CreateSprite("Firefly"); firefly.GetComponent <Firefly>().enabled = false; firefly.depth = -100; firefly.size = new Vector2(32f, 32f); firefly.pivot = OTObject.Pivot.Center; firefly.PlayLoop("right"); }
// Update is called once per frame void Update() { // only go on if Orthello is ready if (!OT.isValid) { return; } // Initialize application once if (!initialized) { Initialize(); } // if containers that were created are not ready yet, lets hold. if (!OT.ContainersReady()) { return; } switch (appMode) { case 1: star.visible = true; // we are in the star stage so increase star creation wait time starTime += Time.deltaTime; // check if we may create a new star if (starTime > starSpeed) { // Lets create one, reset the wait time starTime = 0; // Create a copy of out animating star OTAnimatingSprite newStar = OT.CreateSprite(star) as OTAnimatingSprite; // Put this star in our active stars list stars.Add(newStar); // Give it a random size newStar.size *= (0.3f + Random.value * 2.5f); // Give it a random position on the right border of the screen newStar.position = new Vector2((Screen.width / 2) + newStar.size.x / 2, ((Screen.height / 2) * -1) + newStar.size.y / 2 + Random.value * (Screen.height - newStar.size.y)); // Calculate the depth (smaller stars to the back, bigger to the front) newStar.depth = (int)((1 / newStar.size.x) * 100); // Set material to additive newStar.additive = true; newStar.frameIndex = 0; } // Lets loop all active stars // HINT : Because we will be adjusting (removing) items as they get out of view, // we better not use a for() loop. While() is the better way for this. int s = 0; while (s < stars.Count) { // get next active star OTAnimatingSprite dStar = stars[s]; // increase its position dStar.position += new Vector2(stars[s].size.x * 3 * Time.deltaTime * -1, 0); // If the star gets out of view we will remove and destroy it if (dStar.outOfView) { // remove from active stars list stars.Remove(dStar); // destroy this object OT.DestroyObject(dStar); // no need to increment iterator as we just removed the current element } else { s++; // increment iterator } } break; case 2: man.visible = true; // we are in the walking man stage so calculate a normalized vector from // our man to the mouse pointer Vector2 mouseVector = (OT.view.mouseWorldPosition - man.position).normalized; // The Atan2 will give you a -3.141 to 3.141 range depending of your vector x/y values float angle = Mathf.Atan2(mouseVector.x, mouseVector.y); // Play the right frameset dependent on the angle float part = 6.2f / 8; string anim = ""; if (angle > -1 * (part / 2) && angle <= (part / 2)) { anim = "up"; } else if (angle > -3 * (part / 2) && angle <= -1 * (part / 2)) { anim = "upLeft"; } else if (angle > -5 * (part / 2) && angle <= -3 * (part / 2)) { anim = "left"; } else if (angle > -7 * (part / 2) && angle <= -5 * (part / 2)) { anim = "downLeft"; } else if (angle > (part / 2) && angle <= 3 * (part / 2)) { anim = "upRight"; } else if (angle > 3 * (part / 2) && angle <= 5 * (part / 2)) { anim = "right"; } else if (angle > 5 * (part / 2) && angle <= 7 * (part / 2)) { anim = "downRight"; } else { anim = "down"; } man.PlayLoop(anim); // adjust background scroll speed related to our mouse vector back.scrollSpeed = mouseVector * 10; break; } // color menu red when we are hovering over an item if (OT.Over(stage1)) { stagemesh1.renderer.material.color = new Color(1, .3f, .3f); } else { stagemesh1.renderer.material.color = new Color(1, 1, 1); } if (OT.Over(stage2)) { stagemesh2.renderer.material.color = new Color(1, .3f, .3f); } else { stagemesh2.renderer.material.color = new Color(1, 1, 1); } //check if we want to change stage if (OT.Clicked(stage1)) { appMode = 1; CreateObjects(); } else if (OT.Clicked(stage2)) { appMode = 2; CreateObjects(); } }
// Update is called once per frame void Update () { Vector3 moveRequest = new Vector3(); moveRequest = new Vector3(Input.GetAxisRaw("Horizontal"), 0.0f, 0.0f); WalkDirection direction = currentWalkDirection; if (moveRequest.sqrMagnitude > 0.0) { moveRequest.Normalize(); if (moveRequest.x > 0) { direction = WalkDirection.RIGHT; } else { direction = WalkDirection.LEFT; } } if(Input.GetKeyDown(KeyCode.Z) && !isCurrentlySwinging) { isCurrentlySwinging = true; OTAnimatingSprite sprite = GetComponent<OTAnimatingSprite>(); if(direction == WalkDirection.LEFT) { sprite.PlayOnce("catchLeft"); } else { sprite.PlayOnce("catchRight"); } sprite.Play(); sprite.onAnimationFinish = OnSwingDone; } if(isCurrentlySwinging) { float netXCoord; if(direction == WalkDirection.LEFT) { netXCoord = -64.0f; } else { netXCoord = 24.0f; } Rect net = new Rect(this.transform.position.x + netXCoord, this.transform.position.y - 30f, 40f, 60f); bool captured = fireflies.Captures(net); if(captured) { Debug.Log ("Got one!"); pickupSound.Play(); OTAnimatingSprite firefly = (OTAnimatingSprite) OT.CreateSprite("Firefly"); firefly.GetComponent<Firefly>().enabled = false; firefly.depth = -100; firefly.size = new Vector2(64f, 64f); firefly.pivot = OTObject.Pivot.BottomLeft; firefly.PlayLoop("right"); uiFireflies.Add (firefly); OnSwingDone(null); } } moveRequest *= Time.deltaTime * moveSpeed; bool wasFalling = falling; falling = terrain.CanMoveTo(this.transform.localPosition.x, this.transform.localPosition.y - 1.2f, collidingBox); if(!falling && !terrain.CanMoveTo(this.transform.localPosition.x + moveRequest.x * 10f, this.transform.localPosition.y - 1.2f, collidingBox)) { lastJumpPos = this.transform.localPosition; lastJumpCount = uiFireflies.Count; } moveRequest = terrain.Move(this.transform.localPosition, collidingBox, moveRequest); this.transform.Translate(moveRequest); if(wasFalling && !falling) { landSound.Play(); } if(!falling && verticalSpeed < 0f) { verticalSpeed = 0f; if(Input.GetKeyDown(KeyCode.Space)) { jumpSound.Play(); verticalSpeed = jumpSpeed; } } Fall(); UpdateAnimation(moveRequest.sqrMagnitude > 0.0, direction); currentWalkDirection = direction; UpdateDialog(); UpdateEvents(); UpdateUISprites(); if(this.transform.localPosition.y < 100) { this.transform.localPosition = lastJumpPos; while(uiFireflies.Count > lastJumpCount) { uiFireflies.RemoveAt(0); } } }