source: 2015/24/ValtteriV/Happy Balloon Jump/Happy Balloon Jump/Happy Balloon Jump/Happy_Balloon_Jump.cs @ 6079

Revision 6079, 4.2 KB checked in by jotapoti, 6 years ago (diff)

Happy Balloon Jump - esitelty versio

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8using Jypeli.WP7;
9
10public class Happy_Balloon_Jump : PhysicsGame
11{
12    PhysicsObject player, player2; 
13   
14    public override void Begin()
15    {
16        CreateLevel();
17        Player();
18        Player2();
19
20        Camera.Follow(player, player2);
21        Camera.ZoomFactor = 0.5;
22        Camera.StayInLevel = true;
23
24        TouchPanel.Listen(ButtonState.Down, Movement, "");
25        PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");
26    }
27    void Player()
28    {
29        player = new PhysicsObject(LoadImage("PlayerNew"));
30        Add(player);
31        player.Position = new Vector(200.0, 0.0);
32        AddCollisionHandler(player, "player", PelaajaTormasi);
33        //TouchPanel.Listen(ButtonState.Down, MovePlayer, "Moves the balloon", player);
34    }
35
36    void CreateLevel()
37    {
38        /*PhysicsObject grass = PhysicsObject.CreateStaticObject(410.0, 260.0);
39        Add(grass);
40        grass.Image = LoadImage("Grass");*/
41        //Level.Size = new Vector(Screen.Size.Y*2, Screen.Size.X*2);
42        //Level.Width *= 5;
43        Level.Size = new Vector(4000.0, 2000.0);
44        //Camera.ZoomTo(new Vector(Level.Left, Level.Bottom - 40), new Vector(Screen.Right, Screen.Top));
45
46
47        Surface alaReuna = Surface.CreateBottom(Level, 100, 1000, 20);
48        alaReuna.Position += new Vector(0.0, alaReuna.Height - 100);
49        // alaReuna.Position += new Vector(0.0, alaReuna.Height);
50        Add(alaReuna);
51
52        Borders();
53
54        Gravity = new Vector(0, -100);
55
56        // Camera.ZoomTo(Level.Left, Level.Bottom, Camera.ScreenToWorld(new Vector(Screen.Right, 0.0)).X, Camera.ScreenToWorld(new Vector(0.0, Screen.Top)).Y);
57        // Camera.ZoomToLevel();
58
59        //GameObject background = new GameObject(LoadImage("BlueSky"));
60        //background.Width = Level.Width * 1.2;
61        //background.Height = Level.Height * 1.2;
62        //background.Position = new Vector(Level.Left + Screen.Width, 0.0);
63        //Layers[-3].RelativeTransition = new Vector(0.0, 0.0);
64        //Add(background, -3);
65
66        Level.Background.Image = LoadImage("BlueSky");
67        Level.Size = new Vector(5000, 5000);
68        Level.Background.FitToLevel();
69   
70    }
71    void MovePlayer(Touch kosketus, PhysicsObject player)
72    {
73        player.Push(kosketus.MovementOnWorld * 10);
74    }
75    void Borders()
76    {
77        Surface oikeaReuna = Surface.CreateRight(Level, 10, 10, 2);
78        oikeaReuna.Color = Color.Transparent;
79        Add(oikeaReuna);
80        Surface ylaReuna = Surface.CreateTop(Level, 10, 10, 2);
81        ylaReuna.Color = Color.Transparent;
82        Add(ylaReuna);
83        Surface vasenReuna = Surface.CreateLeft(Level, 10, 10, 2);
84        vasenReuna.Color = Color.Transparent;
85        Add(vasenReuna);
86    }
87    void Player2()
88    {
89        player2 = new PhysicsObject(LoadImage("Player2Black"));
90        Add(player2);
91        //TouchPanel.Listen(ButtonState.Down,Player2Movement, "Moves The Balloon", player2);
92        AddCollisionHandler(player2, "player", PelaajaTormasi);
93        player2.Tag = "player";
94    }
95    void Player2Movement(Touch kosketus, PhysicsObject player2)
96    {
97        player2.Push(kosketus.MovementOnWorld * 10);
98    }
99    void Movement(Touch kosketus)
100    {
101        PhysicsObject who = player2;
102       
103        if ((kosketus.PositionOnScreen - player.AbsolutePosition).Magnitude < (kosketus.PositionOnScreen - player2.Position).Magnitude)
104        {
105            who = player;
106        }
107       
108        who.Push(kosketus.MovementOnWorld * 100);
109    }
110    void PelaajaTormasi(PhysicsObject tormaa, PhysicsObject kohde)
111    {
112        if (tormaa.Velocity.Magnitude >= kohde.Velocity.Magnitude)
113        {
114            kohde.Destroy();
115        }
116        else
117        {
118            tormaa.Destroy();
119        }
120
121        Timer.SingleShot(2.00, AloitaAlusta);
122    }
123    void AloitaAlusta()
124    {
125        player.Destroy();
126        player2.Destroy();
127       
128        Player();
129        Player2();
130        Camera.Follow(player, player2);
131    }
132}
Note: See TracBrowser for help on using the repository browser.