source: 2011/26/JaakkoL/Rogue Agent 2372/Rogue Agent 2372/Rogue Agent 2372/Peli.cs @ 2338

Revision 2338, 2.0 KB checked in by teeevasa, 8 years ago (diff)

initial bullet collision

Line 
1 using System;
2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class Peli : PhysicsGame
10{
11    const int SCREEN_WIDTH = 50;
12    const int SCREEN_HEIGTH = 50;
13    Player player;
14    Image background1 = LoadImage("Images/reactorBG");
15
16    public override void Begin()
17    {
18        Gravity = new Vector(0, -1000);
19        createLevel();
20
21        // Starts playing the background music, which is set to repeat
22        MediaPlayer.Play("Sounds/Stage1Music");
23        MediaPlayer.Volume = 0.5;
24        MediaPlayer.IsRepeating = true;
25
26        Camera.Follow(player);
27        Camera.ZoomFactor = 1.0;
28        Camera.StayInLevel = true;
29    }
30
31
32    // Creates the level from a text file
33    void createLevel()
34    {
35        TileMap levelSpec = TileMap.FromFile("ReactorEntrance.txt");
36        levelSpec['='] = createVerticalBlock;
37        levelSpec['|'] = createHorizontalBlock;
38        levelSpec['P'] = addPlayer;
39        levelSpec['a'] = addMeleeAlien;
40        levelSpec.Insert(SCREEN_WIDTH, SCREEN_HEIGTH);
41        Level.CreateBorders();
42        Level.Background.Image = background1;
43    }
44
45    Player addPlayer()
46    {
47        player = new Player(33, 74, Shape.Rectangle);
48        return player;
49    }
50
51    MeleeAlien addMeleeAlien()
52    {
53        MeleeAlien meleeAlien = new MeleeAlien(45, 80, Shape.Rectangle, 10, "Patrol");
54        return meleeAlien;
55    }
56
57    PhysicsObject createHorizontalBlock()
58    {
59        PhysicsObject hBlock = PhysicsObject.CreateStaticObject(SCREEN_WIDTH, SCREEN_HEIGTH,
60            Shape.Rectangle, CollisionShapeQuality.Best);
61        hBlock.Color = Color.Gray;
62        return hBlock;
63    }
64
65    PhysicsObject createVerticalBlock()
66    {
67        PhysicsObject vBlock = PhysicsObject.CreateStaticObject(SCREEN_WIDTH, SCREEN_HEIGTH,
68            Shape.Rectangle, CollisionShapeQuality.Best);
69        vBlock.Color = Color.DarkGray;
70        return vBlock;
71    }
72}
Note: See TracBrowser for help on using the repository browser.