- Timestamp:
- 2012-07-05 14:20:42 (11 years ago)
- Location:
- 2012/27/NikoKi/EpicTankBattle/EpicTankBattle
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/27/NikoKi/EpicTankBattle/EpicTankBattle/EpicTankBattle/EpicTankBattle.cs
r3494 r3588 6 6 using Jypeli.Effects; 7 7 using Jypeli.Widgets; 8 9 public class Tankki : PlatformCharacter2 10 { 11 public bool liikkumassa = false; 12 public Tankki(double leveys, double korkeus) 13 : base(leveys, korkeus) 14 { 15 } 16 } 8 17 9 18 public class EpicTankBattle : PhysicsGame … … 16 25 Image Mustatankki = LoadImage("Mustatankki"); 17 26 Image Tykki = LoadImage("Tykki"); 18 19 20 Tank P1; 27 Image Rajahdys = LoadImage("Rajahdys"); 28 29 30 31 Tankki P1; 32 Tankki P2; 33 Cannon P1tykki; 34 Cannon P2tykki; 35 Direction tankki1suunta = Direction.Right; 21 36 22 37 public override void Begin() … … 24 39 // TODO: Kirjoita ohjelmakoodisi tähän 25 40 26 Gravity = new Vector(0, -250); 41 42 43 Gravity = new Vector(0, -2000); 44 //Level.CreateBorders(); 45 //Surface maasto = Surface.CreateBottom(Level, 20, 200, 20); 46 //Add(maasto); 47 48 ColorTileMap Ruudut = ColorTileMap.FromLevelAsset("Maapera"); 49 Ruudut.SetTileMethod(Color.Black, LuoNelio); 50 Ruudut.Execute(20, 10); 51 27 52 Level.CreateBorders(); 53 Camera.StayInLevel = false; 54 Camera.ZoomToLevel(); 55 Surface.CreateLeft(Level); 56 Surface.CreateRight(Level); 28 57 29 58 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 30 59 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 31 60 61 P1 = new Tankki(40, 25); 62 P1.Image = Punainentankki; 63 P1.PlatformTolerance = 1; 64 P1.Acceleration = 0.6; 65 P1.MaxVelocity = 3; 66 P1.KineticFriction = 0; 67 Add(P1); 68 69 P1tykki = new Cannon(60, 7); 70 P1tykki.Image = LoadImage("tykki"); 71 P1tykki.Angle = Angle.StraightAngle; 72 P1.Add(P1tykki); 73 74 P2 = new Tankki(40, 25); 75 P2.Image = Vihreatankki; 76 P2.PlatformTolerance = 1; 77 P2.FacingDirection = Direction.Left; 78 Add(P2); 79 80 P1.X = -700; 81 P1.Y = 10; 82 P2.X = 700; 83 P2.Y = 10; 84 85 P2tykki = new Cannon(60, 7); 86 P2tykki.Image = LoadImage("tykki"); 87 P2.Add(P2tykki); 88 32 89 Nappaimisto(); 33 P1 = new Tank(45, 30); 34 P1.Image = Vihreatankki; 35 P1.Cannon.Image = Tykki; 36 Add (P1); 37 } 90 } 91 92 void LuoNelio(Vector paikka, double leveys, double korkeus) 93 { 94 PhysicsObject nelio = PhysicsObject.CreateStaticObject(leveys, korkeus); 95 nelio.Position = paikka; 96 nelio.Color = Color.Brown; 97 nelio.CollisionIgnoreGroup = 1; 98 nelio.KineticFriction = 0; 99 Add(nelio); 100 } 101 102 void LiikutaP1(PlatformCharacter2 P1, Vector liike) 103 { 104 105 // LiikutaP1.Velocity = LiikutaP1.Velocity + Liike; 106 107 } 108 38 109 void Nappaimisto() 39 110 { 40 Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaP1, "liikuta pelaajaa 1", new Vector(-200, 0)); 41 Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaP1, "liikuta pelaajaa 1", new Vector(200, 0)); 42 43 } 44 45 void LiikutaP1(Vector liike) 46 { 47 P1.Push(liike); 111 Vector vasemmalle = new Vector(-1400, 1400); 112 Vector oikealle = new Vector(1400, 1400); 113 114 Keyboard.Listen(Key.A, ButtonState.Down, Liikuta, null, P1, vasemmalle); 115 Keyboard.Listen(Key.D, ButtonState.Down, Liikuta, null, P1, oikealle); 116 117 Keyboard.Listen(Key.Left, ButtonState.Down, Liikuta, null, P2, vasemmalle); 118 Keyboard.Listen(Key.Right, ButtonState.Down, Liikuta, null, P2, oikealle); 119 120 Keyboard.Listen(Key.LeftControl, ButtonState.Down, Ammu, null, P1); 121 Keyboard.Listen(Key.RightControl, ButtonState.Down, Ammu, null, P2); 122 123 Keyboard.Listen(Key.W, ButtonState.Down, KaannaTykki1, null, P1tykki, 2); 124 Keyboard.Listen(Key.S, ButtonState.Down, KaannaTykki1, null, P1tykki, -2); 125 126 Keyboard.Listen(Key.Down, ButtonState.Down, KaannaTykki2, null, P2tykki, 2); 127 Keyboard.Listen(Key.Up, ButtonState.Down, KaannaTykki2, null, P2tykki, -2); 128 129 //Keyboard.Listen(Key.LeftControl, ButtonState.Down, P1Ammu, null, P1tykki); 130 //Keyboard.Listen(Key.RightControl, ButtonState.Down, P2Ammu, null, P2tykki); 131 132 } 133 134 void Liikuta(Tankki tankki, Vector liike) 135 { 136 if (Keyboard.GetKeyState(Key.Left) == ButtonState.Down && Keyboard.GetKeyState(Key.Right) == ButtonState.Down) 137 return; 138 139 if (Keyboard.GetKeyState(Key.A) == ButtonState.Down && Keyboard.GetKeyState(Key.D) == ButtonState.Down) 140 return; 141 142 if (liike.X < 0) 143 { 144 if (tankki == P1 && tankki1suunta == Direction.Right) 145 { 146 tankki1suunta = Direction.Left; 147 Vector v = Vector.FromAngle(P1tykki.Angle); 148 P1tykki.Angle = new Vector(-v.X, v.Y).Angle; 149 } 150 } 151 152 else if (liike.X > 0) 153 { 154 if (tankki == P1 && tankki1suunta == Direction.Left) 155 { 156 tankki1suunta = Direction.Right; 157 Vector v = Vector.FromAngle(P1tykki.Angle); 158 P1tykki.Angle = new Vector(-v.X, v.Y).Angle; 159 } 160 } 161 162 // Tankki.Walk(Direction.Left); 163 tankki.Push(liike); 164 } 165 166 void Ammu(PlatformCharacter2 Tankki) 167 { 168 // Tankki.Shoot(1000000); 169 } 170 171 void KaannaTykki1(Cannon tykki, int suunta) 172 { 173 double tykinkulma = tykki.Angle.Degrees; 174 double uusikulma; 175 176 if (tankki1suunta == Direction.Right) 177 uusikulma = tykinkulma + suunta; 178 else 179 uusikulma = tykinkulma - suunta; 180 181 if ( (tankki1suunta == Direction.Right && uusikulma <= -90 && uusikulma >= -180 ) || 182 (tankki1suunta == Direction.Left && uusikulma <= 0 && uusikulma >= -90)) 183 { 184 tykki.Angle = Angle.FromDegrees(uusikulma); 185 } 186 } 187 188 void KaannaTykki2(Cannon tykki, int suunta) 189 { 190 double tykinkulma = tykki.Angle.Degrees; 191 double uusikulma = tykinkulma + suunta; 192 193 //if (uusikulma <= 0 && uusikulma >= -90) 194 { 195 tykki.Angle = Angle.FromDegrees(uusikulma); 196 } 197 } 198 199 void AlustaRajahdys() 200 { 201 //rajahdyssysteemi = new ExplosionSystem(Rajahdys, 5000); 202 //rajahdyssysteemi.MinScale = 1; 203 //rajahdyssysteemi.MaxScale = 5; 204 //Add(rajahdyssysteemi); 48 205 } 49 206 50 207 } 208 209 -
2012/27/NikoKi/EpicTankBattle/EpicTankBattle/EpicTankBattleContent/EpicTankBattleContent.contentproj
r3494 r3588 106 106 </Compile> 107 107 </ItemGroup> 108 <ItemGroup> 109 <Compile Include="Rajahdys.png"> 110 <Name>Rajahdys</Name> 111 <Importer>TextureImporter</Importer> 112 <Processor>TextureProcessor</Processor> 113 </Compile> 114 </ItemGroup> 115 <ItemGroup> 116 <Compile Include="Maapera.png"> 117 <Name>Maapera</Name> 118 <Importer>TextureImporter</Importer> 119 <Processor>TextureProcessor</Processor> 120 </Compile> 121 </ItemGroup> 122 <ItemGroup> 123 <Compile Include="Nelio.png"> 124 <Name>Nelio</Name> 125 <Importer>TextureImporter</Importer> 126 <Processor>TextureProcessor</Processor> 127 </Compile> 128 </ItemGroup> 108 129 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 109 130 <!-- 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.