splitting meteors

This commit is contained in:
Dylan Wilson
2016-01-07 08:19:46 +10:00
parent ad82127677
commit f1498eda8f
8 changed files with 217 additions and 43 deletions
+16 -14
View File
@@ -22,7 +22,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:playerShip1_blue.png
@@ -34,7 +33,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_big1.png
@@ -46,7 +44,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:laserBlue03.png
@@ -58,7 +55,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_big2.png
@@ -70,7 +66,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_big3.png
@@ -82,7 +77,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_big4.png
@@ -94,7 +88,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_med1.png
@@ -106,7 +99,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_med3.png
@@ -118,7 +110,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_small1.png
@@ -130,7 +121,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_small2.png
@@ -142,7 +132,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_tiny1.png
@@ -154,7 +143,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:meteorBrown_tiny2.png
@@ -166,7 +154,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:black.png
@@ -183,7 +170,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:regular-explosion.png
@@ -192,3 +178,19 @@
/processor:TexturePackerProcessor
/build:regular-explosion-sheet.json
#begin Fonts/courier-new-32.fnt
/importer:BitmapFontImporter
/processor:BitmapFontProcessor
/build:Fonts/courier-new-32.fnt
#begin Fonts/courier-new-32_0.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:TextureFormat=Color
/build:Fonts/courier-new-32_0.png
@@ -0,0 +1,105 @@
<?xml version="1.0"?>
<font>
<info face="Courier New" size="32" bold="1" italic="0" charset="" unicode="1" stretchH="100" smooth="1" aa="1" padding="0,0,0,0" spacing="1,1" outline="1"/>
<common lineHeight="31" base="23" scaleW="256" scaleH="256" pages="1" packed="0" alphaChnl="0" redChnl="4" greenChnl="4" blueChnl="4"/>
<pages>
<page id="0" file="courier-new-32_0.png" />
</pages>
<chars count="95">
<char id="32" x="248" y="37" width="5" height="3" xoffset="-2" yoffset="29" xadvance="17" page="0" chnl="15" />
<char id="33" x="117" y="44" width="8" height="19" xoffset="4" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="34" x="36" y="121" width="13" height="10" xoffset="2" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="35" x="64" y="0" width="18" height="23" xoffset="-1" yoffset="3" xadvance="17" page="0" chnl="15" />
<char id="36" x="48" y="0" width="15" height="24" xoffset="1" yoffset="3" xadvance="17" page="0" chnl="15" />
<char id="37" x="158" y="24" width="17" height="19" xoffset="0" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="38" x="116" y="83" width="16" height="18" xoffset="1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="39" x="247" y="60" width="7" height="10" xoffset="5" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="40" x="107" y="0" width="10" height="23" xoffset="6" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="41" x="129" y="0" width="10" height="23" xoffset="1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="42" x="236" y="95" width="16" height="14" xoffset="1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="43" x="217" y="79" width="18" height="17" xoffset="0" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="44" x="50" y="121" width="9" height="10" xoffset="4" yoffset="18" xadvance="17" page="0" chnl="15" />
<char id="45" x="112" y="118" width="15" height="5" xoffset="1" yoffset="12" xadvance="17" page="0" chnl="15" />
<char id="46" x="247" y="71" width="7" height="6" xoffset="5" yoffset="18" xadvance="17" page="0" chnl="15" />
<char id="47" x="17" y="0" width="15" height="25" xoffset="1" yoffset="2" xadvance="17" page="0" chnl="15" />
<char id="48" x="101" y="44" width="15" height="19" xoffset="1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="49" x="0" y="47" width="16" height="19" xoffset="1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="50" x="17" y="47" width="16" height="19" xoffset="0" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="51" x="194" y="21" width="17" height="19" xoffset="0" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="52" x="212" y="21" width="17" height="19" xoffset="0" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="53" x="230" y="21" width="17" height="19" xoffset="0" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="54" x="68" y="45" width="16" height="19" xoffset="1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="55" x="34" y="47" width="16" height="19" xoffset="0" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="56" x="85" y="44" width="15" height="19" xoffset="1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="57" x="51" y="46" width="16" height="19" xoffset="1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="58" x="248" y="21" width="7" height="15" xoffset="5" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="59" x="166" y="82" width="10" height="18" xoffset="4" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="60" x="177" y="82" width="19" height="17" xoffset="-2" yoffset="7" xadvance="17" page="0" chnl="15" />
<char id="61" x="16" y="121" width="19" height="10" xoffset="-1" yoffset="10" xadvance="17" page="0" chnl="15" />
<char id="62" x="197" y="82" width="19" height="17" xoffset="0" yoffset="7" xadvance="17" page="0" chnl="15" />
<char id="63" x="150" y="82" width="15" height="18" xoffset="1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="64" x="179" y="0" width="14" height="21" xoffset="1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="65" x="194" y="41" width="21" height="18" xoffset="-2" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="66" x="187" y="63" width="19" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="67" x="167" y="63" width="19" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="68" x="0" y="86" width="19" height="18" xoffset="-2" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="69" x="20" y="86" width="19" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="70" x="79" y="85" width="18" height="18" xoffset="0" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="71" x="44" y="67" width="20" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="72" x="40" y="86" width="19" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="73" x="133" y="82" width="16" height="18" xoffset="0" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="74" x="107" y="64" width="19" height="18" xoffset="0" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="75" x="86" y="64" width="20" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="76" x="127" y="63" width="19" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="77" x="126" y="44" width="23" height="18" xoffset="-3" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="78" x="150" y="44" width="21" height="18" xoffset="-2" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="79" x="227" y="60" width="19" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="80" x="60" y="86" width="18" height="18" xoffset="0" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="81" x="159" y="0" width="19" height="22" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="82" x="65" y="66" width="20" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="83" x="238" y="41" width="17" height="18" xoffset="0" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="84" x="207" y="60" width="19" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="85" x="172" y="44" width="21" height="18" xoffset="-2" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="86" x="216" y="41" width="21" height="18" xoffset="-2" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="87" x="0" y="67" width="21" height="18" xoffset="-2" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="88" x="22" y="67" width="21" height="18" xoffset="-2" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="89" x="147" y="63" width="19" height="18" xoffset="-1" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="90" x="98" y="83" width="17" height="18" xoffset="0" yoffset="6" xadvance="17" page="0" chnl="15" />
<char id="91" x="140" y="0" width="10" height="23" xoffset="5" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="92" x="0" y="0" width="16" height="25" xoffset="0" yoffset="2" xadvance="17" page="0" chnl="15" />
<char id="93" x="118" y="0" width="10" height="23" xoffset="2" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="94" x="0" y="121" width="15" height="12" xoffset="1" yoffset="3" xadvance="17" page="0" chnl="15" />
<char id="95" x="88" y="120" width="23" height="5" xoffset="-3" yoffset="27" xadvance="17" page="0" chnl="15" />
<char id="96" x="78" y="121" width="9" height="6" xoffset="4" yoffset="4" xadvance="17" page="0" chnl="15" />
<char id="97" x="107" y="102" width="19" height="15" xoffset="-1" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="98" x="60" y="25" width="20" height="19" xoffset="-2" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="99" x="165" y="101" width="18" height="15" xoffset="0" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="100" x="39" y="26" width="20" height="19" xoffset="-1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="101" x="127" y="102" width="18" height="15" xoffset="-1" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="102" x="139" y="24" width="18" height="19" xoffset="0" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="103" x="0" y="26" width="20" height="20" xoffset="-1" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="104" x="81" y="24" width="19" height="19" xoffset="-1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="105" x="21" y="26" width="17" height="20" xoffset="0" yoffset="4" xadvance="17" page="0" chnl="15" />
<char id="106" x="33" y="0" width="14" height="25" xoffset="1" yoffset="4" xadvance="17" page="0" chnl="15" />
<char id="107" x="101" y="24" width="18" height="19" xoffset="-1" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="108" x="176" y="23" width="17" height="19" xoffset="0" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="109" x="0" y="105" width="22" height="15" xoffset="-2" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="110" x="236" y="79" width="19" height="15" xoffset="-1" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="111" x="184" y="100" width="17" height="15" xoffset="0" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="112" x="215" y="0" width="20" height="20" xoffset="-2" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="113" x="194" y="0" width="20" height="20" xoffset="-1" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="114" x="146" y="101" width="18" height="15" xoffset="0" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="115" x="202" y="100" width="17" height="15" xoffset="0" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="116" x="120" y="24" width="18" height="19" xoffset="0" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="117" x="67" y="105" width="19" height="15" xoffset="-1" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="118" x="23" y="105" width="21" height="15" xoffset="-2" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="119" x="45" y="105" width="21" height="15" xoffset="-2" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="120" x="87" y="104" width="19" height="15" xoffset="-1" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="121" x="236" y="0" width="19" height="20" xoffset="-1" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="122" x="220" y="97" width="15" height="15" xoffset="1" yoffset="9" xadvance="17" page="0" chnl="15" />
<char id="123" x="83" y="0" width="11" height="23" xoffset="3" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="124" x="151" y="0" width="7" height="23" xoffset="5" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="125" x="95" y="0" width="11" height="23" xoffset="3" yoffset="5" xadvance="17" page="0" chnl="15" />
<char id="126" x="60" y="121" width="17" height="8" xoffset="0" yoffset="11" xadvance="17" page="0" chnl="15" />
</chars>
</font>
Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+1
View File
@@ -12,6 +12,7 @@ namespace SpaceGame.Entities
{
_animator = animator;
_animator.Sprite.Position = position;
_animator.Sprite.Scale = Vector2.One*0.2f;
_animator.IsLooping = false;
_animator.PlayAnimation("explode", Destroy);
}
+6 -3
View File
@@ -8,23 +8,26 @@ namespace SpaceGame.Entities
{
public class Meteor : Entity
{
public Meteor(TextureRegion2D textureRegion, Vector2 position, Vector2 velocity, float rotationSpeed)
public Meteor(TextureRegion2D textureRegion, Vector2 position, Vector2 velocity, float rotationSpeed, int size)
{
_sprite = new Sprite(textureRegion);
_shape = new CircleF(_sprite.Position, _radius);
_shape = new CircleF(_sprite.Position, _radius * size);
Position = position;
Velocity = velocity;
RotationSpeed = rotationSpeed;
HealthPoints = 1;
Size = size;
}
private const float _radius = 55f;
private const float _radius = 55f / 4f;
private readonly Sprite _sprite;
private CircleF _shape;
public int HealthPoints { get; private set; }
public float RotationSpeed { get; private set; }
public Vector2 Velocity { get; set; }
public int Size { get; private set; }
public Vector2 Position
{
+30 -11
View File
@@ -4,6 +4,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGame.Extended;
using MonoGame.Extended.BitmapFonts;
using MonoGame.Extended.Shapes;
using MonoGame.Extended.Sprites;
using MonoGame.Extended.TextureAtlases;
@@ -22,6 +23,8 @@ namespace SpaceGame
private readonly Random _random;
private readonly EntityManager _entityManager;
private Camera2D _camera;
private BitmapFont _font;
private int _score;
public GameMain()
{
@@ -43,6 +46,7 @@ namespace SpaceGame
{
_viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
_camera = new Camera2D(_viewportAdapter);
_font = Content.Load<BitmapFont>("Fonts/courier-new-32");
_spriteBatch = new SpriteBatch(GraphicsDevice);
@@ -105,45 +109,60 @@ namespace SpaceGame
_entityManager.Update(gameTime);
CheckMeteorLaserCollisions();
foreach (var laser in _entityManager.Entities.Where(e => e is Laser).Cast<Laser>().ToArray())
_previousMouseState = mouseState;
_camera.LookAt(_player.Position + _player.Velocity * 0.2f);
base.Update(gameTime);
}
private void CheckMeteorLaserCollisions()
{
var meteors = _entityManager.Entities.Where(e => e is Meteor).Cast<Meteor>().ToArray();
var lasers = _entityManager.Entities.Where(e => e is Laser).Cast<Laser>().ToArray();
foreach (var laser in lasers)
{
foreach (var meteor in _entityManager.Entities.Where(e => e is Meteor).Cast<Meteor>().ToArray())
foreach (var meteor in meteors)
{
if (meteor.Contains(laser.Position))
{
meteor.Damage(1);
laser.Destroy();
_score++;
var animator = Content.Load<SpriteSheetAnimator>("explosion-animations");
_entityManager.AddEntity(new Explosion(animator, meteor.Position));
_meteorFactory.SpawnNewMeteor(_player.Position);
_entityManager.AddEntity(new Explosion(animator, laser.Position));
if(meteor.Size >= 2)
_meteorFactory.SplitMeteor(meteor);
}
}
}
_previousMouseState = mouseState;
_camera.LookAt(_player.Position + _player.Velocity * 0.2f);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
// background
var sourceRectangle = new Rectangle(0, 0, _viewportAdapter.VirtualWidth, _viewportAdapter.VirtualHeight);
sourceRectangle.Offset(_camera.Position);
_spriteBatch.Begin(samplerState: SamplerState.LinearWrap, transformMatrix: _camera.GetViewMatrix());
_spriteBatch.Draw(_backgroundTexture, _camera.Position, sourceRectangle, Color.White);
_spriteBatch.End();
// entities
_spriteBatch.Begin(samplerState: SamplerState.LinearClamp, transformMatrix: _camera.GetViewMatrix());
_entityManager.Draw(_spriteBatch);
_spriteBatch.End();
// hud
_spriteBatch.Begin();
_spriteBatch.DrawString(_font, string.Format("Score: {0}", _score), Vector2.One, Color.White);
_spriteBatch.End();
base.Draw(gameTime);
}
}
+57 -15
View File
@@ -13,29 +13,70 @@ namespace SpaceGame
public class MeteorFactory
{
private readonly EntityManager _entityManager;
private readonly List<TextureRegion2D> _bigRegions = new List<TextureRegion2D>();
private readonly List<TextureRegion2D> _mediumRegions = new List<TextureRegion2D>();
private readonly List<TextureRegion2D> _smallRegions = new List<TextureRegion2D>();
private readonly List<TextureRegion2D> _tinyRegions = new List<TextureRegion2D>();
private readonly Dictionary<int, TextureRegion2D[]> _meteorRegions;
private readonly Random _random = new Random();
public MeteorFactory(EntityManager entityManager, ContentManager contentManager)
{
_entityManager = entityManager;
_bigRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_big1")));
_bigRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_big2")));
_bigRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_big3")));
_bigRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_big4")));
_meteorRegions = new Dictionary<int, TextureRegion2D[]>()
{
{ 4, new []
{
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_big1")),
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_big2")),
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_big3")),
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_big4"))
}
},
{ 3, new []
{
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_med1")),
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_med3"))
}
},
{ 2, new []
{
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_small1")),
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_small2"))
}
},
{ 1, new []
{
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_tiny1")),
new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_tiny2"))
}
}
_mediumRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_med1")));
_mediumRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_med3")));
};
}
_smallRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_small1")));
_smallRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_small2")));
private TextureRegion2D GetMeteorRegion(int size)
{
var regions = _meteorRegions[size];
var index = _random.Next(0, regions.Length);
return regions[index];
}
_tinyRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_tiny1")));
_tinyRegions.Add(new TextureRegion2D(contentManager.Load<Texture2D>("meteorBrown_tiny2")));
public void SplitMeteor(Meteor meteor)
{
if (meteor.Size <= 1)
throw new InvalidOperationException("Meteor size less than 2 can't be split");
for (var i = 0; i < 2; i++)
{
var size = meteor.Size - 1;
var rotationSpeed = _random.Next(-10, 10)*0.1f;
var spawnPosition = meteor.Position;
var velocity = i == 0
? meteor.Velocity.PerpendicularClockwise() + meteor.Velocity
: meteor.Velocity.PerpendicularCounterClockwise() + meteor.Velocity;
var textureRegion = GetMeteorRegion(size);
var newMeteor = new Meteor(textureRegion, spawnPosition, velocity, rotationSpeed, size);
_entityManager.AddEntity(newMeteor);
}
}
public void SpawnNewMeteor(Vector2 playerPosition)
@@ -46,7 +87,8 @@ namespace SpaceGame
var spawnPosition = spawnCircle.GetPointAlongEdge(spawnAngle);
var velocity = (playerPosition - spawnPosition)
.Rotate(MathHelper.ToRadians(_random.Next(-15, 15))) * _random.Next(3, 10) * 0.01f;
var meteor = new Meteor(_bigRegions[_random.Next(0, _bigRegions.Count)], spawnPosition, velocity, rotationSpeed);
var textureRegion = GetMeteorRegion(4);
var meteor = new Meteor(textureRegion, spawnPosition, velocity, rotationSpeed, 3);
_entityManager.AddEntity(meteor);
}
+2
View File
@@ -67,6 +67,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Content\black.png" />
<Content Include="Content\Fonts\courier-new-32_0.png" />
<Content Include="Content\laserBlue03.png" />
<Content Include="Content\meteorBrown_big1.png" />
<Content Include="Content\meteorBrown_big2.png" />
@@ -88,6 +89,7 @@
<ItemGroup>
<Content Include="Content\explosion-animations.aa" />
<Content Include="Content\regular-explosion-sheet.json" />
<None Include="Content\Fonts\courier-new-32.fnt" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>