- Timestamp:
- 2015-06-12 15:04:11 (8 years ago)
- Location:
- 2015/24/VeetiI/LABYRINTTI/LABYRINTTI
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/24/VeetiI/LABYRINTTI/LABYRINTTI/LABYRINTTI/LABYRINTTI.cs
r5961 r6080 9 9 public class LABYRINTTI : PhysicsGame 10 10 { 11 Image olionKuva = LoadImage("hirviötekstuuri"); 12 11 PhysicsObject pelaaja1; 12 GameObject taskulamppu; 13 Image olionKuva = LoadImage("labyrinttipelihahmo2015"); 14 Image HirvionKuva = LoadImage("hirviötekstuuri"); 15 Image aarteenKuva = LoadImage("aarrelabyrintti2015"); 16 Image jumpscareKuva = LoadImage("3688"); 17 SoundEffect jumpscareAani = LoadSoundEffect("räjähdys"); 18 19 const int RUUDUN_KOKO = 40; 13 20 const double RUUDUN_LEVEYS = 50.0; 14 21 const double RUUDUN_KORKEUS = 50.0; … … 16 23 public override void Begin() 17 24 { 25 Mouse.IsCursorVisible = true; 26 Level.Background.Color = Color.DarkGray; 27 Level.Background.FitToLevel(); 28 Timer ajastin = new Timer(); 29 ajastin.Interval = 300.0; 30 ajastin.Timeout += AloitaAlusta; 31 ajastin.Start(10000000); 32 MediaPlayer.IsRepeating = true; 33 MediaPlayer.Play("pelimusiikki"); 34 35 36 LuoPistelaskuri(); 18 37 //PhysicsObject mob = new PhysicsObject(500,400); 19 38 //Add(mob); … … 21 40 // TODO: Kirjoita ohjelmakoodisi tähän 22 41 23 24 Level.Background.Color = Color.Maroon; 25 26 42 LuoKentta(); 43 44 AsetaOjaimet(); 45 } 46 47 void AsetaOjaimet() 48 { 27 49 Keyboard.Listen(Key.D, ButtonState.Down, 28 LiikutaPelaajaa, null, new Vector(1000, 0));50 LiikutaPelaajaa, null, new Vector(6000, 0)); 29 51 Keyboard.Listen(Key.A, ButtonState.Down, 30 LiikutaPelaajaa, null, new Vector(- 1000, 0));52 LiikutaPelaajaa, null, new Vector(-6000, 0)); 31 53 Keyboard.Listen(Key.W, ButtonState.Down, 32 LiikutaPelaajaa, null, new Vector(0, 1000));54 LiikutaPelaajaa, null, new Vector(0, 6000)); 33 55 Keyboard.Listen(Key.S, ButtonState.Down, 34 LiikutaPelaajaa, null, new Vector(0, -1000)); 35 56 LiikutaPelaajaa, null, new Vector(0, -6000)); 57 Mouse.IsCursorVisible = true; 58 Vector paikkaRuudulla = Mouse.PositionOnScreen; 59 Vector paikkaKentalla = Mouse.PositionOnWorld; 60 61 Camera.Follow(pelaaja1); 62 Camera.Zoom(2.5); 63 Camera.StayInLevel = true; 36 64 37 65 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 38 } 66 Mouse.ListenMovement(0.0, HiirenLiikutus, ""); 67 68 } 69 70 void LiikutaPelaajaa(Vector vektori) 71 { 72 pelaaja1.Push(vektori); 73 } 74 75 void HiirenLiikutus(AnalogState Hiiri) 76 { 77 pelaaja1.AbsoluteAngle = (Mouse.PositionOnWorld - pelaaja1.Position).Angle; 78 } 79 80 void LuoSeinä(Vector paikka, double leveys, double korkeus) 81 { 82 83 } 84 85 void KuuneteleLIiketta(AnalogState hiirenTila) 86 { 87 pelaaja1.X = Mouse.PositionOnWorld.X; 88 } 89 90 void LuoAarre(Vector paikka, double leveys, double korkeus) 91 { 92 PhysicsObject aarre = new PhysicsObject(leveys, korkeus); 93 aarre.Shape = Shape.Diamond; 94 aarre.Position = paikka; 95 aarre.Color = Color.Yellow; 96 aarre.Image = aarteenKuva; 97 aarre.Tag = "aarre"; 98 aarre.IgnoresCollisionResponse = true; 99 Add(aarre); 100 } 101 102 39 103 void LuoKentta() 40 104 { 41 105 ColorTileMap ruudut = ColorTileMap.FromLevelAsset("labyrintinkenttä"); 42 ruudut.SetTileMethod(Color.Black, LuoSeinä); 43 ruudut.Execute(RUUDUN_LEVEYS, RUUDUN_KORKEUS); 44 } 45 void LuoSeinä(Vector paikka, double leveys, double korkeus) 46 { 47 48 } 49 50 51 void LiikutaPelaajaa(Vector vektori) 52 { 53 54 pelaaja1.Push(vektori); 106 ruudut.SetTileMethod(Color.FromHexCode("0000FF"), LuoPelaaja); 107 ruudut.SetTileMethod(Color.Black, LuoSeina); 108 ruudut.SetTileMethod(new Color(0, 255, 0, 255), LuoAarre); 109 ruudut.SetTileMethod(Color.Yellow, LuoMaali); 110 ruudut.Execute(RUUDUN_KOKO, RUUDUN_KOKO); 111 112 113 ColorTileMap ruudut2 = ColorTileMap.FromLevelAsset("labyrintinkenttä"); 114 ruudut2.SetTileMethod(Color.Red, LuoHirvio); 115 ruudut2.Execute(RUUDUN_KOKO, RUUDUN_KOKO); 116 117 } 118 119 IntMeter pisteLaskuri; 120 121 void LuoPistelaskuri() 122 { 123 pisteLaskuri = new IntMeter(0); 124 125 Label pisteNaytto = new Label(); 126 pisteNaytto.X = Screen.Right - 100; 127 pisteNaytto.Y = Screen.Top - 100; 128 pisteNaytto.TextColor = Color.Red; 129 pisteNaytto.Color = Color.DarkGray; 130 131 pisteNaytto.BindTo(pisteLaskuri); 132 Add(pisteNaytto); 133 } 134 135 void LuoPelaaja(Vector paikka, double leveys, double korkeus) 136 { 137 pelaaja1 = new PhysicsObject(leveys - 4, korkeus - 4); 138 pelaaja1.Position = paikka; 139 pelaaja1.Image = olionKuva; 140 pelaaja1.LinearDamping = 0.5; 141 142 pelaaja1.Shape = Shape.Circle; 143 AddCollisionHandler(pelaaja1, "Hirvio", TormaaHirvioon); 144 //AddCollisionHandler(pelaaja1, "aarre", CollisionHandler.AddMeterValue(pisteLaskuri, 100)); 145 AddCollisionHandler(pelaaja1, "aarre", TormaaAarteeseen); 146 AddCollisionHandler(pelaaja1, "maali", TormaaMaaliin); 147 148 Add(pelaaja1); 149 150 taskulamppu = new GameObject(LoadImage("flashlight")); 151 Add(taskulamppu, 2); 152 } 153 void LuoSeina(Vector paikka, double leveys, double korkeus) 154 { 155 PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); 156 taso.Position = paikka; 157 taso.Color = Color.Black; 158 taso.Tag = "seina"; 159 taso.CollisionIgnoreGroup = 1; 160 Add(taso); 161 } 162 void LuoHirvio(Vector paikka, double leveys, double korkeus) 163 { 164 PhysicsObject Hirvio = new PhysicsObject(leveys - 2, korkeus - 2); 165 Hirvio.Position = paikka; 166 Hirvio.Image = HirvionKuva; 167 Hirvio.Shape = Shape.Circle; 168 Hirvio.Tag = "Hirvio"; 169 Add(Hirvio, 1); 170 LabyrinthWandererBrain labyrinttiAivot = new LabyrinthWandererBrain(RUUDUN_KOKO); 171 labyrinttiAivot.Speed = 100.0; 172 labyrinttiAivot.LabyrinthWallTag = "seina"; 173 174 175 FollowerBrain seuraajanAivot = new FollowerBrain(pelaaja1); 176 seuraajanAivot.Speed = 300; // Millä nopeudella kohdetta seurataan 177 seuraajanAivot.DistanceFar = 100; // Etäisyys jolla aletaan seurata kohdetta 178 seuraajanAivot.DistanceClose = 10; // Etäisyys jolloin ollaan lähellä kohdetta 179 seuraajanAivot.StopWhenTargetClose = false; // Pysähdytään kun ollaan lähellä kohdetta 180 seuraajanAivot.FarBrain = labyrinttiAivot; // Käytetään satunnaisaivoja kun ollaan kaukana 181 182 Hirvio.Brain = seuraajanAivot; 183 } 184 185 void TormaaHirvioon(PhysicsObject pelaaja, PhysicsObject kohde) 186 { 187 pelaaja.Destroy(); 188 Explosion rajahdys = new Explosion(1000); 189 rajahdys.Position = pelaaja1.Position; 190 rajahdys.Speed = 5000.0; 191 rajahdys.Force = 1000; 192 jumpscareAani.Play(); 193 Add(rajahdys); 194 AloitaAlusta(); 195 } 196 197 void TormaaAarteeseen(PhysicsObject pelaaja, PhysicsObject aarre) 198 { 199 aarre.Destroy(); 200 pisteLaskuri.Value += 100; 201 } 202 203 protected override void Update(Time time) 204 { 205 taskulamppu.Position = pelaaja1.Position; 206 taskulamppu.Angle = pelaaja1.Angle; 207 208 base.Update(time); 209 } 210 void LuoMaali(Vector paikka, double leveys, double korkeus) 211 { 212 PhysicsObject maali = new PhysicsObject(leveys, korkeus); 213 maali.Tag = "maali"; 214 maali.Position = paikka; 215 Add(maali); 216 } 217 218 void AloitaAlusta() 219 { 220 ClearAll(); 221 LuoKentta(); 222 AsetaOjaimet(); 223 LuoPistelaskuri(); 224 } 225 226 void TormaaMaaliin(PhysicsObject pelaaja, PhysicsObject maali) 227 { 228 ClearAll(); 229 PhysicsObject jumpscare = new PhysicsObject(Screen.Width, Screen.Height); 230 jumpscare.Image = jumpscareKuva; 231 Add(jumpscare); 232 jumpscareAani.Play(); 233 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 55 234 } 56 235 57 236 } 58 // TODO: Kirjoita ohjelmakoodisi tähän 59 60 61 62 63 64 237 238 239 240 241 242 -
2015/24/VeetiI/LABYRINTTI/LABYRINTTI/LABYRINTTIContent/LABYRINTTIContent.contentproj
r5961 r6080 62 62 </Compile> 63 63 </ItemGroup> 64 <ItemGroup>64 <ItemGroup> 65 65 <Compile Include="labyrintinkenttä.png"> 66 66 <Name>labyrintinkenttä</Name> … … 68 68 <Processor>TextureProcessor</Processor> 69 69 </Compile> 70 </ItemGroup> <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 70 </ItemGroup> 71 <ItemGroup> 72 <Compile Include="3688.png"> 73 <Name>3688</Name> 74 <Importer>TextureImporter</Importer> 75 <Processor>TextureProcessor</Processor> 76 </Compile> 77 <Compile Include="flashlight.png"> 78 <Name>flashlight</Name> 79 <Importer>TextureImporter</Importer> 80 <Processor>TextureProcessor</Processor> 81 </Compile> 82 <Compile Include="pelimusiikki.mp3"> 83 <Name>pelimusiikki</Name> 84 <Importer>Mp3Importer</Importer> 85 <Processor>SongProcessor</Processor> 86 </Compile> 87 <Compile Include="räjähdys.wav"> 88 <Name>räjähdys</Name> 89 <Importer>WavImporter</Importer> 90 <Processor>SoundEffectProcessor</Processor> 91 </Compile> 92 </ItemGroup> 93 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 71 94 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 72 95 Other similar extension points exist, see Microsoft.Common.targets.
Note: See TracChangeset
for help on using the changeset viewer.