Created
August 4, 2014 01:17
-
-
Save iminurnamez/c42eb71620fdd6a36b78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import pygame as pg | |
class MouseTester(object): | |
def __init__(self): | |
self.done = False | |
self.clock = pg.time.Clock() | |
self.screen = pg.display.set_mode((800, 800)) | |
self.center_rect = pg.Rect(0, 0, 10, 10) | |
self.center_rect.center = self.screen.get_rect().center | |
self.font = pg.font.Font("freesansbold.ttf", 24) | |
self.clicked_label = self.font.render("Last click: No click yet", True, pg.Color("white")) | |
def update(self): | |
pg.display.set_caption("{}".format(pg.mouse.get_pos())) | |
def draw(self): | |
self.screen.fill(pg.Color("black")) | |
pg.draw.rect(self.screen, pg.Color("blue"), self.center_rect) | |
self.screen.blit(self.clicked_label, (0, 0)) | |
def event_loop(self): | |
for event in pg.event.get(): | |
if event.type == pg.QUIT: | |
self.done = True | |
if event.type == pg.MOUSEBUTTONDOWN: | |
self.clicked_label = self.font.render("Last click: {}".format(event.pos), True, pg.Color("white")) | |
def run(self): | |
while not self.done: | |
self.event_loop() | |
self.update() | |
self.draw() | |
pg.display.update() | |
self.clock.tick(30) | |
if __name__ == "__main__": | |
pg.init() | |
test= MouseTester() | |
test.run() | |
pg.quit() | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment