Ignore:
Timestamp:
2015-06-23 23:27:22 (4 years ago)
Author:
sieerinn
Message:

Putoamis- ja hyppyanimaatio.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun.cs

    r6217 r6218  
    2929{ 
    3030    private IntMeter lifeCounter = new IntMeter(2, 0, 2); 
    31     public IntMeter Life  
     31    public IntMeter Life 
    3232    { 
    3333        set { lifeCounter = value; } 
    34         get { return lifeCounter; }  
     34        get { return lifeCounter; } 
    3535    } 
    3636 
     
    4040        : base(leveys, korkeus) 
    4141    { 
    42          
     42 
    4343    } 
    4444} 
     
    5555    //private List<double> playerPositionsY = new List<double>(); 
    5656 
     57    private const double PLAYER_SPEED = 180; 
    5758    private const double TILE_SIZE = 70; 
    5859 
     
    6768    private Image[] groundTopImages = LoadImages("ground_top"); 
    6869    private Image[] foregroundDecorations = LoadImages("viljaa"); 
    69     private Image[] blockImages = LoadImages("box"); 
     70    private Image[] blockImages = LoadImages("box2"); 
    7071 
    7172    private Image[] houseImages = LoadImages("house", "houseburned"); 
     
    7374    private Image cartImage = LoadImage("cart"); 
    7475    private Image milkImage = LoadImage("tonkkaitem"); 
    75      
     76 
    7677    private Image cartWheelImage = LoadImage("cartwheel"); 
    7778 
     
    9091    private Animation normalWalk; 
    9192    private Animation playerIdle; 
    92     #endregion  
     93    private Animation playerJump; 
     94    private Animation playerFall; 
     95    #endregion 
    9396 
    9497    private double leftCamLimit; 
     
    97100 
    98101    private int levelNumber = 0; 
    99     
     102 
    100103    public override void Begin() 
    101104    { 
     
    111114 
    112115        Keyboard.Listen(Key.Escape, ButtonState.Pressed, SkipIntro, "Skip"); 
    113          
     116 
    114117        ShowMadeWithJypeli(); 
    115118 
     
    118121            ShowBackgroundStory(); 
    119122        }); 
    120          
     123 
    121124 
    122125 
     
    126129    { 
    127130        Image madewithImage = LoadImage("madewithjypeli"); 
    128          
     131 
    129132        double w = Window.Width / 4; 
    130133        double h = w * (madewithImage.Height / (double)madewithImage.Width); // take aspect ratio from the picture 
    131          
     134 
    132135        GameObject madewithjypeliObject = new GameObject(w, h); 
    133136        madewithjypeliObject.Image = madewithImage; 
     
    143146        //}; 
    144147        //fadeTimer.Start(5); 
    145          
     148 
    146149        Timer.SingleShot(1.2, delegate 
    147150        { 
     
    266269        normalWalk = LoadAnimation("pwalk"); 
    267270        playerIdle = LoadAnimation("idle"); 
     271        playerJump = LoadAnimation("jump"); 
     272        playerFall = LoadAnimation("fall"); 
    268273    } 
    269274 
     
    301306        level.SetTileMethod(Color.Gold, CreatePlayer); 
    302307        level.SetTileMethod(Color.Harlequin, CreateCart); 
    303         level.SetTileMethod(Color.White, CreateBlockObject);  
    304         level.SetTileMethod(Color.DarkGray, CreateMilk);    
     308        level.SetTileMethod(Color.White, CreateBlockObject); 
     309        level.SetTileMethod(Color.DarkGray, CreateMilk); 
    305310        level.SetTileMethod(Color.Gray, CreateCrawly); 
    306311        level.SetTileMethod(Color.Red, CreateDummy, Color.Red);    //TODO: CreateWitch 
    307         level.SetTileMethod(Color.Rose, CreateFlame);    
     312        level.SetTileMethod(Color.Rose, CreateFlame); 
    308313        //level.SetTileMethod(Color.Azure, CreateDummy, Color.Azure);   //TODO: CreateSmoke 
    309314        //level.SetTileMethod(Color.Orange, CreateDummy, Color.Orange); //TODO: CreateTombstone 
    310315        level.Optimize(Color.Black, Color.Brown); 
    311316        level.Execute(TILE_SIZE, TILE_SIZE); 
    312          
     317 
    313318 
    314319        //TileMap level = TileMap.FromLevelAsset("level" + levelNumber); 
     
    350355    void CreateBlockObject(Vector position, double width, double height) 
    351356    { 
     357        // Säädin vähän tätä jotta laatikko näkyy hyvin. Pitää ehkä tehdä laatikolle ihan oma metodi. 
     358 
    352359        PhysicsObject block = PhysicsObject.CreateStaticObject(width, height); 
    353         block.Image = blockImages[levelNumber]; 
     360        block.IsVisible = false; 
     361        //block.Image = blockImages[levelNumber]; 
    354362        block.Position = position; 
    355         Add(block); 
     363        block.Y -= height / 2.0; 
     364        Add(block, 1); 
     365 
     366        GameObject visibleBlock = new GameObject(width, height * 1.5); 
     367        visibleBlock.Position = position; 
     368        visibleBlock.Image = blockImages[levelNumber]; 
     369        visibleBlock.Y -= height / 2.0; 
     370        Add(visibleBlock, -1); 
    356371    } 
    357372 
    358373    void CreateMilk(Vector position, double width, double height) 
    359374    { 
    360         GameObject milk = new GameObject(milkImage.Width, milkImage.Height); 
     375        double size = 30; 
     376        double ratio = milkImage.Height / milkImage.Width; 
     377        PhysicsObject milk = new PhysicsObject(size, size * ratio); 
    361378        milk.Image = milkImage; 
    362379        milk.Position = position; 
     
    405422        Add(house, -2); 
    406423 
    407         PhysicsObject platform = PhysicsObject.CreateStaticObject(house.Width* 0.25, 1); 
     424        PhysicsObject platform = PhysicsObject.CreateStaticObject(house.Width * 0.25, 1); 
    408425        platform.IsVisible = false; 
    409426        platform.Position = new Vector(house.X + platform.Width * 0.5, house.Top); 
     
    445462        player.AnimWalk = new Animation(normalWalk); 
    446463        player.AnimIdle = new Animation(playerIdle); 
     464        player.AnimJump = new Animation(playerJump); 
     465        player.AnimFall = new Animation(playerFall); 
     466        player.AnimFall.StopOnLastFrame = true; 
    447467        players.Add(player); 
    448468        startingPlayers.Add(player); 
    449469        Add(player); 
    450         AddCollisionHandler(player, "burn", delegate(PhysicsObject p, PhysicsObject t)  
     470        AddCollisionHandler(player, "burn", delegate(PhysicsObject p, PhysicsObject t) 
    451471        { 
    452472            HillBilly billy = p as HillBilly; 
     
    455475        }); 
    456476 
    457         player.Life.LowerLimit += delegate  
    458         {  
     477        player.Life.LowerLimit += delegate 
     478        { 
    459479            if (players.Count < 2) 
    460480            { 
     
    463483            players.Remove(player); player.Destroy(); 
    464484        }; 
     485 
     486        AddCollisionHandler(player, "milk", CollectMilk); 
    465487    } 
    466488 
     
    494516    } 
    495517 
    496     void CreateGround(Vector position, double width, double height)  
     518    void CreateGround(Vector position, double width, double height) 
    497519    { 
    498520        PhysicsObject ground = PhysicsObject.CreateStaticObject(width, height); 
     
    506528    void SetControls() 
    507529    { 
    508         double speed = 180; // TODO: Siirrä tämä johonkin. 
    509         Keyboard.Listen(Key.A, ButtonState.Down, delegate { startingPlayers[0].Walk(-speed); }, "Player 1 moves left"); 
    510         Keyboard.Listen(Key.D, ButtonState.Down, delegate { startingPlayers[0].Walk(speed); }, "Player 1 moves right"); 
     530        Keyboard.Listen(Key.A, ButtonState.Down, delegate { startingPlayers[0].Walk(-PLAYER_SPEED); }, "Player 1 moves left"); 
     531        Keyboard.Listen(Key.D, ButtonState.Down, delegate { startingPlayers[0].Walk(PLAYER_SPEED); }, "Player 1 moves right"); 
    511532        Keyboard.Listen(Key.W, ButtonState.Down, delegate { startingPlayers[0].Jump(1000); }, "Player 1 jumps"); 
    512533 
    513         Keyboard.Listen(Key.Left, ButtonState.Down, delegate { startingPlayers[1].Walk(-speed); }, "Player 2 moves left"); 
    514         Keyboard.Listen(Key.Right, ButtonState.Down, delegate { startingPlayers[1].Walk(speed); }, "Player 2 moves right"); 
     534        Keyboard.Listen(Key.Left, ButtonState.Down, delegate { startingPlayers[1].Walk(-PLAYER_SPEED); }, "Player 2 moves left"); 
     535        Keyboard.Listen(Key.Right, ButtonState.Down, delegate { startingPlayers[1].Walk(PLAYER_SPEED); }, "Player 2 moves right"); 
    515536        Keyboard.Listen(Key.Up, ButtonState.Down, delegate { startingPlayers[1].Jump(1000); }, "Player 2 jumps"); 
    516537 
     
    523544        //TODO: Sumthin' flashy for our fallen friends. 
    524545        Exit(); 
     546    } 
     547 
     548    void CollectMilk(PhysicsObject player, PhysicsObject milk) 
     549    { 
     550        HillBilly billy = player as HillBilly; 
     551        if (billy == null) 
     552            return; 
     553 
     554        milk.Destroy(); 
     555        billy.AnimWalk = new Animation(milkWalk); 
     556        billy.AnimIdle = new Animation(milkWalk.CurrentFrame); 
    525557    } 
    526558 
Note: See TracChangeset for help on using the changeset viewer.