|
Revision 1, 3.6 kB
(checked in by krobillard, 3 years ago)
|
|
Import orca & thune.
|
| Line | |
|---|
| 1 | ORCA [ |
|---|
| 2 | Title: "Pong" |
|---|
| 3 | ] |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | task-list: make list! 32 |
|---|
| 7 | |
|---|
| 8 | state-machine: func [spec /local sm] [ |
|---|
| 9 | sm: context [ |
|---|
| 10 | state: none |
|---|
| 11 | ] |
|---|
| 12 | make sm spec |
|---|
| 13 | ] |
|---|
| 14 | |
|---|
| 15 | task: func [mach state] [ |
|---|
| 16 | mach/state: get in mach state |
|---|
| 17 | task-list: append task-list mach |
|---|
| 18 | ] |
|---|
| 19 | |
|---|
| 20 | run-tasks: does [ |
|---|
| 21 | foreach t task-list [do t/state] |
|---|
| 22 | ] |
|---|
| 23 | |
|---|
| 24 | ;----------------------------------------------------------------------------- |
|---|
| 25 | |
|---|
| 26 | ; 1 2 |
|---|
| 27 | ; 8 3 |
|---|
| 28 | ; 0 |
|---|
| 29 | ; 7 4 |
|---|
| 30 | ; 6 5 |
|---|
| 31 | |
|---|
| 32 | ball-gl: compile-gl [ |
|---|
| 33 | verts [ |
|---|
| 34 | 0 0 0 |
|---|
| 35 | -0.2 0.4 0 |
|---|
| 36 | 0.2 0.4 0 |
|---|
| 37 | 0.4 0.2 0 |
|---|
| 38 | 0.4 -0.2 0 |
|---|
| 39 | 0.2 -0.4 0 |
|---|
| 40 | -0.2 -0.4 0 |
|---|
| 41 | -0.4 -0.2 0 |
|---|
| 42 | -0.4 0.2 0 |
|---|
| 43 | ] |
|---|
| 44 | colors [ |
|---|
| 45 | 255.255.255 |
|---|
| 46 | 80.80.80 |
|---|
| 47 | ] |
|---|
| 48 | fan cv [ |
|---|
| 49 | 0 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 1 |
|---|
| 50 | ] |
|---|
| 51 | ] |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | paddle-gl: compile-gl [ |
|---|
| 55 | verts [ |
|---|
| 56 | -0.3 2.0 0 |
|---|
| 57 | 0.3 2.0 0 |
|---|
| 58 | 0.3 -2.0 0 |
|---|
| 59 | -0.3 -2.0 0 |
|---|
| 60 | ] |
|---|
| 61 | quads v [ |
|---|
| 62 | 0 1 2 3 |
|---|
| 63 | ] |
|---|
| 64 | ] |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | quad: compile-gl [ |
|---|
| 68 | verts [ |
|---|
| 69 | 0 0 0 |
|---|
| 70 | 0 1 0 |
|---|
| 71 | 1 1 0 |
|---|
| 72 | 1 0 0 |
|---|
| 73 | ] |
|---|
| 74 | colors [ |
|---|
| 75 | 255.0.0 |
|---|
| 76 | 0.255.0 |
|---|
| 77 | 0.0.255 |
|---|
| 78 | 128.128.128 |
|---|
| 79 | ] |
|---|
| 80 | ;quads cv [0 0 1 1 2 2 3 3] |
|---|
| 81 | quads v [0 1 2 3] |
|---|
| 82 | ] |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | ball: context [ |
|---|
| 86 | vel: <0 0 0> |
|---|
| 87 | pos: <0 0 0> |
|---|
| 88 | ] |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | player: context [ |
|---|
| 92 | pos: <0 0 0> |
|---|
| 93 | hold: false |
|---|
| 94 | im: none |
|---|
| 95 | ] |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | ;----------------------------------------------------------------------------- |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | player1: make player |
|---|
| 102 | [ |
|---|
| 103 | pos: <-10 0 0> |
|---|
| 104 | comment { |
|---|
| 105 | im: activate input-map [ |
|---|
| 106 | ppos/y [ |
|---|
| 107 | mouse-dy [input * 0.01 + ppos/y] |
|---|
| 108 | up on [ppos/y + 0.5] |
|---|
| 109 | down on [ppos/y - 0.5] |
|---|
| 110 | ] |
|---|
| 111 | hold [ |
|---|
| 112 | spc [true] |
|---|
| 113 | ] |
|---|
| 114 | ] |
|---|
| 115 | } |
|---|
| 116 | ] |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | player2: make player |
|---|
| 120 | [ |
|---|
| 121 | pos: <10 0 0> |
|---|
| 122 | ] |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | world-rp: render-prog #world-rp compose [ |
|---|
| 126 | push |
|---|
| 127 | scale 3 |
|---|
| 128 | |
|---|
| 129 | push |
|---|
| 130 | trans (ball/pos) |
|---|
| 131 | call (ball-gl) |
|---|
| 132 | pop |
|---|
| 133 | |
|---|
| 134 | push |
|---|
| 135 | trans (player1/pos) |
|---|
| 136 | 155.255.80 |
|---|
| 137 | call (paddle-gl) |
|---|
| 138 | pop |
|---|
| 139 | |
|---|
| 140 | push |
|---|
| 141 | trans (player2/pos) |
|---|
| 142 | 255.80.155 |
|---|
| 143 | call (paddle-gl) |
|---|
| 144 | pop |
|---|
| 145 | |
|---|
| 146 | pop |
|---|
| 147 | ] |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | comment { |
|---|
| 151 | ball-rp: render-prog #ball-rp compose [ |
|---|
| 152 | push |
|---|
| 153 | scale 3 |
|---|
| 154 | trans (ball/pos) |
|---|
| 155 | call (ball-gl) |
|---|
| 156 | pop |
|---|
| 157 | ] |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | paddleA-rp: render-prog #paddleA-rp compose [ |
|---|
| 161 | push |
|---|
| 162 | scale 3 |
|---|
| 163 | trans (player1/pos) |
|---|
| 164 | 155.255.80 |
|---|
| 165 | call (paddle-gl) |
|---|
| 166 | pop |
|---|
| 167 | ] |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | paddleB-rp: render-prog #paddleB-rp compose [ |
|---|
| 171 | push |
|---|
| 172 | scale 3 |
|---|
| 173 | trans (player2/pos) |
|---|
| 174 | 255.80.155 |
|---|
| 175 | call (paddle-gl) |
|---|
| 176 | pop |
|---|
| 177 | ] |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | scoreA: 13 |
|---|
| 184 | scoreB: 12 |
|---|
| 185 | ;scoreA-pos: 1x1 widget resize computes this |
|---|
| 186 | |
|---|
| 187 | scores-rp: render-prog #score-rp [ |
|---|
| 188 | 255.255.255 |
|---|
| 189 | ;pen :scoreA-pos |
|---|
| 190 | pen -280x-160 |
|---|
| 191 | text :scoreA |
|---|
| 192 | pen 280x-160 |
|---|
| 193 | text :scoreB |
|---|
| 194 | ] |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | pong-sm: state-machine [ |
|---|
| 198 | init: [ |
|---|
| 199 | print "INIT" |
|---|
| 200 | display/window 640x480 |
|---|
| 201 | clear-color 20.30.200 |
|---|
| 202 | ;tfont: make-texfont #tfont %data/arial.ttf 32 |
|---|
| 203 | sfont: make-texfont/glyphs #sfont %data/arial.ttf 40 "0123456789" |
|---|
| 204 | state: title |
|---|
| 205 | ] |
|---|
| 206 | |
|---|
| 207 | title: [ |
|---|
| 208 | print "TITLE" |
|---|
| 209 | ] |
|---|
| 210 | |
|---|
| 211 | menu: [ |
|---|
| 212 | ] |
|---|
| 213 | |
|---|
| 214 | play: [ |
|---|
| 215 | ] |
|---|
| 216 | |
|---|
| 217 | exit-query: [ |
|---|
| 218 | ] |
|---|
| 219 | ] |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | task pong-sm 'init |
|---|
| 223 | |
|---|
| 224 | ;probe task-list |
|---|
| 225 | run-tasks |
|---|
| 226 | |
|---|
| 227 | exec make widget [ |
|---|
| 228 | key-down: key-handler [ |
|---|
| 229 | esc [quit] |
|---|
| 230 | ] |
|---|
| 231 | |
|---|
| 232 | mouse-move: mouse-handler [ |
|---|
| 233 | print dy |
|---|
| 234 | ] |
|---|
| 235 | |
|---|
| 236 | ;resize: [ |
|---|
| 237 | ; scoreA-pos/x: width * 0.25 + left |
|---|
| 238 | ; scoreA-pos/y: bottom + 12 |
|---|
| 239 | ; scoreB-pos/x: width * 0.75 + left |
|---|
| 240 | ; scoreB-pos/y: bottom + 12 |
|---|
| 241 | ;] |
|---|
| 242 | |
|---|
| 243 | render: [ |
|---|
| 244 | ;run-tasks |
|---|
| 245 | |
|---|
| 246 | ortho-view self 100x100 none |
|---|
| 247 | render-state 'solid |
|---|
| 248 | call world-rp |
|---|
| 249 | ;call ball-rp |
|---|
| 250 | ;call paddleA-rp |
|---|
| 251 | ;call paddleB-rp |
|---|
| 252 | |
|---|
| 253 | ortho-view self none none |
|---|
| 254 | render-state sfont |
|---|
| 255 | call scores-rp |
|---|
| 256 | ] |
|---|
| 257 | ] |
|---|
| 258 | |
|---|
| 259 | ;eof |
|---|