-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathantimatter.py
59 lines (45 loc) · 1.56 KB
/
antimatter.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
from bge import logic
import types
from mathutils import Vector
from math import ceil
from random import random
from particle import Particle
gdict = logic.globalDict
def antimatter(cont):
#module called by stars and antimatter
particle = cont.owner
if particle.name != "Antimatter":
particle = Particle(particle)
particle.annihilate = types.MethodType(annihilate,particle)
particle.collisionCallbacks.append(particle.annihilate)
def annihilate(self,atom):
#sever bonds
if "bonds" not in atom:
#not matter
if self.name == "Antimatter":
self.endObject()
return
### in state 2, it executes self_destruct safely without other controllers
atom.self_destruct()
##stars and floor also annihilate things
if self.name == "Antimatter":
for i in range(0,100):
photon = self.scene.addObject("Photon",atom,ceil(100 * random()))
photon.applyForce(Vector([random() ,random(),random()]) * 5000 - Vector([2500,2500,2500]))
self.scene.addObject("Explosion_sound",self)
self.endObject()
def self_destruct(cont):
atom = cont.owner
for adjacent in atom.get_bonds():
if adjacent.invalid:
continue
if adjacent.name == "Lone Pair":
adjacent.endObject()
else:
atom.unlink(adjacent)
type = atom.name
if atom in gdict["atoms"]:
gdict["atoms"].remove(atom)
gdict["cations"].discard(atom)
gdict["free"][type].discard(atom)
atom.endObject()