Changeset 6148 for 2015


Ignore:
Timestamp:
2015-06-22 21:47:07 (8 years ago)
Author:
sieerinn
Message:

Toisenlainen kameraohjaus ja maa tekstuuri.

Location:
2015/26/ohjaajat/HillbillyRun
Files:
12 added
4 deleted
5 edited

Legend:

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

    • Property svn:ignore set to
      HillbillyRun.v12.suo
  • 2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun

    • Property svn:global-ignores set to
      bin
      obj
    • Property svn:ignore set to
      HillbillyRun.csproj.Debug.cachefile
  • 2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun.cs

    r6147 r6148  
    11using System; 
    22using System.Collections.Generic; 
     3using System.Linq; 
    34using Jypeli; 
    45using Jypeli.Assets; 
     
    89 
    910//Luokka maajussien erikoisuuksille. 
    10 class HillBilly : PlatformCharacter2 
     11class HillBilly : PlatformCharacter 
    1112{ 
    1213    public HillBilly(double leveys, double korkeus) 
     
    2324{ 
    2425    private List<HillBilly> players = new List<HillBilly>(); 
    25     private List<double> playerPositionsX = new List<double>(); 
    26     private List<double> playerPositionsY = new List<double>(); 
     26    //private List<double> playerPositionsX = new List<double>(); 
     27    //private List<double> playerPositionsY = new List<double>(); 
     28 
     29    private const double TILE_SIZE = 70; 
     30 
     31    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). 
     33    private double cameraSpeed = 2.0; // Kameran liikkumisnopeus. 
     34 
     35    private Image groundImage = LoadImage("ground"); 
    2736 
    2837    public override void Begin() 
     
    3039        CreateLevel(); 
    3140        Extras(); 
     41 
     42        Camera.X = cameraTargetX = players[0].X; 
    3243    } 
    3344 
     
    4354        TileMap level = TileMap.FromLevelAsset("level1"); 
    4455        level.SetTileMethod('P', CreatePlayer); 
    45         level.Execute(50, 50); 
    46         level.Optimize(); 
     56        level.SetTileMethod('#', CreateGround); 
     57        level.Optimize('#'); 
     58        level.Execute(TILE_SIZE, TILE_SIZE); 
    4759        Level.CreateBorders(true); 
    4860 
     
    5062    } 
    5163 
    52     void CreatePlayer(Vector location, double width, double height) 
     64    void CreatePlayer(Vector position, double width, double height) 
    5365    { 
    5466        HillBilly player = new HillBilly(width, height * 2); 
    5567        player.Shape = Shape.Rectangle; 
    56         player.Position = location + new Vector(0, height * 0.5); 
     68        player.Position = position + new Vector(0, height * 0.5); 
    5769        player.Color = Color.White; 
    5870        players.Add(player); 
     
    6072    } 
    6173 
     74    void CreateGround(Vector position, double width, double height) 
     75    { 
     76        PhysicsObject ground = PhysicsObject.CreateStaticObject(width, height); 
     77        ground.Image = groundImage; 
     78        ground.Position = position; 
     79        ground.TextureWrapSize = new Vector(width / TILE_SIZE, height / TILE_SIZE); 
     80        Add(ground); 
     81    } 
     82 
    6283    void SetControls() 
    6384    { 
    64         Keyboard.Listen(Key.A, ButtonState.Down, delegate { players[0].Walk(Direction.Left); }, "Player 1 moves left"); 
    65         Keyboard.Listen(Key.D, ButtonState.Down, delegate {players[0].Walk(Direction.Right);}, "Player 1 moves right"); 
    66         Keyboard.Listen(Key.W, ButtonState.Down, delegate{players[0].Jump(1000);}, "Player 1 jumps"); 
     85        Keyboard.Listen(Key.A, ButtonState.Down, delegate { players[0].Walk(-300); }, "Player 1 moves left"); 
     86        Keyboard.Listen(Key.D, ButtonState.Down, delegate { players[0].Walk(300); }, "Player 1 moves right"); 
     87        Keyboard.Listen(Key.W, ButtonState.Down, delegate { players[0].Jump(1000); }, "Player 1 jumps"); 
    6788 
    68         Keyboard.Listen(Key.Left, ButtonState.Down, delegate { players[1].Walk(Direction.Left); }, "Player 2 moves left"); 
    69         Keyboard.Listen(Key.Right, ButtonState.Down, delegate { players[1].Walk(Direction.Right); }, "Player 2 moves right"); 
     89        Keyboard.Listen(Key.Left, ButtonState.Down, delegate { players[1].Walk(-300); }, "Player 2 moves left"); 
     90        Keyboard.Listen(Key.Right, ButtonState.Down, delegate { players[1].Walk(300); }, "Player 2 moves right"); 
    7091        Keyboard.Listen(Key.Up, ButtonState.Down, delegate { players[1].Jump(1000); }, "Player 2 jumps"); 
     92 
     93        //Keyboard.Listen(Key.A, ButtonState.Down, delegate { players[0].Walk(Direction.Left); }, "Player 1 moves left"); 
     94        //Keyboard.Listen(Key.D, ButtonState.Down, delegate {players[0].Walk(Direction.Right);}, "Player 1 moves right"); 
     95        //Keyboard.Listen(Key.W, ButtonState.Down, delegate{players[0].Jump(1000);}, "Player 1 jumps"); 
     96 
     97        //Keyboard.Listen(Key.Left, ButtonState.Down, delegate { players[1].Walk(Direction.Left); }, "Player 2 moves left"); 
     98        //Keyboard.Listen(Key.Right, ButtonState.Down, delegate { players[1].Walk(Direction.Right); }, "Player 2 moves right"); 
     99        //Keyboard.Listen(Key.Up, ButtonState.Down, delegate { players[1].Jump(1000); }, "Player 2 jumps"); 
    71100    } 
    72101 
     102    protected override void Update(Time time) 
     103    { 
     104        double minX = players.Min(p => p.X) + cameraOffset; 
     105        cameraTargetX = Math.Max(cameraTargetX, minX); 
     106        Camera.X += (cameraTargetX - Camera.X) * time.SinceLastUpdate.TotalSeconds * cameraSpeed; 
     107 
     108        double windowMax = Camera.ScreenToWorld(new Vector(Window.Width / 2.0, 0)).X; 
     109        double windowMin = Camera.ScreenToWorld(new Vector(-Window.Width / 2.0, 0)).X; 
     110        foreach (var player in players) 
     111        { 
     112            player.Left = Math.Max(player.Left, windowMin); 
     113            player.Right = Math.Min(player.Right, windowMax); 
     114        } 
     115 
     116        base.Update(time); 
     117    } 
    73118 
    74119    /// <summary> 
     
    76121    /// </summary> 
    77122    /// <param name="gameTime"></param> 
     123    /* 
    78124    protected override void Update(Microsoft.Xna.Framework.GameTime gameTime) 
    79125    { 
     
    99145        base.Update(gameTime); 
    100146    } 
     147     */ 
    101148} 
  • 2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRunContent

    • Property svn:global-ignores set to
      bin
      obj
  • 2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRunContent/HillbillyRunContent.contentproj

    r6147 r6148  
    5353    </Compile> 
    5454  </ItemGroup> 
     55  <ItemGroup> 
     56    <Compile Include="ground.png"> 
     57      <Name>ground</Name> 
     58      <Importer>TextureImporter</Importer> 
     59      <Processor>TextureProcessor</Processor> 
     60    </Compile> 
     61  </ItemGroup> 
    5562  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    5663  <!--  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.