Mercurial > games > semicongine
comparison tests/test_font.nim @ 888:cbbb9abe256e
add: nicer key-stroke test, cleanup test-resource files
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 03 Feb 2024 23:03:34 +0700 |
parents | 604f1e7be026 |
children | 740d2f0d1264 |
comparison
equal
deleted
inserted
replaced
887:604f1e7be026 | 888:cbbb9abe256e |
---|---|
23 F5: Center | 23 F5: Center |
24 F6: Bottom""", scale = 0.0002, position = newVec2f(0, 0), horizontalAlignment = Left, verticalAlignment = Top) | 24 F6: Bottom""", scale = 0.0002, position = newVec2f(0, 0), horizontalAlignment = Left, verticalAlignment = Top) |
25 scene.add main_text | 25 scene.add main_text |
26 scene.add help_text | 26 scene.add help_text |
27 engine.loadScene(scene) | 27 engine.loadScene(scene) |
28 mixer[].loadSound("key", "key.ogg") | |
28 | 29 |
29 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | 30 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
30 if engine.windowWasResized(): | 31 if engine.windowWasResized(): |
31 var winSize = engine.getWindow().size | 32 var winSize = engine.getWindow().size |
32 main_text.aspect_ratio = winSize[0] / winSize[1] | 33 main_text.aspect_ratio = winSize[0] / winSize[1] |
37 if main_text.text.len < main_text.maxLen - 1: | 38 if main_text.text.len < main_text.maxLen - 1: |
38 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, | 39 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, |
39 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, | 40 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, |
40 Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]: | 41 Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]: |
41 if engine.keyWasPressed(c): | 42 if engine.keyWasPressed(c): |
43 discard mixer[].play("key") | |
42 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): | 44 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): |
43 main_text.text = main_text.text & ($c).toRunes | 45 main_text.text = main_text.text & ($c).toRunes |
44 else: | 46 else: |
45 main_text.text = main_text.text & ($c).toRunes[0].toLower() | 47 main_text.text = main_text.text & ($c).toRunes[0].toLower() |
46 if engine.keyWasPressed(Enter): | 48 if engine.keyWasPressed(Enter): |
49 discard mixer[].play("key") | |
47 main_text.text = main_text.text & Rune('\n') | 50 main_text.text = main_text.text & Rune('\n') |
48 if engine.keyWasPressed(Space): | 51 if engine.keyWasPressed(Space): |
52 discard mixer[].play("key") | |
49 main_text.text = main_text.text & Rune(' ') | 53 main_text.text = main_text.text & Rune(' ') |
50 | 54 |
51 # remove character | 55 # remove character |
52 if engine.keyWasPressed(Backspace) and main_text.text.len > 0: | 56 if engine.keyWasPressed(Backspace) and main_text.text.len > 0: |
57 discard mixer[].play("key") | |
53 main_text.text = main_text.text[0 ..< ^1] | 58 main_text.text = main_text.text[0 ..< ^1] |
54 | 59 |
55 # alignemtn with F-keys | 60 # alignemtn with F-keys |
56 if engine.keyWasPressed(F1): main_text.horizontalAlignment = Left | 61 if engine.keyWasPressed(F1): main_text.horizontalAlignment = Left |
57 elif engine.keyWasPressed(F2): main_text.horizontalAlignment = Center | 62 elif engine.keyWasPressed(F2): main_text.horizontalAlignment = Center |