Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Jypeli;
- using Jypeli.Assets;
- using Jypeli.Controls;
- using Jypeli.Widgets;
- public class Ht : PhysicsGame
- {
- PhysicsObject pelaaja;
- PhysicsObject tahtain;
- PhysicsObject golfpallo;
- const double golfpallopysahtyy = 0.1;
- public override void Begin()
- {
- LuoKenttä();
- AsetaOhjaimet();
- //Update(Jypeli.Time.SinceLastUpdate);
- }
- //protected override void Update(Time time)
- //{
- // if (golfpallo != null &&( Math.Abs(golfpallo.Velocity.X + golfpallo.Velocity.Y) < golfpallopysahtyy))
- // {
- //pelaaja.X = golfpallo.X;
- //pelaaja.Y = golfpallo.Y;
- //golfpallo.Destroy();
- //}
- //base.Update(time);
- //}
- // Luo pelikentän ja tarvittavat oliot
- void LuoKenttä()
- {
- pelaaja = new PhysicsObject(20.0, 30.0);
- pelaaja.Shape = Shape.Rectangle;
- Mouse.ListenMovement(0.01, Tahtaa, null);
- pelaaja.IgnoresCollisionResponse = true;
- Add(pelaaja);
- tahtain = new PhysicsObject(15.0, 15.0, Shape.Circle);
- tahtain.IgnoresCollisionResponse = true;
- //tahtain.Image = LoadImage("tahtain");
- Add(tahtain);
- Mouse.IsCursorVisible = true;
- Mouse.ListenMovement(0.001, KuunteleLiiketta, null);
- Level.CreateBorders(1.0, false);
- Level.BackgroundColor = Color.LightBlue;
- }
- void Tahtaa(AnalogState hiirenLiike)
- {
- Vector suunta = (Mouse.PositionOnWorld - pelaaja.AbsolutePosition).Normalize();
- pelaaja.Angle = suunta.Angle;
- }
- void KuunteleLiiketta(AnalogState hiirenTila)
- {
- tahtain.X = Mouse.PositionOnWorld.X;
- tahtain.Y = Mouse.PositionOnWorld.Y;
- Vector hiirenLiike = hiirenTila.MouseMovement;
- }
- void AsetaOhjaimet()
- {
- Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Ammu, "Ammu aseella.");
- PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
- Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
- }
- private void Ammu()
- //aliohjelma ampuu golfpallon kohti kursoria
- {
- // if (golfpallo is PhysicsObject) return;
- //else
- golfpallo = new PhysicsObject(5.0, 5.0);
- golfpallo.Shape = Shape.Circle;
- golfpallo.X = pelaaja.X;
- golfpallo.Y = pelaaja.Y;
- golfpallo.Restitution = 0.5;
- golfpallo.KineticFriction = 1.0;
- golfpallo.LinearDamping = 0.99;
- Add(golfpallo);
- Vector lyonti = new Vector(tahtain.X, tahtain.Y);
- golfpallo.Hit(lyonti);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement