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

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

initial bullet collision

RevLine 
[2203]1using System;
2using Jypeli;
3using Jypeli.Assets;
4using Jypeli.Controls;
5using Jypeli.Effects;
6using Jypeli.Widgets;
7
[2205]8public class Player : GenCharacter
[2203]9{
[2286]10    const int speed = 200;
[2300]11    const int jumpSpeed = 500;
[2286]12    const int mass = 10;
[2261]13    Image portrait = Game.LoadImage("Images/character");
[2286]14    SoundEffect walking = Game.LoadSoundEffect("Sounds/walkingsound");
[2245]15
[2286]16    Timer walker;
17
[2203]18        public Player(double width, double height, Shape shape)
19        : base(width, height, shape)
20        {
[2206]21        hitPoints = 100;
[2234]22        AddedToGame += addControls;
[2261]23        this.Image = portrait;
[2286]24
25        walker = new Timer();
[2300]26        walker.Interval = 0.7;
[2286]27        walker.Trigger += playWalkingSound;
28
[2337]29        Pistol pistol = new Pistol(20.0, 10.0);
30        pistol.X = -0.05;
31        pistol.Y = 5;
32        this.Weapon = pistol;
[2338]33
34        //pistol.ProjectileCollision += bulletReachedTarget;
[2206]35        }
[2205]36
[2286]37    private void addControls()
[2206]38    {
[2217]39        Game.Keyboard.Listen(Key.Right, ButtonState.Down, moveRight, "Moves right", speed);
[2219]40        Game.Keyboard.Listen(Key.Left, ButtonState.Down, moveLeft, "Moves left", speed);
41        Game.Keyboard.Listen(Key.Up, ButtonState.Down, jump, "Jumps", jumpSpeed);
[2300]42        Game.Keyboard.Listen(Key.Space, ButtonState.Pressed, shoot, "Shoots");
[2206]43    }
[2209]44
[2300]45    private void shoot()
46    {
[2336]47        PhysicsObject bullet = this.Weapon.Shoot();
48        bullet.Hit(new Vector(1000, 0));
[2338]49
50        // As of now weapons are set to have infinite ammo, but that might change
51        if (bullet != null)
52        { 
53           
54        }
[2300]55    }
56
[2338]57    void bulletReachedTarget(Bullet bullet, MeleeAlien target)
58    { 
59   
60    }
61
[2286]62    private void playWalkingSound(Timer sender)
[2209]63    {
[2286]64        this.walking.Play();
65    }
66
67    private void moveRight(int speed)
68    {
69        walker.Start();
[2234]70        this.Walk(speed);
[2286]71        //this.Image = Image.Mirror(portrait); // Doesn't work at all!
[2209]72    }
[2218]73
[2286]74    private void moveLeft(int speed)
[2218]75    {
[2286]76        walker.Start();
[2218]77        this.Walk(-speed);
[2261]78        this.Image = Image.Mirror(portrait);
[2218]79    }
80
[2219]81    public void jump(int jumpSpeed)
82    {
83        this.Jump(jumpSpeed);
84    }
85
[2203]86}
Note: See TracBrowser for help on using the repository browser.