-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreenobjects.py
More file actions
executable file
·82 lines (68 loc) · 3.1 KB
/
screenobjects.py
File metadata and controls
executable file
·82 lines (68 loc) · 3.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
71
72
73
74
75
76
77
78
79
80
81
82
import pygame
from math import sin, cos, radians, pi
class Eye:
#Initiate the eye, set the image used for the eye, as well as if it's a left or right eye
def __init__(self, imagePath, leftEye, game):
self.leftEye = leftEye
self.eye = pygame.image.load(imagePath)
self.ballrect = self.eye.get_rect()
self.eyeWidth = self.ballrect.width
self.eyeHeight = self.ballrect.height
self.centerPointX = int(self.eyeWidth / 2)
self.centerPointY = int(self.eyeWidth / 2)
self.ballrect.center = [self.centerPointX, self.centerPointY]
self.rotateX = 0
self.rotateY = 0
self.eyeAngle = 10
#This function is used to update the location of the eyes as the angle changes
def setEyeAngle(self, angle):
self.eyeAngle = angle
def levelEyes(self, game):
d = game.SCREEN_MIDPOINT_X - game.SCREEN_THIRD_X
x0 = 0
y0 = 0
theta_rad = pi/2 - radians(self.eyeAngle)
self.rotateY = int(x0 + d*cos(theta_rad))
self.rotateX = int(d - int(y0 + d*sin(theta_rad)))
#This function is used to update the location of the eye on the screen.
def updateLocation(self, joystick, game):
self.levelEyes(game )
#calulate the X position of an Eye
#=================================
rawXAxisValue = float(joystick.get_axis(0))
blinkButton = joystick.get_button( 7 )
if(blinkButton == 1):
self.ballrect.x = 10000
self.ballrect.y = 10000
else:
if(game.REVERSE_X_EYES):
rawXAxisValue = 0 - rawXAxisValue
#Calculate position of eye in the deadzone
if (rawXAxisValue >= (game.DEADZONE_LIMIT * -1) ) and (rawXAxisValue <= game.DEADZONE_LIMIT):
if(self.leftEye):
self.ballrect.x = game.SCREEN_THIRD_X - self.centerPointX + self.rotateX
else:
self.ballrect.x = (game.SCREEN_WIDTH - game.SCREEN_THIRD_X) - self.centerPointX - self.rotateX
#Calculate the position of the eye when the joystick is outside the deadzone
else:
pixelDifference = rawXAxisValue * game.SCREEN_THIRD_X
if(self.leftEye):
eyelocation_x = game.SCREEN_THIRD_X + pixelDifference - self.centerPointX + self.rotateX
else:
eyelocation_x = (game.SCREEN_WIDTH - game.SCREEN_THIRD_X) + pixelDifference - self.centerPointX - self.rotateX
self.ballrect.x = eyelocation_x
#Calculate the Y position of an eye
#==================================
rawYAxisValue = joystick.get_axis(1)
#Calculate position of eye in the deadzone
if(self.leftEye):
rotatePixels = self.rotateY * -1
else:
rotatePixels = self.rotateY
if rawYAxisValue >= (game.DEADZONE_LIMIT * -1 ) and rawYAxisValue <= game.DEADZONE_LIMIT:
self.ballrect.y = game.SCREEN_MIDPOINT_Y - self.centerPointY + rotatePixels
#Calculate hte position of the eye when the joystick is outside the deadzone
else:
joy_stick_y = ( rawYAxisValue + 1) / 2
eyelocation_y = int( joy_stick_y * game.SCREEN_HEIGHT ) - self.centerPointY + rotatePixels
self.ballrect.y = eyelocation_y