-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame1.cs
More file actions
96 lines (86 loc) · 3.26 KB
/
Game1.cs
File metadata and controls
96 lines (86 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Liquish;
public class Game1 : Game {
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public InputManager IM;
public LiquidManager LM;
public Texture2D img;
public Texture2D EP;
public List<Rectangle> Eps = [];
public List<float> Speeds = [];
public Point ScreenSize => new(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight);
public Game1() {
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize() {
_graphics.PreferredBackBufferWidth = 1066;
_graphics.PreferredBackBufferHeight = 600;
_graphics.SynchronizeWithVerticalRetrace = true;
IsFixedTimeStep = false;
_graphics.ApplyChanges();
base.Initialize();
}
protected override void LoadContent() {
_spriteBatch = new SpriteBatch(GraphicsDevice);
IM = new();
img = Content.Load<Texture2D>("cool");
EP = Content.Load<Texture2D>("EP");
LM = new LiquidManager(GraphicsDevice);
Color sC = new Color(0.1f, 0.4f, 0.8f) * 0.8f;
Color bC = new Color(0, 0, 0.2f) * 0.8f;
Color sC2 = new Color(255, 139, 34) * 0.96f;
Color bC2 = new Color(255, 119, 0) * 0.96f;
Liquid waterPool = new(new Rectangle(10, ScreenSize.Y / 2, 400, 200), 0.5f, 150, 0.99f, sC, bC);
Liquid lavaPool = new(new Rectangle(500, ScreenSize.Y / 2, 400, 200), 0.5f, 150, 0.98f, sC2, bC2);
LM.Add("waterPool", waterPool);
LM.Add("lavaPool", lavaPool);
}
protected override void Update(GameTime gameTime) {
IM.Update();
if (IM.KeyTapped(Keys.Escape))
Exit();
if (IM.MBTapped(MouseButton.Left)) {
Eps.Add(new Rectangle(IM.CMousePos() - new Point(25,24), new(50, 50)));
Speeds.Add(0);
}
for (int i = Eps.Count - 1; i >= 0 ; i--) {
Rectangle rect = Eps[i];
bool contained = false;
foreach (var l in LM.liquids.Values) {
contained = contained || l.boundingBox.Intersects(rect);
}
Speeds[i] += 0.5f;
rect.Y += (int)Speeds[i];
Eps[i] = rect;
foreach (var l in LM.liquids.Values) {
if (!contained && l.boundingBox.Intersects(rect)) {
l.CreateDisturbance(rect.Center.X, 50, 1, 20);
}
}
if (rect.Y > ScreenSize.Y) {
Eps.RemoveAt(i);
Speeds.RemoveAt(i);
}
}
LM.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.White);
_spriteBatch.Begin();
_spriteBatch.Draw(img, new Rectangle(Point.Zero, ScreenSize), Color.White);
foreach (Rectangle Ep in Eps) {
_spriteBatch.Draw(EP, Ep, Color.White);
}
_spriteBatch.End();
LM.Draw(Matrix.Identity);
base.Draw(gameTime);
}
}