I haven't tested this code:

var my_motion[3];
var my_bounce[3];
var bouncing;

function ball_event
{
bouncing=1;
vec_to_angle(my_bounce, bounce);
my_bounce.tilt=0;
my_bounce.roll=0;
}

action ball
//first part of code...
//calculate speed:
my_motion.x += (key_cur-key_cul)*0.5*time;
my_motion.y += (key_cuu-key_cud)*0.5*time;
my_motion.z=0;

//include bounce set in event function(rotate speed vector if bouncing)
if(bouncing==1){vec_rotate(my_motion,my_bounce);
bouncing=0;//instant reset

c_move(my, nullvector, my_motion, ignore_passents+activate_trigger+use_aabb);
my.x=clamp(my.x,0,1024); my.y=clamp(my.y,0,2048);
wait(1);
//rest of code