This repository was archived by the owner on Oct 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame1.cs
75 lines (66 loc) · 2.58 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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using mono2.src.mapping;
using mono2.src.entities.player;
using mono2.src.entities;
using mono2.src.models;
using mono2.src.models.mapping;
using System.Linq;
using System.Collections.Generic;
using System;
namespace mono2
{
public class Game1 : Game {
private static int tileDiameter = 16;
private static int bottomMenuHeight = 8 * tileDiameter;
private Size mapSize = new Size(64, 48);
private GraphicsDeviceManager graphics;
private SpriteBatch spriteBatch;
private TileMap map;
private PlayerController playerController;
private AiController monsterController;
private int framesSinceLastUpdate = 0;
public Game1() {
this.graphics = new GraphicsDeviceManager(this);
this.graphics.PreferredBackBufferWidth = (mapSize.width * tileDiameter);
this.graphics.PreferredBackBufferHeight = (mapSize.height * tileDiameter) + bottomMenuHeight;
this.Content.RootDirectory = "Content";
this.IsMouseVisible = true;
this.monsterController = new AiController(EntityType.Monster);
this.playerController = new PlayerController();
}
protected override void Initialize() {
map = new TileMap(tileDiameter, this.mapSize, this.Content, Color.Gray, new List<Entity>() { new Player(PlayerIndex.One, 5, 5, Color.OrangeRed), new Player(PlayerIndex.Two, 5, 6, Color.Teal) });
base.Initialize();
}
protected override void LoadContent() {
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime) {
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { // TODO gamepad support inside of player class
this.Exit();
}
if (framesSinceLastUpdate > 4) {
foreach (Entity entity in this.map.entities.ToList()) {
if (entity is Player) {
entity.setPos(this.playerController.getMove(this.map, (Player)entity, Keyboard.GetState()));
} else {
entity.setPos(this.monsterController.getMove(this.map, entity));
}
}
framesSinceLastUpdate = 0;
}
framesSinceLastUpdate++;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.Black);
this.spriteBatch.Begin();
this.map.drawMap(spriteBatch);
this.map.drawEntities(spriteBatch);
this.spriteBatch.End();
base.Draw(gameTime);
}
}
}