# ENIGMA Development Environment

 Pages: 1
 Author Topic: Fancy Collision Script  (Read 1920 times)
RetroX
 Posted on: November 16, 2008, 07:00:04 PM

Master of all things Linux

Location: US
Joined: Apr 2008
Posts: 1055

This is a script that will move the object into a free position in the best way possible.  Simple, yet effective.
Code: [Select]
`// Syntax: collision_free(max)// Function: Moves at a maximum of "max" outside of solids.// Define Varsleft=0;right=0;up=0;down=0;// Don't do anything if we're already collision freeif not place_free(x,y) { // Check to see which way is closest to get outside of a solid for (i=0;i<=argument0;i+=1;)  {  if place_free(x-i,y)   {   // Find out how far we can move left   left=i;   break;   }  } for (i=0;i<=argument0;i+=1;)  {  if place_free(x+i,y)   {   // Find out how far we can move right   right=i;   break;   }  } for (i=0;i<=argument0;i+=1;)  {  if place_free(x,y-1)   {   // Find out how far we can move up   up=i;   break;   }  } for (i=0;i<=argument0;i+=1;)  {  if place_free(x,y+1)   {   // Find out how far we can move down   down=i;   break;   }  } }// If up is the highest, move upif up>=left or up>=right or up>=down { y-=up; }// If down is the highest, move downif down>=left or down>=right or down>=up { y+=down; }// If left is the highest, move leftif left>=right or left>=up or left>=down { x-=left; }// If right is the highest, move rightif right>=left or left>=up or left>=down { x+=right; }`
 Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars?
 Reply #1 Posted on: November 19, 2008, 12:17:42 PM

Joined: Jul 2008
Posts: 68

Nice. Very useful, especially for Platformers and RPGs.
 Logged
RetroX
 Reply #2 Posted on: November 19, 2008, 04:05:15 PM

Master of all things Linux

Location: US
Joined: Apr 2008
Posts: 1055

Like how in some games you end up saving over the starting point of an object and ruin the entire game.
 Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars?
 Pages: 1