From be6ebaa64a1c5727dfc46b1fb9cdd98ac263bdbf Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Mon, 17 Aug 2015 19:44:46 +0200 Subject: install instructions --- installing.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 installing.txt diff --git a/installing.txt b/installing.txt new file mode 100644 index 0000000..1c8e604 --- /dev/null +++ b/installing.txt @@ -0,0 +1,15 @@ +debian wheezy instructions: + + apt-get install python3 + apt-get install python3-pip + cd repo/ + ln -s agarnet/agarnet fuckthisshit + in main.py, change "from agarnet.agarnet import [...]" to + "from fuckthisshit import [...]" + pip-3.2 install websocket-client + there will be an error message about invalid syntax in + sock.send(u""). Ignore it. + follow https://wiki.ubuntuusers.de/Pygame + do NOT use pip for installing pygame + + -- cgit v1.2.3 From 3f82941e685ce8c8b17f22a7c8b7b926e27b830f Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 18 Aug 2015 00:35:57 +0200 Subject: draw_circle: also convert radius to window lengths --- gui.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gui.py b/gui.py index 688c095..cf0710d 100644 --- a/gui.py +++ b/gui.py @@ -49,6 +49,7 @@ def draw_box(rect, color, filled=False, global_coords=True): def draw_circle(pos, r, color, filled=False, global_coords=True): if global_coords: pos = world_to_win_pt(pos, c.player.center) + r = world_to_win_length(r) if filled: gfxdraw.filled_circle(screen, pos[0], pos[1], r, color) -- cgit v1.2.3 From 8ad11d5114bab53c57323081ea0a042c60667926 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 18 Aug 2015 00:36:17 +0200 Subject: skip "both user and bot can control" mode --- gui.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/gui.py b/gui.py index cf0710d..4975031 100644 --- a/gui.py +++ b/gui.py @@ -247,9 +247,6 @@ def draw_frame(): elif not input and not bot_input: input = True bot_input = False - elif input and not bot_input: - input = True - bot_input = True else: input = False bot_input = True -- cgit v1.2.3 From ecdfcf48607ab9a382695dd0cdbdaada5d731762 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 18 Aug 2015 00:36:29 +0200 Subject: draw and set markers --- gui.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/gui.py b/gui.py index 4975031..0293152 100644 --- a/gui.py +++ b/gui.py @@ -23,6 +23,9 @@ input = False bot_input = True clock = pygame.time.Clock() +marker = [(0,0),(0,0),(0,0)] +marker_updated = [True, True, True] + screensize=(1280, 800) screen=pygame.display.set_mode(screensize,HWSURFACE|DOUBLEBUF|RESIZABLE) @@ -197,8 +200,22 @@ def clear_screen(): screen.fill((255,255,255)) +def draw_marker(pos, color, thick): + offset = 40 / math.sqrt(2.) + # offset = 15 + draw_line((pos[0]+offset, pos[1]+offset),(pos[0]-offset, pos[1]-offset), color) + draw_line((pos[0]-offset, pos[1]+offset),(pos[0]+offset, pos[1]-offset), color) + for r in [10,20,30,40]: + draw_circle(pos, r, color) + + +def draw_markers(): + colors=[(255,0,255),(255,255,0),(0,255,255)] + for i in [0, 1, 2]: + draw_marker(marker[i], colors[i], marker_updated[i]) + def draw_frame(): - global screen, movement, zoom, screensize, input, bot_input + global screen, movement, zoom, screensize, input, bot_input, marker, marker_updated pygame.event.pump() clock.tick() @@ -222,6 +239,9 @@ def draw_frame(): for cell in viruses: draw_cell(cell) + + draw_markers() + draw_leaderboard() total_mass = 0 @@ -254,16 +274,16 @@ def draw_frame(): pygame.quit() if event.key == K_r: c.send_respawn() - if input: + if event.type == MOUSEBUTTONDOWN: + if event.button in [1,2,3]: + marker[event.button-1] = win_to_world_pt(event.pos, c.player.center) + marker_updated[event.button-1] = True + print("set marker "+str(event.button-1)+" to "+str(event.pos)) + if input: if event.type == KEYDOWN: if event.key == K_w: c.send_shoot() if event.key == K_SPACE: c.send_split() - if event.type == MOUSEBUTTONDOWN: - if event.button == 1: - c.send_split() - if event.button == 3: - c.send_shoot() if event.type == MOUSEMOTION: c.send_target(*win_to_world_pt(event.pos, c.player.center)) -- cgit v1.2.3 From 57609975e0ea98c7152859ffd4c965c0879608ad Mon Sep 17 00:00:00 2001 From: SpitfireX Date: Sun, 16 Aug 2015 04:48:55 +0200 Subject: draw_text is now callable externally (cherrypick from strategy-rework) --- gui.py | 44 ++++++++++++++++++++++++++++---------------- strategy.py | 2 ++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/gui.py b/gui.py index 0293152..92b1982 100644 --- a/gui.py +++ b/gui.py @@ -81,6 +81,25 @@ def draw_arc(pos, r, bounds, color, global_coords=True): gfxdraw.arc(screen, pos[0], pos[1], r, int(bounds[0]*180/math.pi), int(bounds[1]*180/math.pi), color) +def draw_text(pos, text, color, font_size=16, global_coords=True, draw_centered=False): + if global_coords: + pos = world_to_win_pt(pos, c.player.center) + + output = None + + if font_fallback: + font = pygame.font.SysFont(pygame.font.get_default_font(), font_size) + output = font.render(text, 1, color) + else: + font = pygame.freetype.SysFont(pygame.freetype.get_default_font(), font_size) + output = font.render(text, color)[0] + + if draw_centered: + screen.blit(output, (pos[0] - (output.get_width()/2), pos[1] - (output.get_height()/2))) + else: + screen.blit(output, pos) + return output + def update(): pygame.display.update() @@ -121,16 +140,6 @@ def generate_virus(spikes, spike_length, radius, global_coords): points.append(t); return points -def draw_text(text, color, font_size): - if font_fallback: - font = pygame.font.SysFont(pygame.font.get_default_font(), font_size) - output = font.render(text, 1, color) - return output - else: - font = pygame.freetype.SysFont(pygame.freetype.get_default_font(), font_size) - output = font.render(text, color) - return output[0] - def draw_cell(cell): cx,cy = world_to_win_pt(cell.pos,c.player.center) radius = world_to_win_length(cell.size) @@ -159,11 +168,13 @@ def draw_cell(cell): font_size = 16 - surface = draw_text(cell.name, (0, 0, 0), font_size) - screen.blit(surface, (cx - (surface.get_width()/2), cy + radius + 5)) + draw_text((cx, cy + radius + 10), cell.name, (0, 0, 0), font_size, False, True) + # surface = draw_text(cell.name, (0, 0, 0), font_size) + # screen.blit(surface, (cx - (surface.get_width()/2), cy + radius + 5)) - surface = draw_text(str(int(cell.mass)), (255, 255, 255), font_size) - screen.blit(surface, (cx - (surface.get_width()/2), cy - (surface.get_height()/2))) + draw_text((cx, cy), str(int(cell.mass)), (255, 255, 255), font_size, False, True) + # surface = draw_text(str(int(cell.mass)), (255, 255, 255), font_size) + # screen.blit(surface, (cx - (surface.get_width()/2), cy - (surface.get_height()/2))) else: gfxdraw.aacircle(screen, cx, cy, radius, color) gfxdraw.filled_circle(screen, cx, cy, radius, color) @@ -175,8 +186,9 @@ def draw_leaderboard(): font_size = 16 for i, s in zip(range(1, len(leaderboard)+1), leaderboard): - surface = draw_text((str(i) + ": " +s), (0, 0, 0), font_size) - screen.blit(surface, (5, next_y)) + surface = draw_text((5, next_y), (str(i) + ": " +s), (0, 0, 0), font_size, False) + # surface = draw_text((str(i) + ": " +s), (0, 0, 0), font_size) + # screen.blit(surface, (5, next_y)) next_y += surface.get_height()+5 def draw_world_borders(): diff --git a/strategy.py b/strategy.py index 0d2d8f0..233541b 100644 --- a/strategy.py +++ b/strategy.py @@ -190,4 +190,6 @@ class Strategy: # more debugging gui.draw_line(self.c.player.center, self.target, self.color) + gui.draw_text(self.target, str(round(zipped[0][1], 2)), (0,0,0), draw_centered = True) + return self.target -- cgit v1.2.3