randomize ball launch velocity
This commit is contained in:
parent
5299fa66af
commit
e4b69704ab
@ -6,7 +6,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void launch_ball(struct game_state * state);
|
void launch_ball(struct game_state * state, double time);
|
||||||
void reset_level(struct game_state * state);
|
void reset_level(struct game_state * state);
|
||||||
void update(struct game_state * state, double time);
|
void update(struct game_state * state, double time);
|
||||||
|
|
||||||
|
|||||||
@ -217,8 +217,10 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double time = glfwGetTime();
|
||||||
|
|
||||||
if (!last_x_press && x_press) {
|
if (!last_x_press && x_press) {
|
||||||
launch_ball(&state);
|
launch_ball(&state, time);
|
||||||
}
|
}
|
||||||
last_x_press = x_press;
|
last_x_press = x_press;
|
||||||
|
|
||||||
@ -229,7 +231,6 @@ int main()
|
|||||||
if (state.paddle_x > 12 - extent)
|
if (state.paddle_x > 12 - extent)
|
||||||
state.paddle_x = 12 - extent;
|
state.paddle_x = 12 - extent;
|
||||||
|
|
||||||
double time = glfwGetTime();
|
|
||||||
update(&state, time);
|
update(&state, time);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
|
|||||||
@ -12,16 +12,43 @@
|
|||||||
#include "math/float_types.hpp"
|
#include "math/float_types.hpp"
|
||||||
#include "math/transform.hpp"
|
#include "math/transform.hpp"
|
||||||
|
|
||||||
void launch_ball(struct game_state * state)
|
static uint64_t xorshift_state = 0x1234567812345678;
|
||||||
|
|
||||||
|
uint64_t xorshift64(uint64_t x)
|
||||||
|
{
|
||||||
|
x ^= x << 13;
|
||||||
|
x ^= x >> 7;
|
||||||
|
x ^= x << 17;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
void launch_ball(struct game_state * state, double time)
|
||||||
{
|
{
|
||||||
if (state->balls_launched >= MAX_BALLS)
|
if (state->balls_launched >= MAX_BALLS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (xorshift_state == 0x1234567812345678) {
|
||||||
|
double timed = time;
|
||||||
|
uint64_t timei = *((uint64_t *)&timed);
|
||||||
|
xorshift_state = xorshift64(xorshift_state + timei);
|
||||||
|
}
|
||||||
|
xorshift_state = xorshift64(xorshift_state);
|
||||||
|
|
||||||
|
uint64_t rx = (xorshift_state >> 0) & 0xffffffff;
|
||||||
|
double orientation = rx;
|
||||||
|
double x = cos(orientation) - sin(orientation);
|
||||||
|
double y = sin(orientation) + cos(orientation);
|
||||||
|
vec2 d = normalize(vec2(x, y)) * 0.2f;
|
||||||
|
if (d.y < 0.1)
|
||||||
|
d.y = 0.1;
|
||||||
|
if (d.x > 0.05)
|
||||||
|
d.x = 0.05f * fabsf(d.x) / d.x;
|
||||||
|
|
||||||
struct ball_state& ball = state->balls[state->balls_launched];
|
struct ball_state& ball = state->balls[state->balls_launched];
|
||||||
ball.ball_x = state->paddle_x;
|
ball.ball_x = state->paddle_x;
|
||||||
ball.ball_y = 25.0;
|
ball.ball_y = 25.0f;
|
||||||
ball.ball_dx = 0.1;
|
ball.ball_dx = d.x;
|
||||||
ball.ball_dy = -0.1;
|
ball.ball_dy = -d.y;
|
||||||
|
|
||||||
state->balls_launched += 1;
|
state->balls_launched += 1;
|
||||||
}
|
}
|
||||||
@ -31,8 +58,6 @@ void reset_level(struct game_state * state)
|
|||||||
state->paddle_x = 0.0;
|
state->paddle_x = 0.0;
|
||||||
state->paddle_y = 26.0;
|
state->paddle_y = 26.0;
|
||||||
|
|
||||||
launch_ball(state);
|
|
||||||
|
|
||||||
state->start_time = 0.0;
|
state->start_time = 0.0;
|
||||||
|
|
||||||
assert(src_level_level1_data_size == 13 * 28);
|
assert(src_level_level1_data_size == 13 * 28);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user