Skip to content

Commit 884a252

Browse files
committed
Add unicode support
1 parent 46c67a7 commit 884a252

File tree

10 files changed

+236
-51
lines changed

10 files changed

+236
-51
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ NICO is a simple game framework for the [Nim](http://nim-lang.org/) programming
3737
* For web builds you'll need [Emscripten](https://emscripten.org/docs/getting_started/downloads.html).
3838
* From your project directory run ```nimble webr``` to build for web in release mode.
3939
* From your project directory run ```nimble webd``` to build for web in debug mode.
40+
* From your project directory run ```nimble runweb``` or ```emrun projectname.html ``` open browser run it.
4041

4142
## Learning
4243
* [API Documentation](API.md)

exampleApp/exampleApp.nimble

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ task runr, "Runs exampleApp for current platform":
2222
task rund, "Runs debug exampleApp for current platform":
2323
exec &"nim c -r {debugOpts} -o:exampleApp src/main.nim"
2424

25+
task runweb, "Runs web exampleApp for current platform":
26+
exec &"emrun exampleApp.html"
27+
2528
task release, "Builds exampleApp for current platform":
2629
exec &"nim c {releaseOpts} -o:exampleApp src/main.nim"
2730

examples/assets/ChillBitmap7x.png

109 KB
Loading

examples/assets/ChillBitmap7x.png.dat

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

examples/assets/quan.png

126 KB
Loading

examples/assets/quan.png.dat

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

examples/unicode.nim

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import nico
2+
3+
var messages = @[
4+
("English", "!\"#$%&'()*+,-./0123456789\n:;<=>?@abcdefghijklmnopqrstuvwxyz\n[\\]^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{}~"),
5+
("German", "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg"),
6+
("German", "Beiß nicht in die Hand, die dich füttert."),
7+
("German", "Außerordentliche Übel erfordern außerordentliche Mittel."),
8+
("Armenian", "Կրնամ ապակի ուտել և ինծի անհանգիստ չըներ"),
9+
("Armenian", "Երբ որ կացինը եկաւ անտառ, ծառերը ասացին... «Կոտը մերոնցից է:»"),
10+
("Armenian", "Գառը՝ գարնան, ձիւնը՝ ձմռան"),
11+
("Polish", "Jeżu klątw, spłódź Finom część gry hańb!"),
12+
("Polish", "Dobrymi chęciami jest piekło wybrukowane."),
13+
("Romanian", "Îți mulțumesc că ai ales nico.\nȘi sper să ai o zi bună!"),
14+
("Russian", "Эх, чужак, общий съём цен шляп (юфть) вдрызг!"),
15+
("Russian", "Я люблю nico!"),
16+
("Russian", "Молчи, скрывайся и таи\nИ чувства и мечты свои –\nПускай в душевной глубине\nИ всходят и зайдут оне\nКак звезды ясные в ночи-\nЛюбуйся ими – и молчи."),
17+
("French", "Voix ambiguë d’un cœur qui au zéphyr préfère les jattes de kiwi"),
18+
("Spanish", "Benjamín pidió una bebida de kiwi y fresa; Noé, sin vergüenza, la más exquisita champaña del menú."),
19+
("Greek", "Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός"),
20+
("Greek", "Η καλύτερη άμυνα είναι η επίθεση."),
21+
("Greek", "Χρόνια και ζαμάνια!"),
22+
("Greek", "Πώς τα πας σήμερα;"),
23+
("Chinese", "我能吞下玻璃而不伤身体。"),
24+
("Chinese", "你吃了吗?"),
25+
("Chinese", "不作不死。"),
26+
("Chinese", "最近好吗?"),
27+
("Chinese", "塞翁失马,焉知非福。"),
28+
("Chinese", "千军易得, 一将难求"),
29+
("Chinese", "万事开头难。"),
30+
("Chinese", "风无常顺,兵无常胜。"),
31+
("Chinese", "活到老,学到老。"),
32+
("Chinese", "一言既出,驷马难追。"),
33+
("Chinese", "路遥知马力,日久见人心"),
34+
("Chinese", "有理走遍天下,无理寸步难行。"),
35+
("Japanese", "猿も木から落ちる"),
36+
("Japanese", "亀の甲より年の功"),
37+
("Japanese", "うらやまし 思ひ切る時 猫の恋"),
38+
("Japanese", "虎穴に入らずんば虎子を得ず。"),
39+
("Japanese", "二兎を追う者は一兎をも得ず。"),
40+
("Japanese", "馬鹿は死ななきゃ治らない。"),
41+
("Japanese", "枯野路に 影かさなりて わかれけり"),
42+
("Japanese", "繰り返し麦の畝縫ふ胡蝶哉"),
43+
("Korean", "아득한 바다 위에 갈매기 두엇 날아 돈다.\n너훌너훌 시를 쓴다. 모르는 나라 글자다.\n널따란 하늘 복판에 나도 같이 시를 쓴다."),
44+
("Korean", "제 눈에 안경이다"),
45+
("Korean", "꿩 먹고 알 먹는다"),
46+
("Korean", "로마는 하루아침에 이루어진 것이 아니다"),
47+
("Korean", "고생 끝에 낙이 온다"),
48+
("Korean", "개천에서 용 난다"),
49+
("Korean", "안녕하세요?"),
50+
("Korean", "만나서 반갑습니다"),
51+
("Korean", "한국말 하실 줄 아세요?"),
52+
]
53+
54+
var langs = @[
55+
"quan.png",
56+
"ChillBitmap7x.png",
57+
"font.png"
58+
]
59+
var langIdx = 0
60+
proc gameInit() =
61+
for i in 0..<langs.len:
62+
loadFont(i, langs[i])
63+
64+
setWindowTitle("[ " & langs[langIdx][0..^5] & " ] font")
65+
discard
66+
67+
var iFrame: int
68+
var isPrintr: bool
69+
proc gameUpdate(dt: float32) =
70+
if keyp(K_ESCAPE): shutdown()
71+
if keyp(K_SPACE) or iFrame > 1000:
72+
langIdx.inc
73+
if langIdx >= langs.len:
74+
isPrintr = not isPrintr
75+
langIdx = langIdx mod langs.len
76+
iFrame = 0
77+
setFont(langIdx)
78+
setWindowTitle("[ " & langs[langIdx][0..^5] & " ] font")
79+
iFrame.inc
80+
discard
81+
82+
import strformat
83+
proc gameDraw() =
84+
cls()
85+
var
86+
rcolor {.global.} = rnd(1, 15)
87+
scale {.global.} = 1
88+
block unicode:
89+
#break
90+
var
91+
color = rcolor
92+
h,i = 0
93+
if iFrame < 2: rcolor = rnd(1, 15)
94+
for (language, msg) in messages:
95+
if h > screenHeight:
96+
cls()
97+
h = 0
98+
setColor(color)
99+
if not isPrintr:
100+
print(&"{language}: {msg}", 0, h, scale)
101+
else:
102+
printr(&"{language}: {msg}", screenWidth, h, scale)
103+
h += msg.textHeight(scale)
104+
color.inc
105+
color = color mod 15 + 1 # rnd(1,16)
106+
i.inc
107+
if i > iFrame div 20: break
108+
discard
109+
110+
setColor(6)
111+
printr(&"frame: {iFrame}", screenWidth, screenHeight - fontHeight())
112+
printr("font: " & langs[langIdx][0..^5], screenWidth, screenHeight - fontHeight() * 2 * scale - scale)
113+
discard
114+
115+
nico.init("nico", "unicode test")
116+
nico.createWindow("nico", 384, 384, 2, false)
117+
fixedSize(true)
118+
integerScale(true)
119+
nico.run(gameInit, gameUpdate, gameDraw)

0 commit comments

Comments
 (0)