-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_atoms_.py
130 lines (106 loc) · 3.56 KB
/
_atoms_.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
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
import co
import random, math
import util
import _neutrons_ as neutrons
import _electrons_ as electrons
import pygame as pyg
class Atom():
def __init__(self, x, y, w, h, vx=0.0, vy=0.0):
self.x = float(x)
self.y = float(y)
self.w = w
self.h = h
self.vx = float(vx)
self.vy = float(vy)
self.texture = None
#States
self.can_decay = False
self.can_absorb_neutron = False
#Objects
self.to_delete = False
self.created_atoms = []
self.created_neutrons = []
self.electron = None
#Value
self.over = 0
def reset(self):
#Objects
self.to_delete = False
self.created_atoms = []
self.created_neutrons = []
self.electron = None
#Value
self.over = 0
def get_position(self):
return (self.x, self.y)
def move(self, r):
self.x += self.vx * r
self.y += self.vy * r
if self.x < 0 or self.x + self.w > co.WIDTH:
self.reflect_vertical()
if self.y < 0 or self.y + self.h > co.HEIGHT:
self.reflect_horizontal()
if self.vx > 0:
self.vx = max(0, self.vx - co.ATOM_BRAKE * r)
elif self.vx < 0:
self.vx = min(0, self.vx + co.ATOM_BRAKE * r)
if self.vy > 0:
self.vy = max(0, self.vy - co.ATOM_BRAKE * r)
elif self.vy < 0:
self.vy = min(0, self.vy + co.ATOM_BRAKE * r)
def reflect_horizontal(self):
self.vy *= -1
def reflect_vertical(self):
self.vx *= -1
def has_created_atoms(self):
return (len(self.created_atoms) > 0)
def has_created_neutrons(self):
return (len(self.created_neutrons) > 0)
def has_emitted_electron(self):
return (self.electron is not None)
def age(self, dt):
pass
def is_hit_by_neutron(self, neutron):
pass
class DecayingAtom(Atom):
def __init__(self, x, y, w, h, decay_time):
super().__init__(x, y, h, w)
self.x0 = x
self.y0 = y
self.can_decay = True
self.decay_time = decay_time
self.initial_decay_time = decay_time
self.over = 1
def reset(self):
self.to_delete = False
self.created_atoms = []
self.created_neutrons = []
self.electron = None
self.over = 1
self.decay_time = self.initial_decay_time
def age(self, dt):
self.decay_time -= dt
max_shake = int(co.DECAY_MAX_SHAKE * (1 - self.decay_time / self.initial_decay_time))
self.x = self.x0 + random.randint(-max_shake, max_shake)
self.y = self.y0 + random.randint(-max_shake, max_shake)
if self.decay_time <= 0:
self.emit_electron()
self.disintegrate()
def disintegrate(self):
pass
def emit_electron(self):
vx, vy = util.polar_to_cartesian(co.ELECTRON_SPEED, random.uniform(0, 2*math.pi))
self.electron = electrons.Electron(self.x0 + self.w / 2, self.y0 + self.h / 2, vx, vy)
class NeutronAtom(Atom):
def __init__(self, x, y, w, h):
super().__init__(x, y, w, h)
self.can_absorb_neutron = True
self.over = 1
def reset(self):
self.to_delete = False
self.created_atoms = []
self.created_neutrons = []
self.electron = None
self.over = 1
def is_hit_by_neutron(self, neutron):
pass