summaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorSpitfireX <timm.weber@me.com>2015-08-08 20:16:28 +0200
committerSpitfireX <timm.weber@me.com>2015-08-08 20:16:28 +0200
commit142b6b2844a54fa21e8301d945d43157c42d4ae4 (patch)
tree515c122c1b559d3fbb64b2a1ff482c7073941021 /test.py
parent48339d2e33b2e00a04c591c93fe6f2caac6b8ca9 (diff)
Added FPS counter
added an FPS counter to the window title and fixed window event handling (window now closes properly!). Windfisch pls: schau mal ob du die prints da unten noch brauchst, hab die mal auskommentiert.
Diffstat (limited to 'test.py')
-rw-r--r--test.py25
1 files changed, 20 insertions, 5 deletions
diff --git a/test.py b/test.py
index 413c8be..bde693d 100644
--- a/test.py
+++ b/test.py
@@ -6,6 +6,7 @@ from pygame import freetype
from pygame.locals import *
import sys
import math
+import time
screensize = (0,0)
zoom = 0.74
@@ -196,12 +197,15 @@ screen=pygame.display.set_mode(screensize,HWSURFACE|DOUBLEBUF|RESIZABLE)
zoom = calc_zoom()
i=0
mb=pygame.mouse.get_pressed()
+last_time = time.time()
+fps = 0
+frame_counter = 0
while True:
pygame.event.pump()
i=i+1
- print(i)
+ # print(i)
if (i==30):
c.send_respawn()
@@ -214,7 +218,7 @@ while True:
bottom = int((c.world.bottom_right[0] - c.player.center[1])*zoom + screensize[1]/2)
right = int((c.world.bottom_right[1] - c.player.center[0])*zoom + screensize[0]/2)
- print ((top,bottom,left,right))
+ # print ((top,bottom,left,right))
if (top >= 0): gfxdraw.hline(screen, 0, screensize[0], top, (0,0,0))
if (bottom <= screensize[1]): gfxdraw.hline(screen, 0, screensize[0], bottom, (0,0,0))
if (left >= 0): gfxdraw.vline(screen, left, 0, screensize[1], (0,0,0))
@@ -225,16 +229,25 @@ while True:
draw_leaderboard()
- print(list(c.player.own_cells))
+ # print(list(c.player.own_cells))
total_mass = 0
for cell in c.player.own_cells:
total_mass += cell.mass
- pygame.display.set_caption("Agar.io: " + str(c.player.nick) + " - " + str(int(total_mass)) + (" - MOVEMENT LOCKED" if not movement else ""))
+ global fps, frame_counter, last_time
+ now = time.time()
+ if now - last_time >= 1.0:
+ fps = frame_counter
+ frame_counter = 0
+ last_time = now
+ else:
+ frame_counter += 1
+
+ pygame.display.set_caption("Agar.io: " + str(c.player.nick) + " - " + str(int(total_mass)) + " Total Mass - " + str(fps) + (" FPS - MOVEMENT LOCKED" if not movement else " FPS"))
mp=pygame.mouse.get_pos()
- print(mp)
+ # print(mp)
oldmb=mb
mb = pygame.mouse.get_pressed()
@@ -254,6 +267,8 @@ while True:
screen=pygame.display.set_mode(screensize,HWSURFACE|DOUBLEBUF|RESIZABLE)
zoom = calc_zoom()
pygame.display.update()
+ if event.type==QUIT:
+ pygame.display.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_r:
c.send_respawn()