-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrog.go
117 lines (93 loc) · 3.02 KB
/
rog.go
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
// Copyright 2012 Joseph Hager. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
Package rog provides algorithms and data structures for creating roguelike games.
*/
package rog
import "bytes"
var (
backend *glfwBackend
console *Console
timing *stats
)
// Open creates a window and a root console with size width by height cells.
func Open(width, height, zoom int, fs bool, title string, font *FontData) {
backend = new(glfwBackend)
console = NewConsole(width, height)
if font == nil {
font = ReadFont(bytes.NewBuffer(Terminal()), 16, 16, "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ✵웃世界¢¥¤§©¨«¬£ª±²³´¶·¸¹º»¼½¾¿☐☑═║╔╗╚╝╠╣╦╩╬░▒▓☺☻☼♀♂▀▁▂▃▄▅▆▇█ÐÑÒÓÔÕÖÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏØÙÚÛÜÝàáâãäåèéêëìíîïðñòóôõö÷ùúûüýÿ♥♦♣♠♪♬æçø←↑→↓↔↕®‼ꀥ")
}
backend.Open(width, height, zoom, fs, font)
backend.Name(title)
timing = NewStats()
}
// Running returns whether the rog window is open or not.
func Running() bool {
return backend.Running()
}
// Close shuts down the windowing system.
// No rog functions should be called after this.
func Close() {
backend.Close()
}
// SetTitle changes the title of the window.
func SetTitle(title string) {
backend.Name(title)
}
// Flush renders the root console to the window.
func Flush() {
backend.Render(console)
timing.Update()
}
// Mouse returns a struct representing the state of the mouse.
func Mouse() *MouseData {
return backend.Mouse()
}
// Cursor enables or disables the mouse cursor.
func Cursor(on bool) {
backend.Cursor(on)
}
// Key returns the last key typed this frame.
func Key() int {
return backend.Key()
}
// Dt returns length of the last frame in seconds.
func Dt() float64 {
return timing.Dt
}
// Fps returns the number of rendered frames per second.
func Fps() float64 {
return timing.Fps
}
func Blit(con *Console, x, y int) {
console.Blit(con, x, y)
}
// Set draws on the root console.
func Set(x, y int, fg, bg Blender, data string, rest ...interface{}) {
console.Set(x, y, fg, bg, data, rest...)
}
// Set draws on the root console with wrapping bounds of x, y, w, h.
func SetR(x, y, w, h int, fg, bg Blender, data string, rest ...interface{}) {
console.SetR(x, y, w, h, fg, bg, data, rest...)
}
// Get returns the fg, bg colors and rune of the cell on the root console.
func Get(x, y int) (RGB, RGB, rune) {
return console.Get(x, y)
}
// Fill draws a rect on the root console.
func Fill(x, y, w, h int, fg, bg Blender, ch rune) {
console.Fill(x, y, w, h, fg, bg, ch)
}
// Clear draws a rect over the entire root console.
func Clear(fg, bg Blender, ch rune) {
console.Clear(fg, bg, ch)
}
// Width returns the width of the root console in cells.
func Width() int {
return console.Width()
}
// Height returns the height of the root console in cells.
func Height() int {
return console.Height()
}