-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotlight.py
More file actions
69 lines (59 loc) · 2.02 KB
/
spotlight.py
File metadata and controls
69 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import sys
import pygame as pg
CAPTION="SPOTLIGHT GAME"
screen_size=(1000,650)
color_key=(255,0,255)
ellipse_size=(400,400)
class Control(object):
def __init__(self):
self.screen=pg.display.get_surface()
self.screen_rect=self.screen.get_rect()
self.clock=pg.time.Clock()
self.fps=60.0
self.done=False
self.keys=pg.key.get_pressed()
self.background=FRACTAL
self.ellipse_rect=pg.Rect((0,0),ellipse_size)
def event_loop(self):
for event in pg.event.get():
self.keys=pg.key.get_pressed()
if event.type == pg.QUIT or self.keys[pg.K_ESCAPE]:
self.done = True
def make_hole(self):
hole=pg.Surface(self.screen_rect.size).convert()
hole.set_colorkey(color_key)
hole.fill((0,0,0))
pg.draw.ellipse(hole,color_key,self.ellipse_rect)
return hole
def make_hole_alpha(self):
hole=pg.Surface(self.screen_rect.size).convert_alpha()
hole.fill((255,255,200))
pg.draw.ellipse(hole,(0,0,0,0),self.ellipse_rect)
return hole
def update(self):
self.ellipse_rect.center=pg.mouse.get_pos()
self.hole=self.make_hole()
def draw(self):
self.screen.blit(self.background,(0,0))
self.screen.blit(self.hole,(0,0))
def display_fps(self):
caption="{} - FPS: {:.2f}".format(CAPTION,self.clock.get_fps())
pg.display.set_caption(caption)
def main_loop(self):
while not self.done:
self.event_loop()
self.update()
self.draw()
pg.display.update()
self.clock.tick(self.fps)
self.display_fps()
if __name__=="__main__":
os.environ['SDL_VIDEO_CENTERED']='1'
pg.init()
pg.display.set_mode(screen_size)
FRACTAL=pg.image.load("background.jpg").convert()
run_it=Control()
run_it.main_loop()
pg.quit()
sys.exit()