Mercurial > games > semicongine
comparison examples/E04_input.nim @ 1136:71315636ba82
did: refactor naming in tons of places
author | sam <sam@basx.dev> |
---|---|
date | Tue, 04 Jun 2024 16:51:50 +0700 |
parents | d6c27f0ed3e4 |
children | 114f395b9144 |
comparison
equal
deleted
inserted
replaced
1135:74957cbf589b | 1136:71315636ba82 |
---|---|
5 | 5 |
6 import ../semicongine | 6 import ../semicongine |
7 | 7 |
8 const | 8 const |
9 arrow = @[ | 9 arrow = @[ |
10 newVec3f(-1, -1), | 10 NewVec3f(-1, -1), |
11 newVec3f(1, -1), | 11 NewVec3f(1, -1), |
12 newVec3f(-0.3, -0.3), | 12 NewVec3f(-0.3, -0.3), |
13 newVec3f(-0.3, -0.3), | 13 NewVec3f(-0.3, -0.3), |
14 newVec3f(-1, 1), | 14 NewVec3f(-1, 1), |
15 newVec3f(-1, -1), | 15 NewVec3f(-1, -1), |
16 ] | 16 ] |
17 # keyboard layout, specifying rows with key widths, negative numbers are empty spaces | 17 # keyboard layout, specifying rows with key widths, negative numbers are empty spaces |
18 keyrows = ( | 18 keyrows = ( |
19 [1.0, -0.6, 1.0, 1.0, 1.0, 1.0, -0.5, 1.0, 1.0, 1.0, 1.0, -0.5, 1.0, 1.0, 1.0, 1.0, -0.1, 1.0, 1.0, 1.0], | 19 [1.0, -0.6, 1.0, 1.0, 1.0, 1.0, -0.5, 1.0, 1.0, 1.0, 1.0, -0.5, 1.0, 1.0, 1.0, 1.0, -0.1, 1.0, 1.0, 1.0], |
20 [1.2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.8, -0.1, 1.0, 1.0, 1.0], | 20 [1.2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.8, -0.1, 1.0, 1.0, 1.0], |
23 [2.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.8, -1.3, 1.0], | 23 [2.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.8, -1.3, 1.0], |
24 [1.5, 1.5, 1.5, 6, 1.5, 1.5, -1.2, 1.5, -0.1, 1.0, 1.0, 1.0], | 24 [1.5, 1.5, 1.5, 6, 1.5, 1.5, -1.2, 1.5, -0.1, 1.0, 1.0, 1.0], |
25 ) | 25 ) |
26 keyDimension = 50'f32 | 26 keyDimension = 50'f32 |
27 keyGap = 10'f32 | 27 keyGap = 10'f32 |
28 backgroundColor = newVec4f(0.6705882352941176, 0.6078431372549019, 0.5882352941176471, 1) | 28 backgroundColor = NewVec4f(0.6705882352941176, 0.6078431372549019, 0.5882352941176471, 1) |
29 baseColor = newVec4f(0.9411764705882353, 0.9058823529411765, 0.8470588235294118, 1) | 29 baseColor = NewVec4f(0.9411764705882353, 0.9058823529411765, 0.8470588235294118, 1) |
30 activeColor = newVec4f(0.6509803921568628, 0.22745098039215686, 0.3137254901960784, 1) | 30 activeColor = NewVec4f(0.6509803921568628, 0.22745098039215686, 0.3137254901960784, 1) |
31 arrow_colors = @[ | 31 arrow_colors = @[ |
32 baseColor * 0.9'f32, | 32 baseColor * 0.9'f32, |
33 baseColor * 0.9'f32, | 33 baseColor * 0.9'f32, |
34 baseColor * 0.9'f32, | 34 baseColor * 0.9'f32, |
35 baseColor * 0.8'f32, | 35 baseColor * 0.8'f32, |
59 var | 59 var |
60 scene: Scene | 60 scene: Scene |
61 keyvertexpos: seq[Vec3f] | 61 keyvertexpos: seq[Vec3f] |
62 keyvertexcolor: seq[Vec4f] | 62 keyvertexcolor: seq[Vec4f] |
63 keymeshindices: seq[array[3, uint16]] | 63 keymeshindices: seq[array[3, uint16]] |
64 rowpos = newVec2f(0, 0) | 64 rowpos = NewVec2f(0, 0) |
65 i = 0'u16 | 65 i = 0'u16 |
66 firstRow = true | 66 firstRow = true |
67 rowWidth = 0'f32 | 67 rowWidth = 0'f32 |
68 for row in keyrows.fields: | 68 for row in keyrows.fields: |
69 for key in row: | 69 for key in row: |
70 let keySpace = float32(keyDimension * key) | 70 let keySpace = float32(keyDimension * key) |
71 if key > 0: | 71 if key > 0: |
72 if keyIndices[i div 4] == Enter: | 72 if keyIndices[i div 4] == Enter: |
73 keyvertexpos.add newVec3f(rowpos[0], rowpos[1] - keyDimension - keyGap) | 73 keyvertexpos.add NewVec3f(rowpos[0], rowpos[1] - keyDimension - keyGap) |
74 keyvertexpos.add newVec3f(rowpos[0] + keySpace, rowpos[1] - keyDimension - keyGap) | 74 keyvertexpos.add NewVec3f(rowpos[0] + keySpace, rowpos[1] - keyDimension - keyGap) |
75 else: | 75 else: |
76 keyvertexpos.add newVec3f(rowpos[0], rowpos[1]) | 76 keyvertexpos.add NewVec3f(rowpos[0], rowpos[1]) |
77 keyvertexpos.add newVec3f(rowpos[0] + keySpace, rowpos[1]) | 77 keyvertexpos.add NewVec3f(rowpos[0] + keySpace, rowpos[1]) |
78 keyvertexpos.add newVec3f(rowpos[0] + keySpace, rowpos[1] + keyDimension) | 78 keyvertexpos.add NewVec3f(rowpos[0] + keySpace, rowpos[1] + keyDimension) |
79 keyvertexpos.add newVec3f(rowpos[0], rowpos[1] + keyDimension) | 79 keyvertexpos.add NewVec3f(rowpos[0], rowpos[1] + keyDimension) |
80 keyvertexcolor.add [baseColor, baseColor, baseColor, baseColor] | 80 keyvertexcolor.add [baseColor, baseColor, baseColor, baseColor] |
81 keymeshindices.add [i, i + 1, i + 2] | 81 keymeshindices.add [i, i + 1, i + 2] |
82 keymeshindices.add [i + 2, i + 3, i] | 82 keymeshindices.add [i + 2, i + 3, i] |
83 rowpos[0] += keySpace + keyGap | 83 rowpos[0] += keySpace + keyGap |
84 i += 4 | 84 i += 4 |
102 scale2d(0.5'f32, 1'f32) * | 102 scale2d(0.5'f32, 1'f32) * |
103 rotate2d(float32(PI) / 4'f32) | 103 rotate2d(float32(PI) / 4'f32) |
104 ) | 104 ) |
105 var positions = arrow | 105 var positions = arrow |
106 for i in 0 ..< positions.len: | 106 for i in 0 ..< positions.len: |
107 positions[i] = cursorscale * newVec3f(positions[i].x, positions[i].y) | 107 positions[i] = cursorscale * NewVec3f(positions[i].x, positions[i].y) |
108 | 108 |
109 # define mesh objects | 109 # define mesh objects |
110 var | 110 var |
111 matDef = MaterialType(name: "default", vertexAttributes: { | 111 matDef = MaterialType(name: "default", vertexAttributes: { |
112 "position": Vec3F32, | 112 "position": Vec3F32, |
123 indices = keymeshindices, | 123 indices = keymeshindices, |
124 material = matDef.initMaterialData(), | 124 material = matDef.initMaterialData(), |
125 ) | 125 ) |
126 backgroundmesh = newMesh( | 126 backgroundmesh = newMesh( |
127 positions = @[ | 127 positions = @[ |
128 newVec3f(0'f32, 0'f32), | 128 NewVec3f(0'f32, 0'f32), |
129 newVec3f(1'f32, 0'f32), | 129 NewVec3f(1'f32, 0'f32), |
130 newVec3f(1'f32, 1'f32), | 130 NewVec3f(1'f32, 1'f32), |
131 newVec3f(0'f32, 1'f32), | 131 NewVec3f(0'f32, 1'f32), |
132 ], | 132 ], |
133 colors = @[ | 133 colors = @[ |
134 backgroundColor, | 134 backgroundColor, |
135 backgroundColor, | 135 backgroundColor, |
136 backgroundColor, | 136 backgroundColor, |