summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui.py6
-rw-r--r--main.py22
2 files changed, 28 insertions, 0 deletions
diff --git a/gui.py b/gui.py
index ade95c1..65c977a 100644
--- a/gui.py
+++ b/gui.py
@@ -7,7 +7,12 @@ import sys
import math
import time
+def debug_line(p1,p2,col):
+ global screen
+ pygame.draw.line(screen, col, world_to_win_pt(p1, c.player.center), world_to_win_pt(p2, c.player.center))
+def update():
+ pygame.display.update()
def calc_zoom():
zoom1 = screensize[0] / 2051.
@@ -87,6 +92,7 @@ def draw_cell(cell):
else:
gfxdraw.aacircle(screen, cx, cy, radius, color)
gfxdraw.filled_circle(screen, cx, cy, radius, color)
+
def draw_leaderboard():
def filter(item): return item[1]
leaderboard = list(map(filter, c.world.leaderboard_names))
diff --git a/main.py b/main.py
index 21452bc..3f09e02 100644
--- a/main.py
+++ b/main.py
@@ -36,4 +36,26 @@ gui.set_client(c)
# main loop
while True:
c.on_message()
+
gui.draw_frame()
+
+ if len(list(c.player.own_cells)) > 0:
+ my_smallest = min(map(lambda cell : cell.mass, c.player.own_cells))
+
+ runaway_x, runaway_y=(0.0,0.0)
+ for cell in c.world.cells.values():
+ dist = math.sqrt((cell.pos[0]-c.player.center[0])**2 + (cell.pos[1]-c.player.center[1])**2)
+ if dist < cell.size*4 and cell.mass > my_smallest:
+ runaway_x += (c.player.center[0] - cell.pos[0]) / cell.mass / dist
+ runaway_y += (c.player.center[1] - cell.pos[1]) / cell.mass / dist
+
+
+ runaway_r = math.sqrt(runaway_x**2 + runaway_y**2)
+ if (runaway_r > 0):
+ runaway_x, runaway_y = (c.player.center[0]+int(100*runaway_x / runaway_r)), (c.player.center[1]+int(100*runaway_y / runaway_r))
+
+ c.send_target(runaway_x, runaway_y)
+ print (str((runaway_x-c.player.center[0], runaway_y-c.player.center[1])))
+ gui.debug_line(c.player.center, (runaway_x,runaway_y),(255,0,0))
+ gui.update()
+