Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Stone Jam -- 21 challenging puzzles with perl Tk

by zentara (Archbishop)
on May 03, 2018 at 12:40 UTC ( [id://1213994]=note: print w/replies, xml ) Need Help??


in reply to Stone Jam -- 21 challenging puzzles with perl Tk

Hi Discipulus, no matter what I do I can't get the red block to move.

I wI was for some method to produce some brick-like piece unable to collide themselves.as for some method to produce some brick-like piece unable to collide themselves.

Try this tag method.

#!/usr/bin/perl use warnings; use strict; use Tk; my $dx; my $dy; my $mw = MainWindow->new; $mw->geometry("700x600"); my $canvas = $mw->Canvas(-width => 700, -height => 565, -bg => 'black', -borderwidth => 3, -relief => 'sunken', )->pack; my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exi +t(0)}) ->pack; my $dr = $canvas->createPolygon(0, 20, 50, 20, 50, 75, 0,75, -fill => 'red', -tags => ['move','red','paver'], ); my $db = $canvas->createPolygon(70, 20, 150,20, 150, 75, 70 , 75, -fill => 'blue', -tags => ['move','blue','paver'], ); my $dg = $canvas->createPolygon(200, 20, 250,20, 250, 75, -fill => 'green', -tags => ['move','green','paver'], ); my $dp = $canvas->createPolygon(300, 20, 350,20, 350, 75, -fill => 'purple', -tags => ['move','purple','paver'], ); $canvas->bind('move', '<1>', sub {&mobileStart();}); $canvas->bind('move', '<B1-Motion>', sub {&mobileMove();}); $canvas->bind('move', '<ButtonRelease-1>', sub {&mobileStop();}); MainLoop; sub mobileStart { my $ev = $canvas->XEvent; ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); $canvas->raise('current'); # print "START MOVE-> $dx $dy\n"; } sub mobileMove { my $ev = $canvas->XEvent; # $canvas->bind('current', '<Leave>', sub {&mobileStop();}); + my @coords_in = $canvas->coords('current'); # print "@coords_in\n"; $canvas->move('current', $ev->x + $dx, $ev->y +$dy); ($dx, $dy) = (0 - $ev->x, 0 - $ev->y); # print "MOVING-> $dx $dy\n"; my @coords = $canvas->coords('current'); #print "@coords\n"; my (@olaps) = $canvas->find('overlapping', $coords[0],$coords[1] +,$coords[4],$coords[5], ); foreach my $id(@olaps){ print $canvas->gettags($id),"\t"; } print "@olaps\n"; print "\n"; if(scalar @olaps > 1){ # Redraw the rect $canvas->coords('current', @coords_in); } } sub mobileStop{ &mobileMove; }

what happened to the -tile option for canvas? How can I fill canvas objects (rectangles, ovals..) with Photos or advanced grafic?

I don't think there is a canvas -tile option for it's objects. What you would need to do is create canvas image objects of the appropriate size and manipulate them. See Tk ImageMap-color-zones for an example.


I'm not really a human, but I play one on earth. ..... an animated JAPH

Replies are listed 'Best First'.
Re^2: Stone Jam -- 21 challenging puzzles with perl Tk
by choroba (Cardinal) on May 03, 2018 at 13:26 UTC
    Weird - you can move anything towards the hypotenuse of a triangle, but you can't move a triangle close to anything with its hypotenuse.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Hi, yeah, thanks for pointing that out. It must have something to do with the overlap tag and the way polygon items are drawn. The polygon overlap must be detected by a hidden square made from it's most extreme vertices. More experiments with different types of polygons would be in order. Like what happens with a 5 or 10 sided polygon, or what happens with a circle? It still is a useful collision detection method. It favors "keeping away". :-)

      I'm not really a human, but I play one on earth. ..... an animated JAPH

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1213994]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found