Mercurial > games > semicongine
comparison tests/test_font.nim @ 1021:73b572f82a1f
add: bases for a better input-system
author | sam <sam@basx.dev> |
---|---|
date | Thu, 09 May 2024 23:02:35 +0700 |
parents | 6406766a222d |
children | 74957cbf589b |
comparison
equal
deleted
inserted
replaced
1020:355ef428b5f4 | 1021:73b572f82a1f |
---|---|
29 scene.add help_text | 29 scene.add help_text |
30 engine.loadScene(scene) | 30 engine.loadScene(scene) |
31 mixer[].loadSound("key", "key.ogg") | 31 mixer[].loadSound("key", "key.ogg") |
32 mixer[].setLevel(0.5) | 32 mixer[].setLevel(0.5) |
33 | 33 |
34 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): | 34 while engine.updateInputs() and not keyIsDown(Escape): |
35 var t = cpuTime() | 35 var t = cpuTime() |
36 main_text.color = newVec4f(sin(t) * 0.5 + 0.5, 0.15, 0.15, 1) | 36 main_text.color = newVec4f(sin(t) * 0.5 + 0.5, 0.15, 0.15, 1) |
37 if engine.windowWasResized(): | 37 if windowWasResized(): |
38 var winSize = engine.getWindow().size | 38 var winSize = engine.getWindow().size |
39 | 39 |
40 # add character | 40 # add character |
41 if main_text.text.len < main_text.maxLen - 1: | 41 if main_text.text.len < main_text.maxLen - 1: |
42 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, | 42 for c in [Key.A, Key.B, Key.C, Key.D, Key.E, Key.F, Key.G, Key.H, Key.I, |
43 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, | 43 Key.J, Key.K, Key.L, Key.M, Key.N, Key.O, Key.P, Key.Q, Key.R, Key.S, |
44 Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]: | 44 Key.T, Key.U, Key.V, Key.W, Key.X, Key.Y, Key.Z]: |
45 if engine.keyWasPressed(c): | 45 if keyWasPressed(c): |
46 discard mixer[].play("key") | 46 discard mixer[].play("key") |
47 if engine.keyIsDown(ShiftL) or engine.keyIsDown(ShiftR): | 47 if keyIsDown(ShiftL) or keyIsDown(ShiftR): |
48 main_text.text = main_text.text & ($c).toRunes | 48 main_text.text = main_text.text & ($c).toRunes |
49 else: | 49 else: |
50 main_text.text = main_text.text & ($c).toRunes[0].toLower() | 50 main_text.text = main_text.text & ($c).toRunes[0].toLower() |
51 if engine.keyWasPressed(Enter): | 51 if keyWasPressed(Enter): |
52 discard mixer[].play("key") | 52 discard mixer[].play("key") |
53 main_text.text = main_text.text & Rune('\n') | 53 main_text.text = main_text.text & Rune('\n') |
54 if engine.keyWasPressed(Space): | 54 if keyWasPressed(Space): |
55 discard mixer[].play("key") | 55 discard mixer[].play("key") |
56 main_text.text = main_text.text & Rune(' ') | 56 main_text.text = main_text.text & Rune(' ') |
57 | 57 |
58 # remove character | 58 # remove character |
59 if engine.keyWasPressed(Backspace) and main_text.text.len > 0: | 59 if keyWasPressed(Backspace) and main_text.text.len > 0: |
60 discard mixer[].play("key") | 60 discard mixer[].play("key") |
61 main_text.text = main_text.text[0 ..< ^1] | 61 main_text.text = main_text.text[0 ..< ^1] |
62 | 62 |
63 # alignemtn with F-keys | 63 # alignemtn with F-keys |
64 if engine.keyWasPressed(F1): main_text.horizontalAlignment = Left | 64 if keyWasPressed(F1): main_text.horizontalAlignment = Left |
65 elif engine.keyWasPressed(F2): main_text.horizontalAlignment = Center | 65 elif keyWasPressed(F2): main_text.horizontalAlignment = Center |
66 elif engine.keyWasPressed(F3): main_text.horizontalAlignment = Right | 66 elif keyWasPressed(F3): main_text.horizontalAlignment = Right |
67 elif engine.keyWasPressed(F4): main_text.verticalAlignment = Top | 67 elif keyWasPressed(F4): main_text.verticalAlignment = Top |
68 elif engine.keyWasPressed(F5): main_text.verticalAlignment = Center | 68 elif keyWasPressed(F5): main_text.verticalAlignment = Center |
69 elif engine.keyWasPressed(F6): main_text.verticalAlignment = Bottom | 69 elif keyWasPressed(F6): main_text.verticalAlignment = Bottom |
70 | 70 |
71 origin.refresh() | 71 origin.refresh() |
72 main_text.text = main_text.text & Rune('_') | 72 main_text.text = main_text.text & Rune('_') |
73 main_text.refresh() | 73 main_text.refresh() |
74 main_text.text = main_text.text[0 ..< ^1] | 74 main_text.text = main_text.text[0 ..< ^1] |