c - Opengl make "AI" paddle move up and down -


i'm bit of opengl/programming noobie i'm trying make "ai" right paddle. know isnt proper way of doing it, should doing making follow ball. right i'm trying make perpetually move , down. can't figure out how it, trying use if loops like

if (paddle.pos[1] > 1){ paddle.pos[1] = paddle.pos[1] - delta}

i set delta 0.01, 1 top of screen. isnt right because goes down below 1 goes again, i'm trying it.

2nd question - how move ball 0,0 when starts? kind of same problem, using if statements x values thats not right.

this using c way.

try make pos repeatedly go 0 1 , 0:

// initialize. float pos = 0.0f; float delta = 0.01f;  // on every update. pos += delta; if (pos > 1.0f) {     pos = 1.0f;     delta = -delta; } else if (pos < 0.0f) {     pos = 0.0f;     delta = -delta; } 

the key here invert sign of increment each time reach 1 of end positions.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -