Changeset 7203


Ignore:
Timestamp:
2016-06-08 09:01:44 (3 years ago)
Author:
jotapoti
Message:

ampuminen värjää kenttää & peli ei kaadu, jos yrittää ampua ilman asetta

Location:
2016/23/ohjaajat/Punasininen/Punasininen
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 2016/23/ohjaajat/Punasininen/Punasininen/Punasininen/Player.cs

    r7189 r7203  
    99public class Player : PlatformCharacter2 
    1010{ 
     11 
     12    Weapon Secondary; 
     13 
    1114    public Player(double leveys, double korkeus, Image pic, Color color) 
    1215        : base(leveys, korkeus) 
  • 2016/23/ohjaajat/Punasininen/Punasininen/Punasininen/Punasininen.cs

    r7199 r7203  
    1515    private Player blue; 
    1616    private Player red;  
    17  
    1817    private Image bluepic; 
    1918    private Image redpic; 
     19 
     20    private Image pistolpic; 
     21 
    2022    DoubleMeter percentageTracker; 
    2123 
     
    3840        ColorTileMap map = ColorTileMap.FromLevelAsset("dungeon1"); 
    3941        map.SetTileMethod(Color.Black, LisaaTaso); 
    40         map.SetTileMethod(Color.FromHexCode("#FF0026FF"), delegate(Vector paikka, double leveys, double korkeus) { blue = CreatePlayer(paikka, leveys, korkeus, bluepic, Color.Blue, new Vector(-Screen.Width / 2 + 50, Screen.Height / 2 - 50)); }); 
     42        map.SetTileMethod(Color.FromHexCode("#FF0026FF"), delegate(Vector paikka, double leveys, double korkeus) { blue = CreatePlayer(paikka, leveys, korkeus, bluepic, Color.Blue);}); 
    4143        map.SetTileMethod(Color.FromHexCode("FFD800"), CreateWeaponCrate); 
    42         map.SetTileMethod(Color.Red, delegate(Vector paikka, double leveys, double korkeus) { red = CreatePlayer(paikka, leveys, korkeus, redpic, Color.Red, new Vector(Screen.Width / 2 - 50, Screen.Height / 2 - 50)); }); 
     44        map.SetTileMethod(Color.Red, delegate(Vector paikka, double leveys, double korkeus) { red = CreatePlayer(paikka, leveys, korkeus, redpic, Color.Red); }); 
    4345        map.Execute(TILE_SIZE, TILE_SIZE); 
    4446 
     
    5759    void CreateWeaponCrate(Vector place, double width, double height) 
    5860    { 
    59         PhysicsObject crate = PhysicsObject.CreateStaticObject(width, height); 
     61        WeaponCrate crate = new WeaponCrate(width, height); 
    6062        crate.Position = place; 
     63        crate.Color = Color.DarkGray; 
    6164        Add(crate); 
    6265    } 
     
    7174    } 
    7275 
    73     Player CreatePlayer(Vector paikka, double leveys, double korkeus, Image playerspic, Color playersColor, Vector trackerPosition) 
     76    Player CreatePlayer(Vector paikka, double leveys, double korkeus, Image playerspic, Color playersColor) 
    7477    { 
    7578        Player player = new Player(leveys, korkeus, playerspic, playersColor); 
     
    7982        AddCollisionHandler(player, "platform", delegate(PhysicsObject a, PhysicsObject b) 
    8083        { 
    81             ColorTile(a, b, percentageTracker); 
     84            ColorTile(a, b); 
    8285        }); 
     86        AddCollisionHandler(player, "crate", delegate(PhysicsObject a, PhysicsObject b) 
     87        { 
     88            //((Player)a).Weapon = ((WeaponCrate)b).GiveWeapon(); 
     89            ((Player)a).Weapon = GunLottery(); 
     90            ((Player)a).Weapon.ProjectileCollision = BulletHitsSomething; 
     91            b.Destroy(); 
     92        }); 
    8393 
    8494        return player; 
    8595    } 
    8696 
     97    void BulletHitsSomething (PhysicsObject bullet, PhysicsObject target) 
     98    { 
     99        if (target.Tag == "platform") 
     100        { 
     101            // TODO bullet must know its owner 
     102            if (bullet.Color == Color.Blue) 
     103            { 
     104                ColorTile(blue, target); 
     105            } 
     106            else if (bullet.Color == Color.Red) 
     107            { 
     108                ColorTile(red, target); 
     109            } 
     110        } 
     111        bullet.Destroy(); 
     112    } 
     113 
     114    Weapon GunLottery() 
     115    { 
     116        return new AssaultRifle(50, 50); 
     117    } 
     118 
    87119    void Win(Player player) 
    88120    { 
    89         Pause(); 
     121       Pause(); 
    90122        //Haluaisin tehdä tähän jonkinlaisen hauskan ponnahdusefektin jossain vaiheessa. Sellaisen napakan zoomin ja sitten boing. Hurdur. 
    91123       Camera.ZoomTo(player.Left, player.Bottom, player.Right, player.Top + 100); 
     
    102134    } 
    103135 
    104     void ColorTile(PhysicsObject player, PhysicsObject platform, DoubleMeter tracker) 
     136    void ColorTile(PhysicsObject player, PhysicsObject platform) 
    105137    { 
    106138        platform.Color = player.Color; 
    107139 
    108140        List<GameObject> colored = GetObjects(o => (o.Color == red.Color || o.Color == blue.Color) && (String)o.Tag == "platform"); 
    109         tracker.Value = (double)colored.FindAll(o => o.Color == red.Color).Count/colored.Count * 100; 
     141        percentageTracker.Value = (double)colored.FindAll(o => o.Color == red.Color).Count/colored.Count * 100; 
    110142    } 
    111143 
     
    117149        ControllerOne.Listen(Button.A, ButtonState.Pressed, Jump, "Pelaaja hyppää", red, JUMPSPEED); 
    118150        ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.1, Aim, "Tähtää", red); 
     151        ControllerOne.ListenAnalog(AnalogControl.RightTrigger, 0.1, Shoot, "", red); 
    119152 
    120153        ControllerTwo.ListenAnalog(AnalogControl.LeftStick, 0.1, Move, "Liikuta pelaajaa", blue); 
    121154        ControllerTwo.Listen(Button.A, ButtonState.Pressed, Jump, "Pelaaja hyppää", blue, JUMPSPEED); 
    122155        ControllerOne.ListenAnalog(AnalogControl.RightStick, 0.1, Aim, null, blue); 
     156        ControllerTwo.ListenAnalog(AnalogControl.RightTrigger, 0.1, Shoot, "", blue); 
    123157 
    124158        Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Ohjeet"); 
     
    132166        if (stick.StateVector.Magnitude > 0.15) 
    133167            player.Walk(stick.StateVector.X > 0 ? Direction.Right : Direction.Left); 
     168    } 
     169 
     170    void Shoot(AnalogState trigger, Player player) 
     171    { 
     172        if (player.Weapon != null) 
     173        { 
     174            PhysicsObject bullet = player.Weapon.Shoot(); 
     175            if (bullet != null) 
     176            { 
     177                bullet.Color = player.Color;   
     178            } 
     179        } 
    134180    } 
    135181 
  • 2016/23/ohjaajat/Punasininen/Punasininen/Punasininen/WeaponCrate.cs

    r7196 r7203  
    99class WeaponCrate : PhysicsObject 
    1010{ 
    11     Weapon WeaponInside; 
    1211 
    13     public WeaponCrate(double leveys, double korkeus, Weapon weaponInside, Image pic, Color color) 
     12    public WeaponCrate(double leveys, double korkeus) 
    1413        : base(leveys, korkeus) 
    1514    { 
    16         this.WeaponInside = weaponInside; 
    17         this.Color = color; 
    18         this.Image = pic; 
     15        Tag = "crate"; 
    1916    } 
    2017 
     18    /* 
    2119    public Weapon GiveWeapon() 
    2220    { 
    2321        this.Destroy(); 
    24         return WeaponInside; 
    25     } 
     22    }*/ 
    2623} 
Note: See TracChangeset for help on using the changeset viewer.