source: 2016/24/HaseebS/Dreamcast/Dreamcast/Dreamcast/Dreamcast.cs @ 7380

Revision 7380, 4.9 KB checked in by karkaite, 3 years ago (diff)

I have nearly completed making the game. Just have to additional features and some modification, i think that's it.

Line 
1using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class Dreamcast : PhysicsGame
10{
11
12    PlatformCharacter character;
13    PlatformCharacter character2;
14    Image player1Picture = LoadImage("Player1");
15    Image player2picture= LoadImage("player2");
16    AssaultRifle Player1Gun;
17    AssaultRifle Player2Gun;
18
19    public override void Begin()
20
21 
22    {
23        CreateLevel();
24        Camera.ZoomToAllObjects();
25        addControl();
26        Gravity = new Vector(0.0, -300.0);
27     
28       
29       
30       
31       
32
33    }
34
35    void CreateLevel()
36    {
37        TileMap boxes = TileMap.FromLevelAsset ("Hassebproject");
38        boxes.SetTileMethod('i', Obstacles );
39        boxes.SetTileMethod('W', Wall);
40        boxes.SetTileMethod('#', Ground);
41        boxes.SetTileMethod('C', Character);
42        boxes.SetTileMethod('D', Character2);
43        boxes.Execute();
44
45    }
46    void Obstacles(Vector place, double width, double height)
47    {
48        PhysicsObject obstacles = PhysicsObject.CreateStaticObject(width, height);
49        obstacles.Position = place;
50        obstacles.Shape = Shape.Rectangle;
51        obstacles.Color = Color.GreenYellow;
52       
53        Add(obstacles);
54    }
55
56    void Wall(Vector place, double width, double height)
57    {
58        PhysicsObject wall = PhysicsObject.CreateStaticObject(width, height);
59        wall.Position = place;
60        wall.Shape = Shape.Rectangle;
61        wall.Color = Color.Brown;
62        wall.CollisionIgnoreGroup = 1;
63        Add(wall);
64    }
65    void Ground(Vector place, double width, double height)
66    {
67        PhysicsObject ground = PhysicsObject.CreateStaticObject(width, height);
68        ground.Position = place;
69        ground.Color = Color.Gray;
70        ground.Shape = Shape.Rectangle;
71        //ground.CollisionIgnoreGroup = 1;
72        Add(ground);
73    }
74    void Character(Vector place, double height, double width)
75    {
76        character = new PlatformCharacter(30, 30);
77        character.Position = place;
78        character.X = -50.0;
79        character.Color = Color.Black;
80        character.Shape = Shape.Rectangle;
81        character.CollisionIgnoreGroup = 1;
82        character.Image = player1Picture;
83        Add(character);
84
85        createGun();
86    }
87
88    void Character2(Vector place, double height, double width)
89    {
90        character2 = new PlatformCharacter(30, 30);
91        character2.Position = place;
92        character2.X = 70.0;
93        character2.Color = Color.Black;
94        character2.Shape = Shape.Rectangle;
95        character2.CollisionIgnoreGroup = 1;
96        character2.Image = Image.Mirror(player2picture);
97        Add(character2);
98
99        createGun2();
100    }
101
102    void createGun()
103    {
104        Player1Gun = new AssaultRifle(30, 10);
105        Player1Gun.Ammo.Value = 1000;
106        Player1Gun.MaxAmmoLifetime = TimeSpan.FromSeconds(3.0);
107        //Add(Player1Gun);
108        character.Weapon = Player1Gun;
109    }
110    void createGun2()
111    {
112        Player2Gun = new AssaultRifle(30, 10);
113        Player2Gun.Ammo.Value = 1000;
114        // player2 gun project tile collision = what happens after the bullet hit someone(); 
115        Player2Gun.MaxAmmoLifetime = TimeSpan.FromSeconds(3.0);
116        character2.Weapon = Player2Gun;
117    }
118    void ProjectileHit(PhysicsObject ammunition, PhysicsObject target)
119    {
120        ammunition.Destroy();
121    }
122    void Shootthegun(AssaultRifle weapon)
123    {
124        PhysicsObject ammo = weapon.Shoot();
125        if (ammo != null)
126        {
127            //ammo.Size *= 2;
128        }
129    }
130
131    void addControl()
132    {
133       
134        Keyboard.Listen(Key.W, ButtonState.Down,jump, "Player1 will jump", character,new Vector(0.0, 200.0));
135        Keyboard.Listen(Key.A, ButtonState.Down, movement, "Player1 will turn left", character, new Vector(-100.0, 0.0));
136        Keyboard.Listen(Key.D,ButtonState.Down, movement, "Player1 will turn right", character,new Vector(100.0, 0.0));
137 
138        Keyboard.Listen(Key.LeftControl, ButtonState.Pressed, Shootthegun, "Shoot button", Player1Gun);
139
140       
141        Keyboard.Listen(Key.Up, ButtonState.Down, jump, "Player 2 will jump", character2, new Vector(0.0, 200.0));
142        Keyboard.Listen(Key.Left, ButtonState.Down, movement, "Player 2 will turn left", character2, new Vector(-100.0, 0.0));   
143        Keyboard.Listen(Key.Right, ButtonState.Down, movement, "Player 2 will move right", character2, new Vector(100.0, 0.0)); 
144        Keyboard.Listen(Key.Space, ButtonState.Pressed, Shootthegun, "Shoot button for Player2", Player2Gun );
145       
146        Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli");
147
148    }
149    void movement(PlatformCharacter player, Vector move)
150    {
151        player.Walk(move.X);
152    }
153    void jump (PlatformCharacter player, Vector jump)
154    {
155        player.Jump(jump.Y);
156    }
157
158 }
Note: See TracBrowser for help on using the repository browser.