-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.cs
More file actions
144 lines (125 loc) · 3.91 KB
/
IO.cs
File metadata and controls
144 lines (125 loc) · 3.91 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
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
using SDL2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace BootlegTetris
{
class IO
{
static IntPtr window = SDL.SDL_CreateWindow(
"Tetris .NET Prototype",
SDL.SDL_WINDOWPOS_UNDEFINED,
SDL.SDL_WINDOWPOS_UNDEFINED,
648,
324,
SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN);
static IntPtr renderer = SDL.SDL_CreateRenderer(
window,
-1,
SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED |
SDL.SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);
public enum Color
{
BLACK,
RED,
GREEN,
BLUE,
CYAN,
MAGENTA,
YELLOW,
WHITE,
COLOR_MAX
}
static UInt32[] mColors = new UInt32[(int)Color.COLOR_MAX]
{
4278190080u,
4294901760u,
4278222848u,
4278190335u,
4278255615u,
4294902015u,
4294967040u,
4294967295u
};
public IO()
{
Initgraph();
}
public void ClearScreen()
{
SDL_gfx.boxColor(renderer, 0, 0, 702, 324, mColors[(int) Color.WHITE]);
}
public void DrawRectangle(int pX1, int pY1, int pX2, int pY2, Color pC)
{
SDL_gfx.boxColor(renderer, Convert.ToInt16(pX1), Convert.ToInt16(pY1), Convert.ToInt16(pX2), Convert.ToInt16(pY2 - 1), mColors[(int)pC]);
}
public int GetScreenHeight()
{
return 324;
}
public void UpdateScreen()
{
SDL.SDL_RenderPresent(renderer);
}
public int Pollkey()
{
SDL.SDL_Event _event;
while (SDL.SDL_PollEvent(out _event) == 1)
{
switch (_event.type)
{
case SDL.SDL_EventType.SDL_KEYDOWN:
return (int) _event.key.keysym.sym;
case SDL.SDL_EventType.SDL_QUIT:
return 0;
}
}
return -1;
}
public int Getkey()
{
SDL.SDL_Event _event;
while (true)
{
SDL.SDL_WaitEvent(out _event);
if (_event.type == SDL.SDL_EventType.SDL_KEYDOWN)
{
break;
}
if (_event.type == SDL.SDL_EventType.SDL_QUIT)
{
return 0;
}
}
return (int) _event.key.keysym.sym;
}
public unsafe int IsKeyDown(int pKey)
{
byte* mKeytable;
int mNumkeys = new int();
SDL.SDL_PumpEvents();
mKeytable = (byte*) SDL.SDL_GetKeyboardState(out mNumkeys);
return mKeytable[pKey];
}
public int Initgraph()
{
if ( SDL.SDL_Init(SDL.SDL_INIT_VIDEO) < 0 )
{
Console.WriteLine($"There was an issue initializing SDL. {SDL.SDL_GetError()}");
return 1;
}
if (window == IntPtr.Zero)
{
Console.WriteLine($"There was an issue creating the window. {SDL.SDL_GetError()}");
}
if (renderer == IntPtr.Zero)
{
Console.WriteLine($"There was an issue creating the renderer. {SDL.SDL_GetError()}");
}
return 0;
}
}
}