-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCursor.py
More file actions
70 lines (60 loc) · 2.1 KB
/
Cursor.py
File metadata and controls
70 lines (60 loc) · 2.1 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
70
import pygame, os
""" Das geht ja nich das simon mehr commits hier hat als ich,
also änder ich jetz ganz viele Dateien
-The_Lie0
"""
class Cursor(pygame.sprite.Sprite):
def __init__(self, game):
pygame.sprite.Sprite.__init__(self)
self.game = game
self.image = pygame.image.load(os.path.join('assets', 'sprites', 'cursor.png'))
self.rect = self.image.get_rect()
self.centerCursor()
pygame.mouse.set_visible(False)
self.rect.x = self.game.width / 2
self.rect.y = self.game.height / 2
self.resetBounds()
def get_pos(self):
return [self.rect.x, self.rect.y]
def centerCursor(self):
pygame.mouse.set_pos(self.game.width / 2, self.game.height / 2)
def resetBounds(self):
self.bounds = {
'top': False,
'right': False,
'bottom': False,
'left': False
}
def keepInBounds(self):
if self.rect.x < 0:
self.rect.x = 0
if self.rect.y < 0:
self.rect.y = 0
if self.rect.x > self.game.width:
self.rect.x = self.game.width
if self.rect.y > self.game.height:
self.rect.y = self.game.height
def checkBounds(self):
self.resetBounds()
if self.rect.x == 0:
self.bounds['left'] = True
if self.rect.y == 0:
self.bounds['top'] = True
if self.rect.x == self.game.width:
self.bounds['right'] = True
if self.rect.y == self.game.height:
self.bounds['bottom'] = True
def updatePosition(self):
absolutePosition = pygame.mouse.get_pos()
relativePosition = [absolutePosition[0], absolutePosition[1]]
relativePosition[0] -= self.game.width / 2
relativePosition[1] -= self.game.height / 2
self.rect.x += relativePosition[0]
self.rect.y += relativePosition[1]
self.centerCursor()
self.keepInBounds()
self.checkBounds()
def update(self, deltaTime, events):
self.updatePosition()
def draw(self, screen):
screen.blit(self.image, self.rect)