disappearing gravity vector
This commit is contained in:
parent
370ac137ff
commit
5c9d152eaf
34
balls.c
34
balls.c
@ -140,15 +140,22 @@ static void update_state () {
|
||||
static GtkWidget * window;
|
||||
static cairo_t * cr = 0;
|
||||
|
||||
static int gravity_vector_countdown = 0;
|
||||
static int gravity_vector_init = 300;
|
||||
|
||||
static void draw_gravity_vector() {
|
||||
cairo_new_path(cr);
|
||||
cairo_move_to(cr, width/2, height/2);
|
||||
cairo_line_to(cr, width/2 + g_x, height/2 + g_y);
|
||||
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
||||
cairo_set_line_width(cr, 1.0);
|
||||
cairo_stroke(cr);
|
||||
cairo_arc(cr, width/2 + g_x, height/2 + g_y, 3, 0, 2*M_PI);
|
||||
cairo_fill(cr);
|
||||
if (gravity_vector_countdown != 0) {
|
||||
cairo_new_path(cr);
|
||||
cairo_move_to(cr, width/2, height/2);
|
||||
cairo_line_to(cr, width/2 + g_x, height/2 + g_y);
|
||||
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
||||
cairo_set_line_width(cr, 1.0);
|
||||
cairo_stroke(cr);
|
||||
cairo_arc(cr, width/2 + g_x, height/2 + g_y, 3, 0, 2*M_PI);
|
||||
cairo_fill(cr);
|
||||
if (gravity_vector_countdown > 0)
|
||||
--gravity_vector_countdown;
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_balls_onto_window () {
|
||||
@ -194,20 +201,23 @@ static gint keyboard_input (GtkWidget *widget, GdkEventKey *event) {
|
||||
switch(event->keyval) {
|
||||
case GDK_KEY_Up:
|
||||
g_y -= 10;
|
||||
gravity_vector_countdown = gravity_vector_init;
|
||||
break;
|
||||
case GDK_KEY_Down:
|
||||
g_y += 10;
|
||||
gravity_vector_countdown = gravity_vector_init;
|
||||
break;
|
||||
case GDK_KEY_Left:
|
||||
g_x -= 10;
|
||||
gravity_vector_countdown = gravity_vector_init;
|
||||
break;
|
||||
case GDK_KEY_Right:
|
||||
g_x += 10;
|
||||
gravity_vector_countdown = gravity_vector_init;
|
||||
break;
|
||||
case GDK_KEY_F:
|
||||
case GDK_KEY_f:
|
||||
g_x = rand() % 201 - 100;
|
||||
g_y = rand() % 201 - 100;
|
||||
case GDK_KEY_G:
|
||||
case GDK_KEY_g:
|
||||
gravity_vector_countdown = gravity_vector_init;
|
||||
break;
|
||||
case GDK_KEY_Q:
|
||||
case GDK_KEY_q:
|
||||
|
Loading…
Reference in New Issue
Block a user