Changeset 6202 for 2015/26


Ignore:
Timestamp:
2015-06-23 19:26:59 (4 years ago)
Author:
empaheik
Message:
 
Location:
2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun
Files:
1 added
2 edited

Legend:

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

    r6199 r6202  
    3030 
    3131    private double cameraTargetX; // Sijainti jossa kameran pitäisi olla. 
    32     private double cameraOffset = 400; // Tämän voisi ehkä laskea jostain (esim. ikkunan leveydestä kolmasosa tai jotain). 
     32    private Vector cameraTarget; 
     33 
     34    private double cameraOffset = 400; // TODO: Tämän voisi ehkä laskea jostain (esim. ikkunan leveydestä kolmasosa tai jotain). 
    3335    private double cameraSpeed = 2.0; // Kameran liikkumisnopeus. 
    3436 
     
    3739    private Image[] groundTopImages = LoadImages("ground_top"); 
    3840    private Image[] supportStructureImages = LoadImages(""); 
     41    private Image[] foreGroundDecorations = LoadImages("viljaa"); 
    3942 
    4043    private Image[] houseImages = LoadImages("house", "houseburned"); 
     
    138141        Window.Height = 900; 
    139142 
    140         //Camera.X = cameraTargetX = players[0].X; 
    141         Camera.ZoomToLevel(); 
     143        Camera.X = cameraTargetX = players[0].X; 
     144        Camera.Y = cameraTargetY = players[0].Y; 
     145        //Camera.ZoomToLevel(); 
    142146 
    143147        Timer cameraTimer = new Timer(); 
     
    155159        level.SetTileMethod(Color.Black, CreateGroundTop); 
    156160        level.SetTileMethod(Color.Brown, CreateGround); 
     161 
    157162        level.SetTileMethod(Color.Cyan, CreateHouse); 
    158163        level.SetTileMethod(Color.PaintDotNetBlue, CreateBurnedHouse); 
     164 
    159165        level.SetTileMethod(Color.Gold, CreatePlayer); 
    160166        level.SetTileMethod(Color.Rose, CreateDummy, Color.Rose);   //TODO: CreateFlame 
    161167        level.SetTileMethod(Color.Harlequin, CreateCart); 
    162         level.SetTileMethod(Color.White, CreateDummy, Color.White); //TODO: CreateSmoke 
     168        level.SetTileMethod(Color.White, CreateDummy, Color.White); //TODO: CreateSmoke (optional) 
    163169        //level.SetTileMethod(Color.PaintDotNetBlue, CreateDummy, Color.PaintDotNetBlue);  
    164         level.SetTileMethod(Color.DarkGray, CreateDummy, Color.DarkGray);   //TODO: CreateTombStone 
     170        level.SetTileMethod(Color.DarkGray, CreateDummy, Color.DarkGray);   //TODO: CreateTombStone (optional) 
    165171        level.SetTileMethod(Color.Gray, CreateCrawly);   
    166172        level.SetTileMethod(Color.Red, CreateDummy, Color.Red);    //TODO: CreateWitch 
     
    272278        visibleGround.TextureWrapSize = new Vector(width / TILE_SIZE, height / TILE_SIZE); 
    273279        Add(visibleGround, -1); 
     280 
     281        int probability = RandomGen.NextInt(100); 
     282        bool wheat = probability < 20; 
     283 
     284        if(wheat) 
     285        { 
     286            GameObject wheatBlock = new GameObject(width * 1.5, height * 3); 
     287            wheatBlock.Image = foreGroundDecorations[0]; 
     288            wheatBlock.Position = visibleGround.Position; 
     289            Add(wheatBlock, 2); 
     290        } 
    274291    } 
    275292 
     
    300317    void UpdateCamera() 
    301318    { 
     319 
     320        double minY = players.Min(p => p.Y); 
     321        double maxY = players.Max(p => p.Y); 
    302322        double minX = players.Min(p => p.X) + cameraOffset; 
     323 
     324        Vector minPosition = new Vector(Math.Max(minX, cameraTargetX), minY); 
     325        Vector maxPosition = new Vector(minX, maxY); 
     326 
     327        cameraTarget = (minPosition + maxPosition) * 0.5; 
     328        cameraTarget.X = Math.Max(cameraTargetX, minX);     //Lellllll. 
     329 
    303330        cameraTargetX = Math.Max(cameraTargetX, minX); 
     331 
    304332 
    305333        double windowMax = Camera.ScreenToWorld(new Vector(Window.Width / 2.0, 0)).X; 
     
    310338            player.Right = Math.Min(player.Right, windowMax); 
    311339        } 
     340 
     341        //double windowMax = Camera.ScreenToWorld(new Vector(Window.Width / 2.0, 0)).X; 
     342        //double windowMin = Camera.ScreenToWorld(new Vector(-Window.Width / 2.0, 0)).X; 
     343        //foreach (var player in players) 
     344        //{ 
     345        //    player.Left = Math.Max(player.Left, windowMin); 
     346        //    player.Right = Math.Min(player.Right, windowMax); 
     347        //} 
    312348    } 
    313349 
    314350    protected override void Update(Time time) 
    315351    { 
    316         Camera.X += (cameraTargetX - Camera.X) * time.SinceLastUpdate.TotalSeconds * cameraSpeed; 
     352        Camera.Position += (cameraTarget - Camera.Position) * time.SinceLastUpdate.TotalSeconds * cameraSpeed; 
     353        //Camera.X += (cameraTargetX - Camera.X) * time.SinceLastUpdate.TotalSeconds * cameraSpeed; 
     354 
    317355 
    318356        base.Update(time); 
  • 2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRunContent/HillbillyRunContent.contentproj

    r6198 r6202  
    100100    </Compile> 
    101101  </ItemGroup> 
     102  <ItemGroup> 
     103    <Compile Include="viljaa.png"> 
     104      <Name>viljaa</Name> 
     105      <Importer>TextureImporter</Importer> 
     106      <Processor>TextureProcessor</Processor> 
     107    </Compile> 
     108  </ItemGroup> 
    102109  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    103110  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.