From c5866f304210618979d03c561b1e3f6f83200bce Mon Sep 17 00:00:00 2001 From: ribet Date: Wed, 21 Mar 2007 10:19:39 +0000 Subject: Import initial --- exemples/exemple_MMover_MInertie.pl | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 exemples/exemple_MMover_MInertie.pl (limited to 'exemples/exemple_MMover_MInertie.pl') 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); +} + -- cgit v1.1