-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game1.cs
141 lines (120 loc) · 3.7 KB
/
Game1.cs
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace BomberMan
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Map map;
public static Texture2D walkAble;
public static Texture2D unWalkAble;
public static Texture2D bomb1;
public static Texture2D bomb2;
public static Texture2D Explode;
public static Texture2D bonus;
public static Texture2D enemy;
public static Texture2D button;
public static SpriteFont mainFont;
public static Random rand;
public static int playersNumb = 0;
public bool isChose;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferHeight = 690;
graphics.PreferredBackBufferWidth = 1200;
map = new Map(80, 44);
rand = new Random();
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
IsMouseVisible = true;
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
walkAble = Content.Load<Texture2D>("walkable");
unWalkAble = Content.Load<Texture2D>("UNwalkable");
bomb1 = Content.Load<Texture2D>("Bomb1");
bomb2 = Content.Load<Texture2D>("Bomb2");
Explode = Content.Load<Texture2D>("Explosion");
bonus = Content.Load<Texture2D>("coin");
enemy = Content.Load<Texture2D>("Enemy");
mainFont = Content.Load<SpriteFont>("File");
button = Content.Load<Texture2D>("Button");
map.generate();
// TODO: use this.Content to load your game content here
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
if (!isChose)
{
ChosePlayers();
}else
{
map.Update(gameTime);
}
base.Update(gameTime);
}
public void ChosePlayers()
{
KeyboardState keyboardState = Keyboard.GetState();
MouseState mouseState = Mouse.GetState();
if (mouseState.LeftButton == ButtonState.Pressed)
{
if (mouseState.Position.X > 300 && mouseState.Position.X < 480 && mouseState.Position.Y > 350 && mouseState.Position.Y < 380)
{
isChose = true;
playersNumb = 1;
IsMouseVisible = false;
}
else if(mouseState.Position.X > 600 && mouseState.Position.X < 780 && mouseState.Position.Y > 350 && mouseState.Position.Y < 380)
{
isChose = true;
playersNumb = 2;
IsMouseVisible = false;
}
}
if (isChose && playersNumb == 2)
{
map.players.Add(new Player(Content.Load<Texture2D>("Man"), new Point(3, 3)));
map.players.Add(new Player(Content.Load<Texture2D>("Second"), new Point(5, 4)));
(map.players[1] as Player).controller = new Controller(Keys.Left, Keys.Right, Keys.Up, Keys.Down, Keys.Enter);
}
else if (isChose && playersNumb == 1)
{
map.players.Add(new Player(Content.Load<Texture2D>("Man"), new Point(3, 3)));
}
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
if (!isChose)
{
spriteBatch.Draw(button, new Vector2(300, 350));
spriteBatch.Draw(button, new Vector2(600, 350));
spriteBatch.DrawString(mainFont, "1 player", new Vector2(360, 355), Color.Black);
spriteBatch.DrawString(mainFont, "2 players", new Vector2(660, 355), Color.Black);
}
else
{
map.Draw(spriteBatch);
}
// TODO: Add your drawing code here
spriteBatch.End();
base.Draw(gameTime);
}
}
}