Wednesday, December 07, 2005

screaming again

Last friday night I was screaming at my computer again because I worked for hours on a game maker problem which I couldn't solve

I'll call it the position_meeting() problem, after the name of the recalcitrant function

I worked on it again tonight and solved it. But it still took me at least another couple of hours.

I feel both a deep sense of satisfaction that comes from solving problems such as these, combined with ongoing annoyance that the game maker interface in this case was not intuitive and also the documentation in the manual quite inadequate.

xycoords
When the ghost pushes the rocks onto the placeholders then the wall disappears. That's the big picture of what I was trying to achieve. It's part of a pattern matching exercise that a couple of my students have come up with in the Murdoch game making competition

The problem was that when you determine a position in a room (x, y co-ordinates) by moving the mouse to the desired position and reading the co-ordinates, then that position does not work in the function: position_meeting(x, y, obj).

By default, the position co-ordinates provided by the mouse feedback is snapped to grid and also by default the origin of an object is at the top left hand corner of that object. Anyway, if you do the natural thing and just type in the co-ordinates provided by the mouse feedback then the function does not work.

I solved the problem by adding half the grid width and height to the co-ordinates moving the position detection to the centre of the object, rather than the outer perimeter. For a 24*24 grid add 12 to both the x and y co-ordinates producing 108, 156 and not 96, 144 which is shown in the diagram.

Anyway, the screaming last Friday didn't help much.

0 Comments:

Post a Comment

<< Home