efl/legacy/edje/src/examples/physics_actions.edc

212 lines
5.4 KiB
Plaintext

/* It can be tested with edje_player slave mode
* $ edje_player -S physics_actions.edj
*
* signal up impulse -> will throw both balls up
* signal left impulse -> will throw blue ball to the left
* signal clockwise impulse -> will roll blue ball in clockwise
* signal counterclockwise impulse -> will roll blue ball in counterclockwise
*
* message 1 FLOAT_SET 3 50 -100 0 -> apply an impulse on blue ball with
* x = 50, y = -100, z = 0, for example
* message 2 FLOAT_SET 3 0 0 8.2 -> apply a torque impulse on blue ball with
* x = 4, y = 0, z = 0.8, for example
*/
#define ID_IMPULSE (1)
#define ID_TORQUE_IMPULSE (2)
collections {
images {
image: "bubble-blue.png" COMP;
}
group {
name: "example_group";
script {
public message(Msg_Type:type, id, ...) {
if ((id == ID_IMPULSE) && (type == MSG_FLOAT_SET)) {
new Float:x, Float:y, Float:z;
new n = numargs();
if (n < 5) return;
x = getfarg(2);
y = getfarg(3);
z = getfarg(4);
physics_impulse(PART:"blue_circle", x, y, z);
}
else if ((id == ID_TORQUE_IMPULSE) && (type == MSG_FLOAT_SET)) {
new Float:x, Float:y, Float:z;
new n = numargs();
if (n < 5) return;
x = getfarg(2);
y = getfarg(3);
z = getfarg(4);
physics_torque_impulse(PART:"blue_circle", x, y, z);
}
}
}
parts {
part {
name: "background";
type: RECT;
physics_body: NONE;
description {
state: "default" 0.0;
color: 255 255 255 255; /* white */
rel1.relative: 0.0 0.0;
rel2.relative: 1.0 1.0;
}
}
part {
name: "blue_circle";
type: IMAGE;
physics_body: RIGID_CIRCLE;
description {
state: "default" 0.0;
rel1.relative: 0.35 0.1;
rel2.relative: 0.55 0.2;
aspect: 1 1;
image {
normal: "bubble-blue.png";
}
physics {
restitution: 0.85;
friction: 1.0;
}
}
}
part {
name: "red_circle";
type: IMAGE;
physics_body: RIGID_CIRCLE;
description {
state: "default" 0.0;
color: 255 0 0 255; /* light red */
rel1.relative: 0.65 0.1;
rel2.relative: 0.85 0.2;
aspect: 1 1;
image {
normal: "bubble-blue.png";
}
physics {
restitution: 0.85;
friction: 1.0;
}
}
}
part {
name: "floor";
type: RECT;
physics_body: BOUNDARY_BOTTOM;
description {
state: "default" 0.0;
visible: 0;
physics {
restitution: 0.6;
friction: 1.0;
}
}
}
part {
name: "right_wall";
type: RECT;
physics_body: BOUNDARY_RIGHT;
description {
state: "default" 0.0;
visible: 0;
physics {
restitution: 0.3;
}
}
}
part {
name: "left_wall";
type: RECT;
physics_body: BOUNDARY_LEFT;
description {
state: "default" 0.0;
visible: 0;
physics {
restitution: 0.3;
}
}
}
part {
name: "roof";
type: RECT;
physics_body: BOUNDARY_TOP;
description {
state: "default" 0.0;
visible: 0;
physics {
restitution: 0.2;
}
}
}
}
programs {
program {
name: "impulse_up";
signal: "up";
source: "impulse";
action: PHYSICS_IMPULSE 0 -300 0;
target: "blue_circle";
target: "red_circle";
}
program {
name: "impulse_down";
signal: "down";
source: "impulse";
action: PHYSICS_IMPULSE 0 300 0;
target: "red_circle";
target: "blue_circle";
}
program {
name: "impulse_left";
signal: "left";
source: "impulse";
action: PHYSICS_IMPULSE -300 0 0;
target: "blue_circle";
}
program {
name: "impulse_right";
signal: "right";
source: "impulse";
action: PHYSICS_IMPULSE 300 0 0;
target: "red_circle";
}
program {
name: "impulse_clockwise";
signal: "clockwise";
source: "impulse";
action: PHYSICS_TORQUE_IMPULSE 0 0 4;
target: "blue_circle";
}
program {
name: "impulse_counterclockwise";
signal: "counterclockwise";
source: "impulse";
action: PHYSICS_TORQUE_IMPULSE 0 0 -4;
target: "blue_circle";
}
}
}
}