-
Notifications
You must be signed in to change notification settings - Fork 63
/
follow_cursor.py
57 lines (40 loc) ยท 1.06 KB
/
follow_cursor.py
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
# Author : John Smith
# Library / Framework used : Pygame
# Simple player follow cursor
import pygame
import random
import sys
import time
pygame.init()
black = (0,0,0)
white = (255,255,255)
movement_speed = 10
FPS = 60
width = 640
height = 480
ball = pygame.Rect(0,0,20,20)
ballSize = 5
varHeight = height
ballColor = white
bgColor = black
font = pygame.font.Font('freesansbold.ttf',10)
text = font.render('Left Click to Move',True,white)
textRect = text.get_rect()
textRect.center = (width//2,height//2)
gameOver = False
display = pygame.display.set_mode((width,height))
pygame.display.set_caption('Follow')
x,y = pygame.mouse.get_pos()
clock = pygame.time.Clock()
while not gameOver:
display.fill(bgColor)
display.blit(text,textRect)
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameOver = True
if event.type==pygame.MOUSEBUTTONDOWN:
ball.center=pygame.mouse.get_pos()
pygame.draw.rect(display,ballColor,ball)
pygame.display.update()
pygame.display.flip()
clock.tick(FPS)