-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
88 lines (65 loc) · 1.97 KB
/
functions.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
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
import math
import pygame
from pygame import mixer
def sh(x, y, sh_img, screen):
screen.blit(sh_img, (x, y))
def fire(x, y, f_img, screen):
screen.blit(f_img, (x, y))
def shoot(x,y,b_img,screen):
screen.blit(b_img,(x,y))
def coin(x, y, c_image, screen):
screen.blit(c_image, (x, y))
# num * num * num * num ---> bool (type signature)
def fire_out(s_x, s_y, f_x, f_y):
d = math.sqrt(pow(s_x - f_x, 2) + pow(s_y - f_y, 2))
if (d < 20):
return True
else:
return False
def bullet_out(s_x,s_y,b_x,b_y):
d = math.sqrt(pow(s_x - b_x, 2) + pow(s_y - b_y, 2))
if (d < 20):
return True
else:
return False
# num * num * num * num * num * num ---> bool
def line_out(x1, y1, x2, y2, sh_x, sh_y):
m = (y2 - y1) / (x2 - x1)
d = -1 * ((m * sh_x) - (sh_y) + (y1 - m * x1)) / \
math.sqrt(1 + m * m) # line eq is m*x-y+(y1-m*x1)
if (sh_x > x1 and sh_x < x2):
if (d < (3) and d > -50):
return True
else:
return False
# num * num * num * num ---> bool
def drag_out(xs, ys, xd, yd):
d = math.sqrt(pow(xs - xd, 2) + pow(ys - yd, 2))
if (d < 90):
return True
else:
return False
def gunman_out(xs, ys, xg, yg):
d = math.sqrt(pow(xs - xg, 2) + pow(ys - yg, 2))
if (d < 90):
return True
else:
return False
# num * num * num * num ---> bool
def collect(c_x, c_y, s_x, s_y):
d = math.sqrt(pow((c_x - s_x), 2) + pow((c_y - s_y), 2))
if (d < 35):
mixer.init()
coin_sound = mixer.Sound("coins.wav") # coins sound
coin_sound.play()
c_x = 2000
c_y = 2000
return True
else:
return False
# num * num ---> bool
def cactus_out(sh_img_x, sh_img_y):
if ((sh_img_x == 20 and sh_img_y >= 0) or (sh_img_x == 1140 and sh_img_y >= 0)):
return True
else:
return False