- Timestamp:
- 2015-06-22 21:47:07 (8 years ago)
- 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
-
Property
svn:ignore
set to
-
2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun
-
Property
svn:global-ignores
set to
bin
obj
-
Property
svn:ignore
set to
HillbillyRun.csproj.Debug.cachefile
-
Property
svn:global-ignores
set to
-
2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRun.cs
r6147 r6148 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq; 3 4 using Jypeli; 4 5 using Jypeli.Assets; … … 8 9 9 10 //Luokka maajussien erikoisuuksille. 10 class HillBilly : PlatformCharacter 211 class HillBilly : PlatformCharacter 11 12 { 12 13 public HillBilly(double leveys, double korkeus) … … 23 24 { 24 25 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"); 27 36 28 37 public override void Begin() … … 30 39 CreateLevel(); 31 40 Extras(); 41 42 Camera.X = cameraTargetX = players[0].X; 32 43 } 33 44 … … 43 54 TileMap level = TileMap.FromLevelAsset("level1"); 44 55 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); 47 59 Level.CreateBorders(true); 48 60 … … 50 62 } 51 63 52 void CreatePlayer(Vector location, double width, double height)64 void CreatePlayer(Vector position, double width, double height) 53 65 { 54 66 HillBilly player = new HillBilly(width, height * 2); 55 67 player.Shape = Shape.Rectangle; 56 player.Position = location + new Vector(0, height * 0.5);68 player.Position = position + new Vector(0, height * 0.5); 57 69 player.Color = Color.White; 58 70 players.Add(player); … … 60 72 } 61 73 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 62 83 void SetControls() 63 84 { 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"); 67 88 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"); 70 91 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"); 71 100 } 72 101 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 } 73 118 74 119 /// <summary> … … 76 121 /// </summary> 77 122 /// <param name="gameTime"></param> 123 /* 78 124 protected override void Update(Microsoft.Xna.Framework.GameTime gameTime) 79 125 { … … 99 145 base.Update(gameTime); 100 146 } 147 */ 101 148 } -
2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRunContent
-
Property
svn:global-ignores
set to
bin
obj
-
Property
svn:global-ignores
set to
-
2015/26/ohjaajat/HillbillyRun/HillbillyRun/HillbillyRun/HillbillyRunContent/HillbillyRunContent.contentproj
r6147 r6148 53 53 </Compile> 54 54 </ItemGroup> 55 <ItemGroup> 56 <Compile Include="ground.png"> 57 <Name>ground</Name> 58 <Importer>TextureImporter</Importer> 59 <Processor>TextureProcessor</Processor> 60 </Compile> 61 </ItemGroup> 55 62 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 56 63 <!-- 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.