Skip to content
This repository has been archived by the owner on Jan 22, 2023. It is now read-only.

Commit

Permalink
Update Portal.py.
Browse files Browse the repository at this point in the history
Updated the Portal.py to not let two portal openings open at the same position. Uhm I did not totally change the random position finder code by @spdv123 but modified it a little bit.
  • Loading branch information
Rahul Raman authored Jan 14, 2019
1 parent 98b467e commit 6a8b75c
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions mods/Portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
import copy
import types

# Following are necessary variables for portal
maxportals = 3
currentnum = 0
lastpos = [(0,0,0), (1, 0, 2)] # initial values for test
defi = [(0, 1, 2), (1, 0, 2)] # initial values for test

class Portal(bs.Actor):
def __init__(self,position1 = (0,1,0),color = (random.random(),random.random(),random.random()),r = 1.0,activity = None):
bs.Actor.__init__(self)

self.radius = r
self.position1 = position1
if position1 is None:
self.position1 = self.getRandomPosition(activity)
else :
self.position1 = position1
self.position2 = self.getRandomPosition(activity)

self.portal1Material = bs.Material()
Expand Down Expand Up @@ -72,6 +81,19 @@ def delete(self):
self.node2.delete()
self.visualRadius.delete()
self.visualRadius2.delete()
if self.position1 in lastpos:
lastpos.remove(self.position1)
defi.remove(self.node2.position)

def posn(self, s , act):
ru = random.uniform
rc = random.choice
f = rc([(s[0], s[1], s[2]-ru(0.1, 0.6)), (s[0], s[1], s[2]+ru(0.1, 0.6)), (s[0]-ru(0.1, 0.6), s[1], s[2]), (s[0]+ru(0.1, 0.6), s[1], s[2])])
if f in defi or f in lastpos :
return self.getRandomPosition(act)
else :
defi.append(f)
return f

def getRandomPosition(self, activity):

Expand All @@ -84,8 +106,13 @@ def getRandomPosition(self, activity):
for i in range(3):
pos[i][0] = min(pos[i][0], pt[i])
pos[i][1] = max(pos[i][1], pt[i])
# the credit of this random position finder goes to Deva
# The credit of this random position finder goes to Deva but I did some changes too.
ru = random.uniform
ps = pos
t = ru(ps[0][0] - 1.0, ps[0][1] + 1.0), ps[1][1] + ru(0.1, 1.5), ru(ps[2][0] - 1.0, ps[2][1] + 1.0)
return (t[0],t[1]-ru(0.9,1.3),t[2])
s = (t[0],t[1]-ru(1.0,1.3),t[2])
if s in defi or s in lastpos :
return self.posn(s, activity)
else :
defi.append(s)
return s

0 comments on commit 6a8b75c

Please sign in to comment.