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

Revision 2361, 3.7 KB checked in by teeevasa, 8 years ago (diff)

added preliminary rifle support

RevLine 
[2355]1using System;
[2187]2using System.Collections.Generic;
3using Jypeli;
4using Jypeli.Assets;
5using Jypeli.Controls;
6using Jypeli.Effects;
7using Jypeli.Widgets;
8
9public class Peli : PhysicsGame
10{
[2349]11    List<Label> titleMenu;
[2227]12    const int SCREEN_WIDTH = 50;
[2355]13    const int SCREEN_HEIGHT = 50;
[2206]14    Player player;
[2295]15    Image background1 = LoadImage("Images/reactorBG");
[2206]16
[2187]17    public override void Begin()
18    {
[2345]19        menuCreate();
[2349]20    }
[2187]21
[2349]22    void menuCreate()
23    {
24        ClearAll();
25        titleMenu = new List<Label>();
26
[2354]27        Label startGameButton = new Label("Start Game");
28        startGameButton.Position = new Vector(0, 40);
29        titleMenu.Add(startGameButton);
[2349]30
[2354]31        Label exitGameButton = new Label("Exit Game");
32        exitGameButton.Position = new Vector(0, -40);
33        titleMenu.Add(exitGameButton);
[2349]34
[2360]35        //Starts playing the title screen music, which is set to repeat (which is unnecessary though - who would want to stare at an inanimate screen for 4 minutes?)
[2358]36        MediaPlayer.Play("Sounds/TitleScreenMusic");
37        MediaPlayer.Volume = 1.0;
38        MediaPlayer.IsRepeating = true;
39
[2349]40        foreach (Label titleMenuScreen in titleMenu)
41        {
42            Add(titleMenuScreen);
43        }
44
[2354]45        Mouse.ListenOn(startGameButton, MouseButton.Left, ButtonState.Pressed, startGame, null);
46        Keyboard.Listen(Key.Enter, ButtonState.Pressed, startGame, null);
[2349]47
[2354]48        Mouse.ListenOn(exitGameButton, MouseButton.Left, ButtonState.Pressed, Exit, null);
49        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, null);
50
[2349]51        Mouse.IsCursorVisible = true;
52        Mouse.ListenMovement(1.0, MenuMovement, null);
53    }
54
55    void MenuMovement(AnalogState mouseState)
56    {
57        foreach (Label button in titleMenu)
58        {
59            if (Mouse.IsCursorOn(button))
60            {
61                button.TextColor = Color.DarkRed;
62            }
63            else
64            {
65                button.TextColor = Color.DarkBlue;
66            }
67        }
68    }
69
[2354]70    void startGame()
[2349]71    {
72        ClearAll();
73        createLevel();
74        Gravity = new Vector(0, -1000);
75
[2358]76        MediaPlayer.Stop();
[2338]77        // Starts playing the background music, which is set to repeat
[2286]78        MediaPlayer.Play("Sounds/Stage1Music");
[2358]79        MediaPlayer.Volume = 0.75;
[2338]80        MediaPlayer.IsRepeating = true;
[2276]81
[2234]82        Camera.Follow(player);
[2290]83        Camera.ZoomFactor = 1.0;
[2234]84        Camera.StayInLevel = true;
[2187]85    }
86
[2227]87    void createLevel()
[2187]88    {
[2231]89        TileMap levelSpec = TileMap.FromFile("ReactorEntrance.txt");
90        levelSpec['='] = createVerticalBlock;
91        levelSpec['|'] = createHorizontalBlock;
92        levelSpec['P'] = addPlayer;
93        levelSpec['a'] = addMeleeAlien;
[2355]94        levelSpec.Insert(SCREEN_WIDTH, SCREEN_HEIGHT);
[2245]95        Level.CreateBorders();
[2295]96        Level.Background.Image = background1;
[2187]97    }
98
[2231]99    Player addPlayer()
[2227]100    {
[2252]101        player = new Player(33, 74, Shape.Rectangle);
[2231]102        return player;
[2227]103    }
104
[2231]105    MeleeAlien addMeleeAlien()
106    {
[2361]107        MeleeAlien meleeAlien = new MeleeAlien(45, 80, Shape.Rectangle, 50, player);
[2231]108        return meleeAlien;
[2227]109    }
110
[2231]111    PhysicsObject createHorizontalBlock()
112    {
[2355]113        PhysicsObject hBlock = PhysicsObject.CreateStaticObject(SCREEN_WIDTH, SCREEN_HEIGHT,
[2349]114        Shape.Rectangle, CollisionShapeQuality.Best);
[2295]115        hBlock.Color = Color.Gray;
[2231]116        return hBlock;
[2227]117    }
118
[2231]119    PhysicsObject createVerticalBlock()
120    {
[2355]121        PhysicsObject vBlock = PhysicsObject.CreateStaticObject(SCREEN_WIDTH, SCREEN_HEIGHT,
[2349]122        Shape.Rectangle, CollisionShapeQuality.Best);
[2295]123        vBlock.Color = Color.DarkGray;
[2231]124        return vBlock;
[2227]125    }
[2217]126}
Note: See TracBrowser for help on using the repository browser.