-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathduckhuntplayers.py
More file actions
148 lines (99 loc) · 2.7 KB
/
Copy pathduckhuntplayers.py
File metadata and controls
148 lines (99 loc) · 2.7 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import pygame
#This module contains all the player classes and their respecsctive helper classes.
##====================================================
class Player(object):
#Player class constructor
def __init__(self, window):
#Initializes score to zero.
self.score = 0
self.name = "P"
self.num_bullets = 10
self.window = window
self.shot_img = pygame.image.load("shot.png")
#Returns a 2-tuple with the location at which
#the player shot at the screen.
def shot_at(self, event):
if(event != None):
x, y = event.pos
self.window.blit(self.shot_img, (x - 300//2, y - 300//2))
self.num_bullets-=1
return (0,0)
def update_score(self, points):
self.score += points
def update(self):
pass
def getName(self):
pass
def get_num_bullets(self):
return self.num_bullets
def get_score(self):
return self.score
def clear_score(self):
self.score = 0
def move(self):
pass
def recover_stats(self, score, bullets):
self.score = score
self.bullets = bullets
def set_bullets(self, bullets):
self.num_bullets = bullets
##====================================================
##====================================================
class InteractivePlayer(Player):
#Player class constructor
def __init__(self, window):
Player.__init__(self, window)
self.name = "P1"
#Returns a 2-tuple with the location at which
#the player shot at the screen.
def shot_at(self, event):
Player.shot_at(self, event)
return event.pos
def update(self):
pass
def getName(self):
return self.name
##====================================================
##====================================================
#Class that represents the robot that will play as this game's player.
class Robot(Player):
def __init__(self, window, robot_eye):
Player.__init__(self, window)
self.name = "R"
self.robot_eye = robot_eye
self.wait_time = 25
self.shot = False
self.x = 0
self.y = 0
def shot_at(self, event):
self.shot = True
return Player.shot_at(self, None)
def move(self):
self.eye_x, self.eye_y = self.robot_eye.coord
mouse_x, mouse_y = pygame.mouse.get_pos()
dx = 0
dy = 0
#if(self.eye_x > mouse_x):
# dx = 5
#elif(self.eye < mouse_x):
# dx = -5
#else:
# dx = 0
#if(mouse_y < self.eye_y):
# dy = 5
#elif(mouse_y > self.eye_y):
# dy = -5
#else:
# dy = 0
dx = 0.20*(self.eye_x - mouse_x)
dy = 0.20*(self.eye_y - mouse_y)
self.x = mouse_x+dx
self.y = mouse_y+dy
pygame.mouse.set_pos((self.x, self.y))
if(self.shot):
self.wait_time-=1
if(self.wait_time <= 0):
self.wait_time = 25
def get_location(self):
return (self.x, self.y)
##====================================================