-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
173 lines (145 loc) · 4.94 KB
/
Form1.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TFAGame.UI;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
namespace TFAGame
{
public partial class Form1 : Form
{
public Graphics graphics = null;
private GameGenerator gGen = null;
private Timer drawScreen = new Timer();
private bool bOpenGLReady = false;
public Form1()
{
InitializeComponent();
Config.InitializeSettings();
//Put graphics here
DoubleBuffered = true;
Text = "The Footman Adventure";
Size = new Size(800, 650);
gGen = new GameGenerator();
GameCore.Size = Size;
GameCore.gGen = gGen;
drawScreen.Tick += new EventHandler(drawScreen_Tick);
drawScreen.Interval = 30;
drawScreen.Start();
GameCore.SetupGCMode();
//GameCore = new GameCore();
}
void drawScreen_Tick(object sender, EventArgs e)
{
glControl.Invalidate();
}
private void start_game_Click(object sender, EventArgs e)
{
}
private void end_game_Click(object sender, EventArgs e)
{
}
private void host_game_Click(object sender, EventArgs e)
{
}
private void GLScreen_Load(object sender, EventArgs e)
{
bOpenGLReady = true;
SetupViewport();
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.Disable(EnableCap.DepthTest);
GameCore.CoreFiles = new Memory();
GameObject Grass = new GameObject(GameObject.Type.Grass);
int MaxX = Size.Width / TextureItem.RatioSize;
int MaxY = Size.Height / TextureItem.RatioSize;
GameCore.GrassPatches = new GameObject[MaxX * MaxY];
int i = 0;
for (int x = 0; x < MaxX; x++)
{
for (int y = 0; y < MaxY; y++)
{
GameCore.GrassPatches[i] = new GameObject(GameObject.Type.Grass);
GameCore.GrassPatches[i].X = x * TextureItem.RatioSize;
GameCore.GrassPatches[i].Y = y * TextureItem.RatioSize;
i++;
}
}
GameCore.SetupModules();
}
private void GLScreen_Paint(object sender, PaintEventArgs e)
{
if (!bOpenGLReady)
return;
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Color4(Color.White);
GL.LoadIdentity();
GL.Translate(0, 0, 0);
for (int i = 0; i < GameCore.GrassPatches.Length; i++)
GameCore.GrassPatches[i].DrawObject(true);
GL.PushMatrix();
ShouldTranslate();
GameCore.DrawPlayers();
GameCore.DrawStatusBars();
GL.PopMatrix();
GameCore.DrawUI(800, 600);
//GL.Flush();
glControl.SwapBuffers();
}
bool FirstLoad = true;
public void ShouldTranslate()
{
GL.Translate(3, 3, 0);
//if (FirstLoad)
//{
// GL.Translate(3, 3, 0);
// FirstLoad = false;
//}
}
private void LoadGrassTexture()
{
}
private void GLScreen_Resize(object sender, EventArgs e)
{
if (!bOpenGLReady)
return;
SetupViewport();
}
private void SetupViewport()
{
int w = glControl.Width;
int h = glControl.Height;
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0, w, h, 0, -1, 1); // Bottom-left corner pixel has coordinate (0, 0)
GL.Viewport(0, 0, w, h); // Use all of the glControl painting area
GL.MatrixMode(MatrixMode.Modelview);
}
private void glControl_KeyDown(object sender, KeyEventArgs e)
{
}
private void glControl_MouseDown(object sender, MouseEventArgs e)
{
if (ModuleHandler._CoreModules.Keys.Contains("UITextures"))
{
CoreModule coreModule = null;
ModuleHandler._CoreModules.TryGetValue("UITextures", out coreModule);
UICore coreMod = (UICore)coreModule;
coreMod.OnClick(e.X, e.Y);
}
GameCore.MouseDown(e.X, e.Y);
}
private void glControl_KeyUp(object sender, KeyEventArgs e)
{
GameCore.KeyUp(e);
}
}
}