summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorTimm Weber <timm.weber@me.com>2015-08-08 04:40:42 +0200
committerTimm Weber <timm.weber@me.com>2015-08-08 04:40:42 +0200
commit4c7c9ae495fdf7b8f06a0be2daa9a322bb2b390c (patch)
tree2db6acd2cb83103a3045b27f4c3ce4b1943a6cdd /test.py
parenta89eb43a42cbe8e963d527df50dce7922b1b3967 (diff)
parent61a5f8effb9b07fd4cdb7c38a6b9d0fd78c40c70 (diff)
Merge branch 'master' of /nfshome/ki08jofa/agario-frickel
Diffstat (limited to 'test.py')
-rw-r--r--test.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/test.py b/test.py
index c77a80b..303d6d6 100644
--- a/test.py
+++ b/test.py
@@ -72,6 +72,23 @@ class MeinSubskribierer:
def on_debug_line(self,x,y):
print("debug line")
+def calc_zoom():
+ zoom1 = screensize[0] / 2051.
+ zoom2 = screensize[1] / 1216.
+ return max(zoom1,zoom2)
+
+def world_to_win_length(l):
+ return int(l*zoom)
+
+def win_to_world_length(l):
+ return int(l/zoom)
+
+def world_to_win_pt(pt,center):
+ return (int((pt[0]-center[0])*zoom + screensize[0]/2), int((pt[1]-center[1])*zoom + screensize[1]/2))
+
+def win_to_world_pt(pt,center):
+ return (int((pt[0]-screensize[0]/2)/zoom+center[0]), int((pt[1]-screensize[1]/2)/zoom+center[1]))
+
def generateVirus(spikes, spike_length, radius, global_coords):
step = (2*math.pi) / (spikes*2)
points = []
@@ -91,14 +108,13 @@ def generateVirus(spikes, spike_length, radius, global_coords):
return points
def drawCell(cell):
- cx = int((cell.pos[0]-c.player.center[0])*zoom +screensize[0]/2)
- cy = int((cell.pos[1]-c.player.center[1])*zoom +screensize[1]/2)
- radius = int(cell.size*zoom)
+ cx,cy = world_to_win_pt(cell.pos,c.player.center)
+ radius = world_to_win_length(cell.size)
if cell.is_virus:
color = (0,255,0)
color2 = (100,255,0)
- polygon = generateVirus(int(cell.size*0.3), 5, radius, (cx, cy))
+ polygon = generateVirus(int(cell.size*0.3), 10*zoom, radius, (cx, cy))
gfxdraw.filled_polygon(screen, polygon, color2)
gfxdraw.aapolygon(screen, polygon, color)
@@ -153,10 +169,12 @@ c.send_spectate()
screensize=(800,600)
screen=pygame.display.set_mode(screensize,HWSURFACE|DOUBLEBUF|RESIZABLE)
+zoom = calc_zoom()
i=0
mb=pygame.mouse.get_pressed()
+
while True:
pygame.event.pump()
@@ -164,9 +182,7 @@ while True:
if event.type==VIDEORESIZE:
screensize = event.dict['size']
screen=pygame.display.set_mode(screensize,HWSURFACE|DOUBLEBUF|RESIZABLE)
- zoom1 = screensize[0] / 2051.
- zoom2 = screensize[1] / 1216.
- zoom = max(zoom1,zoom2)
+ zoom = calc_zoom()
pygame.display.update()
i=i+1
@@ -193,8 +209,7 @@ while True:
oldmb=mb
mb = pygame.mouse.get_pressed()
-
- c.send_target(((mp[0]-screensize[0]/2)/zoom)+c.player.center[0],(mp[1]-screensize[1]/2)/zoom+c.player.center[1])
+ c.send_target(*win_to_world_pt(mp, c.player.center))
if mb[0] and not oldmb[0]:
c.send_split()