private void SelectNodeForTouch(PointF touchLocation) { // get the node that is on the posiion touchLocation SKSpriteNode touchedNode = (SKSpriteNode)this.GetNodeAtPoint(touchLocation); // if this is a new node being touched then stop all previous animation and set it as the selected node. if (this.SelectedNode != touchedNode) { if (this.SelectedNode != null) { this.SelectedNode.RemoveAllActions(); this.SelectedNode.RunAction(SKAction.RotateToAngle(0.0f, 0.1)); } this.SelectedNode = touchedNode; // if the node we've touched is an animal node then make it wiggle y0! if (touchedNode.Name == ANIMAL_NODE_NAME) { SKAction sequence = SKAction.Sequence(new SKAction[] { SKAction.RotateByAngle(this.DegreeToRadian(-4.0f), 0.1), SKAction.RotateByAngle(0.0f, 0.1), SKAction.RotateByAngle(this.DegreeToRadian(4.0f), 0.1) }); this.SelectedNode.RunAction(SKAction.RepeatActionForever(sequence)); } } }
public void FaceTo(CGPoint position) { var angle = GraphicsUtilities.RadiansBetweenCGPoints(position, Position); var ang = GraphicsUtilities.PalarAdjust(angle); SKAction action = SKAction.RotateToAngle(ang, 0); RunAction(action); }
public void RotatePlayer_Pitch() { int pitch1 = this.Pitch; double radians = pitch1 * Math.PI / 180; var action1 = SKAction.RotateToAngle((float)radians, 1.0); //HAVE PLAYER MOVE TO ROTATED ANGLE this.PlayerSpriteObject.RunAction(action1); }
public void RotatePlayer_Heading() { //rotates by the heading int Heading1 = this.Heading; double radians = Heading1 * Math.PI / 180; var action1 = SKAction.RotateToAngle((float)radians, 1.0); //HAVE PLAYER MOVE rotation this.PlayerSpriteObject.RunAction(action1); }
public void FireAtPlayer(nfloat x, nfloat y) { int headingdegPlayer; int pitchdegPlayer = 1; //don't need to know the pitch of the player //only need to know general direction for tank double X = (double)x; double Y = (double)y; double pX = (double)this.enemySprite.Position.X; double pY = (double)this.enemySprite.Position.Y; //intx and inty are the position of the player //1)TODO:calculate the angle between the tank and the player headingdegPlayer = (int)Math.Atan2((pY - Y), (pX - X)); this.pitch_cannon = headingdegPlayer; //2)TODO:rotate the tank to that player angle var rotate = SKAction.RotateToAngle((nfloat)(headingdegPlayer * Math.PI / 180), 2.0); //4)TODO:shoot the missile at that angle this.Cannon[0].FireBullet(headingdegPlayer, pitchdegPlayer, (nfloat)x, (nfloat)y); }
public void FireBullet(int pitch, int heading, nfloat startingx, nfloat startingy) { this.isFired = true; //logic for bullet //need a starting point this.x_world = (int)startingx; this.y_world = (int)startingy; int signx = 0; int signy = 0; int dir = 0; int headingcpy = heading; this.Bullet.Position = new CoreGraphics.CGPoint(startingx, startingy); double pitchradians = (pitch * (Math.PI / 180)) - (Math.PI / 2); double heaindingradians = heading * (Math.PI / 180); /*while(pitchradians < 0){ * pitchradians += (2 * Math.PI); * } */ while (headingcpy < 0) { headingcpy += 360; } if ((headingcpy >= 0) && (headingcpy <= 90)) { dir = 1; signx = 1; signy = 1; } else if ((headingcpy > 90) && (headingcpy < 180)) { dir = 2; signx = -1; signy = 1; } else if ((headingcpy >= 180) && (headingcpy < 270)) { dir = 3; signx = -1; signy = -1; } else if ((headingcpy > 270) && (headingcpy <= 360)) { dir = 4; signx = 1; signy = -1; } var action = SKAction.MoveBy((float)(signx * 5000 * Math.Cos((pitch * Math.PI / 180))), (float)(signy * 5000 * Math.Sin((pitch * Math.PI / 180))), 5.0); if ((dir == 1) || (dir == 2)) { var action1 = SKAction.RotateToAngle((nfloat)pitchradians, .25); this.Bullet.RunAction(action1); //rotate the missile first this.Bullet.RunAction(action); //launch the missile! } else if ((dir == 3) || (dir == 4)) { var action1 = SKAction.RotateToAngle((nfloat)(pitchradians + Math.PI), .25); this.Bullet.RunAction(action1); //rotate the missile first this.Bullet.RunAction(action); //launch the missile! } }
public async void AnalyzeTouch() { var touchDiff = LastTouch.Y - FirstTouch.Y; var touchDiffX = LastTouch.X - FirstTouch.X; if (touchDiff > 66) { var sprite = new SKSpriteNode("dart_blue") { Position = new CGPoint( FirstTouch.X, -5f) }; //dart_blue // var sprite1 = new SKSpriteNode ("knife1") { // Position = new CGPoint( // FirstTouch.X,-5f ) // }; sprite.SetScale(1.5f); AddChild(sprite); var finaldest = new CGPoint(); var action = SKAction.MoveTo(finaldest, 0.3); if (touchDiff < 150) { finaldest = new CGPoint(LastTouch.X + (touchDiffX * 0.5f), LastTouch.Y + (touchDiff * 0.3f)); action = SKAction.MoveTo(finaldest, 0.3); //FollowPath (np, 3.0); } else { finaldest = new CGPoint(LastTouch.X + (touchDiffX * 0.5f), LastTouch.Y + (touchDiff * 0.6f)); action = SKAction.MoveTo(finaldest, 0.2); } nfloat rotatingAngle = touchDiffX / 333; Console.WriteLine("touchDiff:::" + touchDiffX); Console.WriteLine("toRadians:::" + rotatingAngle); //to radians var RotAction = SKAction.RotateToAngle(-rotatingAngle, 0); //to small size var scaleAction = SKAction.ScaleTo(0.8f, 0.1555); sprite.RunAction(action); sprite.RunAction(RotAction); sprite.RunAction(scaleAction); SpriteCount++; //COLLISION if (PhotoNode.ContainsPoint(finaldest)) { CurrentScore++; System.Diagnostics.Debug.WriteLine("POINTS: " + CurrentScore); System.Diagnostics.Debug.WriteLine("collideddddddd::::::::::::::::::::::"); await System.Threading.Tasks.Task.Delay(200); await System.Threading.Tasks.Task.Delay(200); var displayScoreNode = new SKLabelNode(); displayScoreNode.Text = "" + CurrentScore; //.ToString (); displayScoreNode.Position = new CGPoint(Size.Width / 2, (Size.Height / 2) - 200); displayScoreNode.FontSize = 80; displayScoreNode.FontColor = UIColor.Red; displayScoreNode.FontName = "GillSans-Bold"; displayScoreNode.SetScale(0.1f); var moveUpAction = SKAction.MoveTo((new CGPoint(Size.Width / 2, Size.Height / 2)), 0.5); var scaleUpAction = SKAction.ScaleBy(9f, 0.5); AddChild(displayScoreNode); displayScoreNode.RunAction(moveUpAction); displayScoreNode.RunAction(scaleUpAction); await System.Threading.Tasks.Task.Delay(1000); displayScoreNode.RemoveFromParent(); } else { await System.Threading.Tasks.Task.Delay(300); SystemSound.Vibrate.PlaySystemSound(); //.PlayAlertSound(); SystemSound.Vibrate.Close(); } //REMOVE SLOW DART if (touchDiff < 100) { await System.Threading.Tasks.Task.Delay(200); sprite.RemoveFromParent(); SpriteCount--; } if (touchDiff > 120 && (!PhotoFrameNode.ContainsPoint(finaldest))) { await System.Threading.Tasks.Task.Delay(300); SystemSound.Vibrate.PlaySystemSound(); //.PlayAlertSound(); SystemSound.Vibrate.Close(); await System.Threading.Tasks.Task.Delay(200); } } }
//********************************************************************** //*****Update(double currentTime){}************************************* //*****is an event that is your frame per second update feature********* //*****essentially your game engine if it's simple enough for writing*** //*****after every frame checks for collisions between player weapons*** //*****and enemy towersa label (myLabel1) is updated every 30 frames**** //***** to display headingthis game is set to around 60 frames per sec** //*****for smoothness, Every Sec (60frames) a random enemy will fire**** //********************************************************************** public override void Update(double currentTime) { // Called before each frame is rendered //check fuel //update screen gaugues SKLabelNode headingvalue = (SKLabelNode)GetChildNode("myLabel1"); SKLabelNode scorelabel = (SKLabelNode)GetChildNode("ScoreLabel"); SKSpriteNode NavArrow = (SKSpriteNode)GetChildNode("NavArrow"); Random enemyNumber = new Random(); if ((PlayerRide.PlayerSpriteObject != null) && (headingvalue != null)) { if ((FrameNumber % 30) == 0) { headingvalue.Text = PlayerRide.GetHeading().ToString(); var action = SKAction.MoveBy(PlayerRide.hSpeed, PlayerRide.vSpeed, 1.0); PlayerRide.PlayerSpriteObject.RunAction(action); } var action2 = SKAction.RotateToAngle((nfloat)((PlayerRide.GetHeading() - 90) * Math.PI / 180), 1.0); NavArrow.RunAction(action2); } if ((FrameNumber % 60) == 0) { int j = (enemyNumber.Next()) % ((EnemyTowers.Length)); int y = (enemyNumber.Next()) % ((EnemyTowers[j].GuardMagazine.Length)); if (EnemyTowers[j].GuardMagazine[y].Bullet != null) { if (EnemyTowers[j].GuardMagazine[y].isFired == false) { AddChild(EnemyTowers[j].GuardMagazine[y].Bullet); EnemyTowers[j].FireAtRandom(); } } } //EveryFrame we need to check for collisions between the missiles //1)check for player missile hits for (int i = 0; i < EnemyTowers.Length; i += 1) { if (PlayerRide.MachineGun[0].BulletCollided(PlayerRide.MachineGun, EnemyTowers[i])) { EnemyTowers[i].TowerGotHit(); score += 10; scorelabel.Text = "Score: " + score.ToString(); } } for (int i = 0; i < EnemyTowers.Length; i += 1) { if (EnemyTowers[i].isDead()) { EnemyTowers[i].tower.RemoveFromParent(); } } FrameNumber += 1; /* * if((FrameNumber% 120) == 0){ * for (int x = 0; x < EnemyTowers.Length; x = 1){ * for (int y = 0; y < EnemyTowers[x].GuardMagazine.Length; y += 1){ * if(EnemyTowers[x].GuardMagazine[y].getXposition() > Frame.Width){ * EnemyTowers[x].GuardMagazine[y].Bullet.RemoveFromParent(); * } * } * } * } */ }