2525// For more information, please refer to <http://unlicense.org>
2626// ***************************************************************************
2727
28+ using System ;
2829using System . Collections . Generic ;
2930using CollisionGrid ;
3031using Microsoft . Xna . Framework ;
3132using Microsoft . Xna . Framework . Graphics ;
32- using Utilities ;
33- using Utilities . Randomizing ;
33+ using MonoGame . Extended . Shapes ;
3434
3535namespace Test
3636{
@@ -58,16 +58,16 @@ public DrawableGrid(Game game, SpriteBatch spriteBatch, float width, float heigh
5858 public override void Initialize ( )
5959 {
6060 base . Initialize ( ) ;
61- var rand = RandomizerController . Randomizer ;
62- for ( var i = 0 ; i < NUMBER_OF_SPRITES ; i ++ )
61+ Random rand = new Random ( 1 ) ;
62+ for ( int i = 0 ; i < NUMBER_OF_SPRITES ; i ++ )
6363 {
64- var s = new Sprite ( Game , SpriteBatch , new Point ( ( int ) width , ( int ) height ) ) ;
65- s . Trajectory = new Vector2 ( rand . RandomBetween ( - 1f , 1f ) , rand . RandomBetween ( - 1f , 1f ) ) ;
64+ Sprite s = new Sprite ( Game , SpriteBatch , new Point ( ( int ) width , ( int ) height ) ) ;
65+ s . Trajectory = new Vector2 ( rand . Next ( - 1000 , 1000 ) / 1000f , rand . Next ( - 1000 , 1000 ) / 1000f ) ;
6666 s . Trajectory . Normalize ( ) ;
67- s . Position = new Vector2 ( rand . RandomBetween ( 0f , 700f ) , rand . RandomBetween ( 0f , 700f ) ) ;
68- s . Velocity = rand . RandomBetween ( .1f , 4f ) ;
69- s . Width = rand . RandomBetween ( 5 , 53 ) ;
70- s . Height = rand . RandomBetween ( 5 , 53 ) ;
67+ s . Position = new Vector2 ( rand . Next ( 0 , 700 ) , rand . Next ( 0 , 700 ) ) ;
68+ s . Velocity = rand . Next ( 100 , 4000 ) / 1000f ;
69+ s . Width = rand . Next ( 5 , 53 ) ;
70+ s . Height = rand . Next ( 5 , 53 ) ;
7171
7272 s . Initialize ( ) ;
7373 Game . Components . Add ( s ) ;
@@ -78,7 +78,7 @@ public override void Initialize()
7878 public override void Update ( GameTime gameTime )
7979 {
8080 base . Update ( gameTime ) ;
81- foreach ( var s in sprites )
81+ foreach ( Sprite s in sprites )
8282 {
8383 Grid . Move ( s , s . GetAabb ( ) ) ;
8484 }
@@ -89,28 +89,34 @@ public override void Draw(GameTime gameTime)
8989 if ( Visible )
9090 {
9191 SpriteBatch . Begin ( SpriteSortMode . Deferred , BlendState . NonPremultiplied ) ;
92- var r = new Rectangle ( ( int ) Position . X , ( int ) Position . Y , ( int ) width , ( int ) height ) ;
92+ Rectangle r = new Rectangle ( ( int ) Position . X , ( int ) Position . Y , ( int ) width , ( int ) height ) ;
9393 SpriteBatch . DrawRectangle ( r , Color . Yellow ) ;
94- for ( var x = 0 ; x < Grid . NumberOfCellsX ; x ++ )
94+ for ( int x = 0 ; x < Grid . NumberOfCellsX ; x ++ )
9595 {
96- for ( var y = 0 ; y < Grid . NumberOfCellsY ; y ++ )
96+ for ( int y = 0 ; y < Grid . NumberOfCellsY ; y ++ )
9797 {
98- var cell = new Rectangle ( ( int ) ( Position . X + x * Grid . CellWidth ) ,
98+ Rectangle cell = new Rectangle ( ( int ) ( Position . X + x * Grid . CellWidth ) ,
9999 ( int ) ( Position . Y + y * Grid . CellHeight ) ,
100100 ( int ) Grid . CellWidth , ( int ) Grid . CellHeight ) ;
101- var l = Grid . Get ( new Point ( x , y ) ) . Length ;
101+ int l = Grid . Get ( new Point ( x , y ) ) . Length ;
102+
103+ Color c ;
102104 if ( l > 0 )
103105 {
104- var f = l / 4f ;
106+ float f = l / 4f ;
105107 if ( f > 1 )
106108 {
107109 f = 1 ;
108110 }
109- SpriteBatch . FillRectangle ( cell , Utils . SetTransparencyOnColor ( Color . Red , f ) ) ;
111+ c = Color . Red ;
112+ c . A = ( byte ) ( 255f * f ) ;
113+ SpriteBatch . FillRectangle ( cell , c ) ;
110114 }
111115 else
112116 {
113- SpriteBatch . DrawRectangle ( cell , Utils . SetTransparencyOnColor ( Color . Yellow , .5f ) ) ;
117+ c = Color . Yellow ;
118+ c . A = ( byte ) ( 255f * .5f ) ;
119+ SpriteBatch . DrawRectangle ( cell , c ) ;
114120 }
115121 }
116122 }
0 commit comments