-
Notifications
You must be signed in to change notification settings - Fork 1
/
participant.py
56 lines (42 loc) · 1.52 KB
/
participant.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
55
56
import pygame
width = 1100
height = 650
fps = 60
striker_radius = height//15
peg_radius = int(striker_radius//1.5)
class Striker():
"""This is class for striker and peg"""
def __init__(self,color,color_outline,radius,x, y):
self.color = color
self.radius = radius
self.color_outline = color_outline
self.x = x
self.y = y
self.position = (x, y)
def get_position(self):
return (self.position)
def draw(self, win):
pygame.draw.circle(win, self.color, self.position, self.radius,0)
pygame.draw.circle(win,self.color_outline,self.position,self.radius,self.radius//10)
def move(self):
pos = pygame.mouse.get_pos()
self.x = pos[0]
self.y = pos[1]
self.update()
def update(self):
self.position = (self.x, self.y)
class pegs(Striker):
def __init__(self,color,color_outline,radius,x, y):
super().__init__(color,color_outline,radius,x, y)
self.vx, self.vy = 0, 0
def draw(self, win):
pygame.draw.circle(win,self.color,(self.x, self.y),self.radius,0)
pygame.draw.circle(win,self.color_outline,(self.x, self.y),self.radius,self.radius//10)
def move(self):
if(self.y >= (height - peg_radius) or self.y <= peg_radius): #if gets at the lower wall (y of peg >=480) or upper wall( y of peg <= 20)
self.vy = (-1)*self.vy # just reverses the direction of the vy
if(self.x >= (width - peg_radius) or self.x <= peg_radius): # if gets hit at right or the left wall respectively
self.vx = (-1)*self.vx # just reverses the direction of vx
self.x += self.vx
self.y += self.vy
self.update()