In my opinion, using Python makes sense whenever complex custom data structures, inheritence or reusable code is needed. For the latter it wouldn't make much sense to "hardcode".
from math import *
class Magnet(object):
def __init__(self, centerX=0, centerY=0, radius=200):
self.center = (centerX, centerY)
self.radius = radius
def lerp(self, a, b, x):
return a + (b - a) * x
def attract(self, construct_object):
a = self.center[0] - construct_object.X
b = self.center[1] - construct_object.Y
c = max(self.radius * 0.5, min(self.radius, sqrt(pow(a, 2) + pow(b, 2))))
f = self.radius / c - 1
construct_object.X = lerp(self.center[0], construct_object.X, f ** System.TimeDelta)
construct_object.Y = lerp(self.center[1], construct_object.Y, f ** System.TimeDelta)[/code:3jh1c5m5]
The script could now be saved, e.g as magnet.py, to ...\Data\Python\ and then be reused in every project with every object that has X and Y properties:
+ Start of layout
-> Script[code:3jh1c5m5]from magnet import *
myMagnet = Magnet(300, 300, 224)[/code:3jh1c5m5]
+ Always
-> Script[code:3jh1c5m5]myMagnet.attract(Sprite)[/code:3jh1c5m5]
Clean and simple
(Please don't test if the code is actually working, it was just a quick written example to show the principle)