Mercurial > hg > beaglert
comparison examples/tank_wars/render.cpp @ 311:493a07f6ec09 prerelease
Renamed BelaContext->audioSampleCount to BelaContext->audioFramesElapsed for consistency of terminology
author | andrewm |
---|---|
date | Fri, 27 May 2016 18:37:51 +0100 |
parents | 421a69d42943 |
children | 9dc5a0ccad25 |
comparison
equal
deleted
inserted
replaced
310:02c4ca0e3718 | 311:493a07f6ec09 |
---|---|
200 context->audioOut[2*audioIndex] = context->audioOut[2*audioIndex + 1] = audioSample; | 200 context->audioOut[2*audioIndex] = context->audioOut[2*audioIndex + 1] = audioSample; |
201 audioIndex++; | 201 audioIndex++; |
202 } | 202 } |
203 | 203 |
204 // First-order lowpass filter to remove noise on launch FSR | 204 // First-order lowpass filter to remove noise on launch FSR |
205 float rawSample = analogReadFrame(context, n, gInputLauncher); | 205 float rawSample = analogRead(context, n, gInputLauncher); |
206 float launchSample = gLauncherFilterPole * gLauncherLastSample + | 206 float launchSample = gLauncherFilterPole * gLauncherLastSample + |
207 (1.0f - gLauncherFilterPole) * rawSample; | 207 (1.0f - gLauncherFilterPole) * rawSample; |
208 gLauncherLastSample = launchSample; | 208 gLauncherLastSample = launchSample; |
209 | 209 |
210 // Peak-detect on launch signal | 210 // Peak-detect on launch signal |
234 | 234 |
235 if(--gSamplesUntilNextFrame <= 0) { | 235 if(--gSamplesUntilNextFrame <= 0) { |
236 // Update game physics and cannon angles | 236 // Update game physics and cannon angles |
237 gSamplesUntilNextFrame = gGameFrameInterval; | 237 gSamplesUntilNextFrame = gGameFrameInterval; |
238 | 238 |
239 setTank1CannonAngle(map(analogReadFrame(context, n, gInputTank1Angle), | 239 setTank1CannonAngle(map(analogRead(context, n, gInputTank1Angle), |
240 0, 1.0, M_PI, 0)); | 240 0, 1.0, M_PI, 0)); |
241 setTank2CannonAngle(map(analogReadFrame(context, n, gInputTank2Angle), | 241 setTank2CannonAngle(map(analogRead(context, n, gInputTank2Angle), |
242 0, 1.0, M_PI, 0)); | 242 0, 1.0, M_PI, 0)); |
243 nextGameFrame(); | 243 nextGameFrame(); |
244 | 244 |
245 // Check for collision and start sound accordingly | 245 // Check for collision and start sound accordingly |
246 if(gameStatusCollisionOccurred()) { | 246 if(gameStatusCollisionOccurred()) { |
263 float x = gScreenBufferRead[gScreenBufferReadPointer++]; | 263 float x = gScreenBufferRead[gScreenBufferReadPointer++]; |
264 float y = gScreenBufferRead[gScreenBufferReadPointer++]; | 264 float y = gScreenBufferRead[gScreenBufferReadPointer++]; |
265 | 265 |
266 // Rescale screen coordinates to matrix ranges; invert the Y | 266 // Rescale screen coordinates to matrix ranges; invert the Y |
267 // coordinate to go from normal screen coordinates to scope coordinates | 267 // coordinate to go from normal screen coordinates to scope coordinates |
268 analogWriteFrameOnce(context, n, gOutputX, constrain(map(x, 0, gScreenWidth, 0, 1.0), 0, 1.0)); | 268 analogWriteOnce(context, n, gOutputX, constrain(map(x, 0, gScreenWidth, 0, 1.0), 0, 1.0)); |
269 analogWriteFrameOnce(context, n, gOutputY, constrain(map(y, 0, gScreenHeight, 1.0, 0), 0, 1.0)); | 269 analogWriteOnce(context, n, gOutputY, constrain(map(y, 0, gScreenHeight, 1.0, 0), 0, 1.0)); |
270 } | 270 } |
271 else { | 271 else { |
272 // Still not ready! Write 0 until something happens | 272 // Still not ready! Write 0 until something happens |
273 analogWriteFrameOnce(context, n, gOutputX, 0); | 273 analogWriteOnce(context, n, gOutputX, 0); |
274 analogWriteFrameOnce(context, n, gOutputY, 0); | 274 analogWriteOnce(context, n, gOutputY, 0); |
275 } | 275 } |
276 | 276 |
277 if(gameStatusWinner() != 0) { | 277 if(gameStatusWinner() != 0) { |
278 // Blink one LED to show who won | 278 // Blink one LED to show who won |
279 // Blink both LEDs when projectile is in motion | 279 // Blink both LEDs when projectile is in motion |
280 float val = (gSampleCounter % 4000 > 2000) ? 1.0 : 0; | 280 float val = (gSampleCounter % 4000 > 2000) ? 1.0 : 0; |
281 analogWriteFrameOnce(context, n, gOutputPlayer1LED, gameStatusWinner() == 1 ? val : 0); | 281 analogWriteOnce(context, n, gOutputPlayer1LED, gameStatusWinner() == 1 ? val : 0); |
282 analogWriteFrameOnce(context, n, gOutputPlayer2LED, gameStatusWinner() == 2 ? val : 0); | 282 analogWriteOnce(context, n, gOutputPlayer2LED, gameStatusWinner() == 2 ? val : 0); |
283 | 283 |
284 // After 5 seconds, restart the game | 284 // After 5 seconds, restart the game |
285 gSamplesSinceFinish++; | 285 gSamplesSinceFinish++; |
286 if(gSamplesSinceFinish > 22050*5) | 286 if(gSamplesSinceFinish > 22050*5) |
287 gGameShouldRestart = true; | 287 gGameShouldRestart = true; |
288 } | 288 } |
289 else if(gameStatusProjectileInMotion()) { | 289 else if(gameStatusProjectileInMotion()) { |
290 // Blink both LEDs when projectile is in motion | 290 // Blink both LEDs when projectile is in motion |
291 float val = (gSampleCounter % 2000 > 1000) ? 1.0 : 0; | 291 float val = (gSampleCounter % 2000 > 1000) ? 1.0 : 0; |
292 analogWriteFrameOnce(context, n, gOutputPlayer1LED, val); | 292 analogWriteOnce(context, n, gOutputPlayer1LED, val); |
293 analogWriteFrameOnce(context, n, gOutputPlayer2LED, val); | 293 analogWriteOnce(context, n, gOutputPlayer2LED, val); |
294 } | 294 } |
295 else if(gameStatusPlayer1Turn()) { | 295 else if(gameStatusPlayer1Turn()) { |
296 analogWriteFrameOnce(context, n, gOutputPlayer1LED, 1.0); | 296 analogWriteOnce(context, n, gOutputPlayer1LED, 1.0); |
297 analogWriteFrameOnce(context, n, gOutputPlayer2LED, 0); | 297 analogWriteOnce(context, n, gOutputPlayer2LED, 0); |
298 } | 298 } |
299 else { | 299 else { |
300 analogWriteFrameOnce(context, n, gOutputPlayer2LED, 1.0); | 300 analogWriteOnce(context, n, gOutputPlayer2LED, 1.0); |
301 analogWriteFrameOnce(context, n, gOutputPlayer1LED, 0); | 301 analogWriteOnce(context, n, gOutputPlayer1LED, 0); |
302 } | 302 } |
303 | 303 |
304 // Check if we have reached the point where we should next update | 304 // Check if we have reached the point where we should next update |
305 if(gScreenBufferReadPointer >= gScreenBufferNextUpdateLocation && | 305 if(gScreenBufferReadPointer >= gScreenBufferNextUpdateLocation && |
306 !gScreenNextBufferReady) { | 306 !gScreenNextBufferReady) { |