Skip to content

Commit b5f4685

Browse files
author
val92130
committed
Rainnnnn
1 parent 40abc4d commit b5f4685

29 files changed

+136
-29
lines changed

LiveIT2.1/Game.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void Form1_Load( object sender, EventArgs e )
9292
fpst.Start();
9393
t.Start();
9494
_soundEnvironment = new SoundEnvironment();
95-
95+
_soundEnvironment.LoadMap( _map );
9696
}
9797

9898
public void LoadMap(Map map)
@@ -167,7 +167,8 @@ public void Draw()
167167
{
168168
Rectangle _rMouse = new Rectangle( new Point( Cursor.Position.X, Cursor.Position.Y ), _selectionCursorWidth );
169169
//_screenGraphic.Clear( Color.FromArgb( 255, Color.Black ) );
170-
_viewPort.Draw( _screenGraphic );
170+
_viewPort.Draw( _screenGraphic );
171+
171172
}
172173

173174
private void Form1_KeyDown( object sender, KeyEventArgs e )

LiveIT2.1/MainViewPort.cs

+58-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class MainViewPort
2121
Map _map;
2222
List<Box> _selectedBoxes;
2323
Texture _texture;
24-
bool _changeTexture, _fillTexture,_putAnimal, _followAnimal;
24+
bool _changeTexture, _fillTexture,_putAnimal, _followAnimal, _isRaining;
2525
public MainViewPort( Map map)
2626
{
2727
_map = map;
@@ -34,16 +34,25 @@ public MainViewPort( Map map)
3434
_miniMapViewPort = new Rectangle( 0, 0, _map.MapSize, _map.MapSize );
3535
_animalSelectorCursor = new Point( 0, 0 );
3636
_map.ViewPort = this;
37+
_isRaining = false;
3738

3839
}
3940

4041

4142
public void Draw( Graphics g )
4243
{
44+
45+
Random t = new Random();
46+
if( t.Next( 0, 1000 ) == 30 ) _map.IsRaining = true;
47+
if( t.Next( 0, 1000 ) == 250 && _map.IsRaining )
48+
{
49+
_map.IsRaining = false;
50+
}
4351
_boxList = _map.GetOverlappedBoxes(_viewPort);
4452
_boxListMini = _map.GetOverlappedBoxes( _miniMapViewPort );
4553
_mouseRect.X = Cursor.Position.X - (_mouseRect.Width / 2);
4654
_mouseRect.Y = Cursor.Position.Y - (_mouseRect.Height / 2);
55+
4756

4857
for( int i = 0; i < _boxList.Count; i++ )
4958
{
@@ -85,10 +94,58 @@ public void Draw( Graphics g )
8594
}
8695
}
8796

97+
if( _map.IsRaining )
98+
{
99+
100+
if( this._isRaining == false )
101+
{
102+
Rain();
103+
this._isRaining = true;
104+
}
105+
106+
g.DrawImage( _texture.GetRain(), _screen );
107+
}
88108
DrawViewPortMiniMap( g, _viewPort, _miniMap, _miniMapViewPort );
89109

90110
}
91111

112+
private void Rain()
113+
{
114+
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
115+
t.Interval = 10000;
116+
t.Tick += new EventHandler( T_rain_tick );
117+
t.Start();
118+
119+
}
120+
121+
private void T_rain_tick( object sender, EventArgs e )
122+
{
123+
if( _map.IsRaining )
124+
{
125+
Random r = new Random();
126+
Point target = new Point( r.Next( 0, _map.MapSize ), r.Next( 0, _map.MapSize ) );
127+
Rectangle targetRect = new Rectangle( target, new Size( r.Next( 0, 800 ), r.Next( 0, 800 ) ) );
128+
int top = targetRect.Top / _map.BoxSize;
129+
int left = targetRect.Left / _map.BoxSize;
130+
int bottom = (targetRect.Bottom - 1) / _map.BoxSize;
131+
int right = (targetRect.Right - 1) / _map.BoxSize;
132+
for( int i = top; i <= bottom; ++i )
133+
{
134+
for( int j = left; j <= right; ++j )
135+
{
136+
if( _map[i, j] != null )
137+
{
138+
Box b = _map[j, i];
139+
b.Ground = BoxGround.Water;
140+
b.DrawTransitionTextures();
141+
}
142+
143+
}
144+
}
145+
}
146+
147+
}
148+
92149
public void CreateAnimal(AnimalTexture animalType)
93150
{
94151
Animal a;

LiveIT2.1/Map.cs

+6-21
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Map
2121
List<Animal> _animals = new List<Animal>();
2222
[NonSerializedAttribute]
2323
MainViewPort _viewPort;
24-
bool _showDebug;
24+
bool _showDebug, _isRaining;
2525

2626
public Map( int boxCountPerLine, int boxSizeInMeter )
2727
{
@@ -98,26 +98,11 @@ public MainViewPort ViewPort
9898
}
9999
}
100100

101-
//public List<Box> GetOverlappedBoxes(Rectangle viewPort)
102-
//{
103-
// List<Box> boxList = new List<Box>();
104-
// for( int i = 0; i < _boxes.Length; i++ )
105-
// {
106-
// Box b = _boxes[i];
107-
108-
// Rectangle rIntersect = b.Area;
109-
// rIntersect.Intersect( viewPort );
110-
// if( rIntersect.IsEmpty ) continue;
111-
// rIntersect.Offset( -b.Area.Left, -b.Area.Top );
112-
// b.Source = b.Area;
113-
114-
// if( _boxes[i].Area.IntersectsWith( viewPort ) )
115-
// {
116-
// boxList.Add( b );
117-
// }
118-
// }
119-
// return boxList;
120-
//}
101+
public bool IsRaining
102+
{
103+
get { return _isRaining; }
104+
set { _isRaining = value; }
105+
}
121106

122107
public List<Box> GetOverlappedBoxes( Rectangle r )
123108
{

LiveIT2.1/Rabbit.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public override void Behavior()
5656
public void Eat()
5757
{
5858
t = new System.Windows.Forms.Timer();
59-
t.Interval = 2000;
59+
t.Interval = 5000;
6060
t.Start();
6161
t.Tick += new EventHandler( T_eat_tick );
6262
}
@@ -65,7 +65,7 @@ private void T_eat_tick( object sender, EventArgs e )
6565
{
6666
if( _isEating )
6767
{
68-
this.Hunger -= 2;
68+
this.Hunger -= 20;
6969
}
7070
}
7171

LiveIT2.1/SoundEnvironment.cs

+31-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ public class SoundEnvironment
1313
{
1414
private WaveOut waveOutBackGround;
1515
private WaveOut waveOutWater;
16-
bool _isStopped, _isWater;
16+
private WaveOut waveOutRain;
17+
bool _isStopped, _isWater, _isRaining;
1718
List<Box> _boxes;
1819
List<BoxGround> _boxGrounds;
20+
Map _map;
1921
public SoundEnvironment()
2022
{
2123
WaveFileReader readerBackGround = new WaveFileReader("../../../sounds/background.wav");
@@ -31,6 +33,12 @@ public SoundEnvironment()
3133
waveOutWater.Init(loopWater);
3234
waveOutWater.Volume = 0.2f;
3335

36+
WaveFileReader readerRain = new WaveFileReader( "../../../sounds/rain.wav" );
37+
LoopStream loopRain = new LoopStream( readerRain );
38+
waveOutRain = new WaveOut();
39+
waveOutRain.Init( loopRain );
40+
waveOutRain.Volume = 1f;
41+
3442
_boxGrounds = new List<BoxGround>();
3543
}
3644

@@ -39,6 +47,11 @@ public void LoadBoxes(List<Box> Boxes)
3947
_boxes = Boxes;
4048
}
4149

50+
public void LoadMap( Map map )
51+
{
52+
_map = map;
53+
}
54+
4255
public void PlayAllSounds()
4356
{
4457
_boxGrounds.Clear();
@@ -62,6 +75,23 @@ public void PlayAllSounds()
6275
{
6376
waveOutWater.Play();
6477
}
78+
79+
if( _map.IsRaining )
80+
{
81+
_isRaining = true;
82+
}
83+
else
84+
{
85+
_isRaining = false;
86+
if( waveOutRain.PlaybackState == PlaybackState.Playing )
87+
{
88+
waveOutRain.Stop();
89+
}
90+
}
91+
if( _isRaining && waveOutRain.PlaybackState == PlaybackState.Stopped && _isStopped == false )
92+
{
93+
waveOutRain.Play();
94+
}
6595
}
6696

6797
public void ToggleMute()

LiveIT2.1/Texture.cs

+36-2
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ public class Texture
1515
Bitmap _textureGrass, _textureDesert, _textureForest, _textureSnow,
1616
_textureDirt, _textureWaterAnimated,_textureRabbit,_textureElephant,
1717
_textureCow, _textureCat, _textureDog, _textureEagle,_textureGazelle,
18-
_textureGiraffe,_textureLion;
18+
_textureGiraffe,_textureLion, _textureRain;
1919
Brush _brushGrass, _brushWater, _brushDesert, _brushForest, _brushSnow, _brushDirt;
20-
Timer _animate;
20+
Timer _animate, _rainTimer;
2121
List <Bitmap> _waterList = new List<Bitmap>();
22+
List<Bitmap> _rainList = new List<Bitmap>();
2223
int count = 0;
24+
int count2 = 0;
2325
public Texture()
2426
{
2527

2628
_animate = new Timer();
2729
_animate.Start();
2830
_animate.Interval = 10;
31+
_rainTimer = new Timer();
32+
33+
_rainTimer.Start();
34+
_rainTimer.Interval = 10;
35+
_rainTimer.Tick += new EventHandler( T_rain_tick );
2936
_animate.Tick += new EventHandler( T_animateTick );
3037
_textureGrass = new Bitmap( @"..\..\..\assets\Grass.jpg");
3138

@@ -34,6 +41,8 @@ public Texture()
3441
_textureDesert = new Bitmap( @"..\..\..\assets\Desert.jpg" );
3542
_textureDirt = new Bitmap( @"..\..\..\assets\Dirt.jpg" );
3643

44+
45+
3746
_textureRabbit = new Bitmap( @"..\..\..\assets\Animal\Rabbit.png" );
3847
_textureElephant = new Bitmap( @"..\..\..\assets\Animal\Elephant.png" );
3948
_textureElephant.RotateFlip(RotateFlipType.Rotate180FlipY);
@@ -71,9 +80,28 @@ public Texture()
7180
_brushForest = new SolidBrush( Color.FromArgb( 110, 121, 53 ) );
7281
_brushSnow = new SolidBrush( Color.FromArgb( 207, 206, 212 ) );
7382

83+
_textureRain = new Bitmap( @"..\..\..\assets\Rain\0.gif" );
84+
_textureRain.MakeTransparent( Color.Black );
85+
7486
_textureWaterAnimated = new Bitmap( @"..\..\..\assets\Water\Water.jpg" );
7587

7688
AddTexturesFromFolderToList( @"..\..\..\assets\Animated\", _waterList );
89+
AddTexturesFromFolderToList( @"..\..\..\assets\Rain\", _rainList );
90+
}
91+
92+
private void T_rain_tick( object sender, EventArgs e )
93+
{
94+
if( count2 + 1 <= _rainList.Count )
95+
{
96+
_rainList[count2].MakeTransparent( Color.Black );
97+
_textureRain = _rainList[count2];
98+
99+
count2++;
100+
}
101+
else
102+
{
103+
count2 = 0;
104+
}
77105
}
78106

79107
private void T_animateTick( object sender, EventArgs e )
@@ -87,6 +115,7 @@ private void T_animateTick( object sender, EventArgs e )
87115
{
88116
count = 0;
89117
}
118+
90119
}
91120

92121
public void AddTexturesFromFolderToList( string Directory, List<Bitmap> list )
@@ -164,5 +193,10 @@ public Bitmap LoadTexture( Animal animal )
164193
return _textureGrass;
165194
}
166195
}
196+
197+
public Bitmap GetRain()
198+
{
199+
return _textureRain;
200+
}
167201
}
168202
}

assets/Rain.gif

3.71 MB
Loading

assets/Rain/0.gif

14.2 KB
Loading

assets/Rain/1.gif

14.2 KB
Loading

assets/Rain/10.gif

12.3 KB
Loading

assets/Rain/11.gif

13.5 KB
Loading

assets/Rain/12.gif

14.5 KB
Loading

assets/Rain/13.gif

14 KB
Loading

assets/Rain/14.gif

13.2 KB
Loading

assets/Rain/15.gif

14.6 KB
Loading

assets/Rain/16.gif

15 KB
Loading

assets/Rain/17.gif

14.7 KB
Loading

assets/Rain/18.gif

13.6 KB
Loading

assets/Rain/19.gif

13.4 KB
Loading

assets/Rain/2.gif

13.5 KB
Loading

assets/Rain/3.gif

12.1 KB
Loading

assets/Rain/4.gif

11.6 KB
Loading

assets/Rain/5.gif

13.2 KB
Loading

assets/Rain/6.gif

13.5 KB
Loading

assets/Rain/7.gif

14.1 KB
Loading

assets/Rain/8.gif

13.6 KB
Loading

assets/Rain/9.gif

11.5 KB
Loading

assets/rain2.gif

293 KB
Loading

sounds/rain.wav

5.56 MB
Binary file not shown.

0 commit comments

Comments
 (0)