disappearing gravity vector

This commit is contained in:
Antonio Carzaniga 2019-07-29 15:49:42 +02:00
parent 370ac137ff
commit 5c9d152eaf

18
balls.c
View File

@ -140,7 +140,11 @@ 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() {
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);
@ -149,6 +153,9 @@ static void draw_gravity_vector() {
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: