source: 2017/24/SamuelN/SpaceShooter2k17/SpaceShooter2k17/SpaceShooter2k17/SpaceShooter2k17.cs @ 8644

Revision 8644, 2.2 KB checked in by npo17_6, 4 years ago (diff)
Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class SpaceShooter2k17 : PhysicsGame
10{
11    PhysicsObject player;
12    PhysicsObject bottom;
13    PhysicsObject top;
14    Color vari = RandomGen.NextColor();
15    Vector SpeedUp = new Vector(0, 300);
16    Vector SpeedDown = new Vector(0, -300);
17    AssaultRifle playerGun;
18
19    public override void Begin()
20    {
21        IsMouseVisible = true;
22        IsFullScreen = true;
23        Level.Background.CreateStars(5000);
24
25        player = PhysicsObject.CreateStaticObject(88, 143);
26        player.Image = LoadImage("ship");
27        player.X = -900;
28        player.Shape = Shape.FromImage(LoadImage("ship"));
29        player.Restitution = 1.0;
30
31        playerGun = new AssaultRifle(30, 10);
32        playerGun.InfiniteAmmo = true;
33        playerGun.ProjectileCollision = AmmusOsui;
34        player.Add(playerGun);
35
36        Add(player);
37
38        top = PhysicsObject.CreateStaticObject(2000, 100);
39        top.Y = 550;
40        top.Color = Color.FromHexCode("00FF00");
41        Add(top);
42
43        bottom = PhysicsObject.CreateStaticObject(2000, 100);
44        bottom.Y = -550;
45        bottom.Color = Color.FromHexCode("00FF00");
46        Add(bottom);
47
48        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
49
50        Keyboard.Listen(Key.Up, ButtonState.Down, SetSpeed, null, player, SpeedUp);
51        Keyboard.Listen(Key.Up, ButtonState.Released, SetSpeed, null, player, Vector.Zero);
52
53        Keyboard.Listen(Key.Down, ButtonState.Down, SetSpeed, null, player, SpeedDown);
54        Keyboard.Listen(Key.Down, ButtonState.Released, SetSpeed, null, player, Vector.Zero);
55    }
56    void AmmusOsui(PhysicsObject ammus, PhysicsObject kohde)
57    {
58       
59    }
60    void SetSpeed(PhysicsObject player, Vector nopeus)
61    {
62        if ((nopeus.Y > 0) && (player.Top > top.Bottom))
63        {
64            player.Velocity = Vector.Zero;
65            return;
66        }
67        if ((nopeus.Y < 0) && (player.Bottom < bottom.Top))
68        {
69            player.Velocity = Vector.Zero;
70            return;
71        }
72
73        player.Velocity = nopeus;
74    }
75}
Note: See TracBrowser for help on using the repository browser.