aboutsummaryrefslogtreecommitdiff
path: root/exemples/exemple_MMover_MInertie.pl
diff options
context:
space:
mode:
Diffstat (limited to 'exemples/exemple_MMover_MInertie.pl')
-rwxr-xr-xexemples/exemple_MMover_MInertie.pl69
1 files changed, 69 insertions, 0 deletions
diff --git a/exemples/exemple_MMover_MInertie.pl b/exemples/exemple_MMover_MInertie.pl
new file mode 100755
index 0000000..fd1f4f1
--- /dev/null
+++ b/exemples/exemple_MMover_MInertie.pl
@@ -0,0 +1,69 @@
+#!/usr/bin/perl
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU GPL General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA,
+# or refer to http://www.gnu.org/copyleft/gpl.html
+#
+
+BEGIN {
+ unshift @INC, ".", "./data", "../src";
+}
+
+use MTools;
+use MTools::Comp::MMover;
+use MTools::GUI::MRect;
+use MTools::Comp::MInertie;
+
+# Creation de la frame
+new MTools (800, 600, 'Exemple MMover et MInertie');
+
+# Creation des objets delimitant l'espace
+new MTools::GUI::MRect (1, 0, 0, 650, 450, -fillcolor => "=axial 90 | #526266 | #667C80", -filled => 1);
+new MTools::GUI::MRect (1, 250, 300, 400, 150, -linecolor => 'black');
+
+# Creation de l'objet deplace
+my $target = minstanciate ('Ampoule.svg#on', 1);
+
+# Ajout du comportement MMover à l'objet
+my $mover = new MTools::Comp::MMover($target, $target, 1, x_max => 600, y_max => 400, y_min => 0, x_min => 0, allower => \&allowmove);
+# Ajout du comportement MInertie au comportement de mover
+new MTools::Comp::MInertie ($mover);
+
+
+# RUN
+mrun;
+
+# La fonction permet de conserver l'objet dans un espace controle
+# Elle recoit en parametre l'ancienne position de l'objet ainsi que le deplacement suggerer
+# Elle retourne un vecteur correspondant a la correction effectuee sur le deplacement
+sub allowmove {
+ my ($x, $y, $dx, $dy) = @_;
+ if ($x > 200)
+ {
+ if ($y + $dy > 250)
+ {
+ $dy = $y + $dy - 250;
+ return (0, $dy);
+ }
+ }
+ elsif ($x + $dx > 200)
+ {
+ if ($y + $dy > 250)
+ {
+ $dx = $x + $dx - 200;
+ return ($dx, 0);
+ }
+ }
+ return (0, 0);
+}
+