Changeset 6237
- Timestamp:
- 2015-06-24 12:01:09 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/30/MitjaK/Attack to Agora/Attack to Agora/Attack to Agora/Attack to Agora/Attack_to_Agora.cs
r6192 r6237 9 9 public class Attack_to_Agora : PhysicsGame 10 10 { 11 private Animation chuckinkavely; 11 12 12 private Animation chuckinkavely; 13 double nopeus = 200; 14 double hyppyvoima = 1000; 13 /// <summary> 14 /// Vakiot kannattaa merkitä constiksi (ei voi muuttaa). Tällöin ne kirjoitetaan isolla. 15 /// </summary> 16 const double NOPEUS = 250; 17 const double HYPPYVOIMA = 1500; 15 18 16 //Image level1 = LoadImage("Agora_paaovi_pixelate");17 19 Image level1 = LoadImage("kentta1"); 18 20 Image taistelijanvarjo = LoadImage("varjo"); 19 20 Image taistelija olio = LoadImage("olio");21 22 Image taistelijaOlio = LoadImage("olio"); 21 23 PlatformCharacter taistelija; 22 23 int kentta nro = 4;24 // int Kenttanro = -1; 24 25 int kenttaNro = 5; 26 25 27 public override void Begin() 26 27 28 28 { 29 LataaContent(); 30 LuoKentta(); 31 AsetaOhjaimet(); 32 } 29 33 30 Luokentta(); 31 32 33 34 } 35 36 37 void Liikuta(PlatformCharacter pelaaja, double suunta) 34 void Liikuta(PlatformCharacter pelaaja, double suunta) 38 35 { 39 36 pelaaja.Walk(suunta); 40 37 41 38 if (!pelaaja.Animation.IsPlaying) 42 43 39 pelaaja.Animation.Resume(); 44 } 45 46 47 48 40 } 49 41 50 42 void LiikutaYlos(PlatformCharacter pelaaja) 51 43 { 52 pelaaja.Jump(hyppyvoima); 53 54 44 pelaaja.Jump(HYPPYVOIMA); 55 45 } 56 46 57 void L uokentta()47 void LataaContent() 58 48 { 59 49 chuckinkavely = LoadAnimation("pelaajaliikkuu"); 50 } 51 52 void LuoKentta() 53 { 60 54 SmoothTextures = false; 61 62 ColorTileMap pohjaLevy = ColorTileMap.FromLevelAsset("kentta4pohja"); 63 pohjaLevy.SetTileMethod(Color.Gold, Luopohja); 64 pohjaLevy.SetTileMethod(Color.Cyan, Luotaistelija); 65 pohjaLevy.Execute(1, 1); 66 67 68 69 Level.Background.Image = LoadImage("kentta"+kenttanro); 70 //Level.Background.Image = level1; 71 //Level.Background.Color = Color.Black; 72 //Level.Width = 2000; 73 //Level.Height = 1200; 74 Level.Background.FitToLevel(); 55 // IsFullScreen = true; 75 56 Gravity = new Vector(0, -2500); 76 57 77 // PhysicsObject pohja = Level.CreateBottomBorder(); 78 // pohja.Y = Level.Bottom + 100; 58 SetWindowSize(1920, 1080); 59 // Synkataan taustakuvan ja colortilemapin pikselit 60 Level.Background.Image = LoadImage("kentta" + kenttaNro.ToString()); 61 62 Level.Width = Screen.Width; 63 double kerroin = (double)Level.Background.Image.Width / Level.Background.Image.Height; 64 Level.Height = Level.Width / kerroin; 65 Level.Background.FitToLevel(); 66 67 Image pohjaLevynKuva = LoadImage("kentta" + kenttaNro.ToString() + "pohja"); 68 69 ColorTileMap pohjaLevy = new ColorTileMap(pohjaLevynKuva); 70 pohjaLevy.SetTileMethod(Color.Gold, LuoPohja); 71 pohjaLevy.SetTileMethod(Color.Cyan, Luotaistelija); 72 pohjaLevy.Optimize(Color.Gold); 73 74 // oletuksena 1 pikseli = 1 unit 75 const double BASE_SIZE = 1.0; 76 double widthMultiplier = Level.Width / pohjaLevynKuva.Width; 77 double heightMultiplier = Level.Height / pohjaLevynKuva.Height; 78 pohjaLevy.Execute(BASE_SIZE * widthMultiplier, BASE_SIZE * heightMultiplier); 79 80 // PhysicsObject pohja = Level.CreateBottomBorder(); 81 // pohja.Y = Level.Bottom + 100; 79 82 //pohja.IsVisible = false; 80 83 PhysicsObject vasenreuna = Level.CreateLeftBorder(); … … 85 88 //oikeareuna.Tag = "oikeareuna"; 86 89 87 88 89 //Varjo(pohja); 90 91 IsFullScreen = true; 92 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 93 94 95 96 90 Varjo(); 97 91 } 98 92 … … 100 94 { 101 95 102 taistelija = new PlatformCharacter( 15, 15);103 taistelija.Shape = Shape. Circle;96 taistelija = new PlatformCharacter(75, 75); 97 taistelija.Shape = Shape.Rectangle; 104 98 taistelija.Animation = new Animation(chuckinkavely); 105 99 taistelija.Animation.Start(); 106 100 taistelija.Position = paikka; 107 101 108 Keyboard.Listen(Key.A, ButtonState.Down, Liikuta, null, taistelija, -nopeus); 109 Keyboard.Listen(Key.D, ButtonState.Down, Liikuta, null, taistelija, nopeus); 110 Keyboard.Listen(Key.Space, ButtonState.Pressed, LiikutaYlos, null, taistelija); 111 AddCollisionHandler(taistelija, "vasenreuna",Seuraavakentta); 102 AddCollisionHandler(taistelija, "vasenreuna", SeuraavaKentta); 112 103 113 104 taistelija.Mass = 10.0; … … 116 107 Camera.StayInLevel = true; 117 108 } 118 void Varjo(PhysicsObject pohja) 109 110 void Varjo() 119 111 { 120 112 GameObject varjo = new GameObject(70, 30); 121 113 varjo.Image = taistelijanvarjo; 122 varjo.Y = pohja.Top;123 114 Add(varjo, -1); 115 124 116 Timer ajastin = new Timer(); 125 117 ajastin.Interval = 0.01; … … 127 119 { 128 120 varjo.X = taistelija.X; 121 varjo.Y = EtsiVarjonY(); 129 122 }; 130 123 ajastin.Start(); 131 124 } 132 125 133 void Seuraavakentta(PhysicsObject tormaaja, PhysicsObject tormatty) 126 /// <summary> 127 /// Etsii pelaajaa lähimpänä pelaajan alla olevan lattiapalikan huipun Y-koordinaatin. 128 /// </summary> 129 /// <returns></returns> 130 double EtsiVarjonY() 131 { 132 List<GameObject> possibleFloorPieces = GetObjects(x => x.Left < taistelija.X && x.Right > taistelija.X); 133 134 double highestY = double.MinValue; 135 int highestIndex = -1; 136 137 for (int i = 0; i < possibleFloorPieces.Count; i++) 138 { 139 double currentY = possibleFloorPieces[i].Y; 140 141 if (currentY > highestY && currentY < taistelija.Bottom) 142 { 143 highestY = currentY; 144 highestIndex = i; 145 } 146 } 147 148 return possibleFloorPieces[highestIndex].Top; 149 } 150 151 void SeuraavaKentta(PhysicsObject tormaaja, PhysicsObject tormatty) 134 152 { 135 153 ClearAll(); 136 kenttanro++; 137 //Kenttanro--; 138 Luokentta(); 154 kenttaNro++; 155 LuoKentta(); 139 156 } 140 157 141 void Luo pohja(Vector paikka, double leveys, double korkeus)158 void LuoPohja(Vector paikka, double leveys, double korkeus) 142 159 { 143 160 PhysicsObject pala = PhysicsObject.CreateStaticObject(leveys, korkeus); 144 161 pala.Position = paikka; 145 pala. Color = Color.Transparent;162 pala.IsVisible = false; 146 163 Add(pala); 147 164 } 148 165 166 /// <summary> 167 /// Asetetaan pelaajalle ohjaimet. 168 /// </summary> 169 void AsetaOhjaimet() 170 { 171 Keyboard.Listen(Key.A, ButtonState.Down, Liikuta, null, taistelija, -NOPEUS); 172 Keyboard.Listen(Key.D, ButtonState.Down, Liikuta, null, taistelija, NOPEUS); 173 Keyboard.Listen(Key.Space, ButtonState.Pressed, LiikutaYlos, null, taistelija); 174 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 175 } 149 176 }
Note: See TracChangeset
for help on using the changeset viewer.