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

Commit

Permalink
Merge pull request #63 from I-Am-The-Great/new-add-ons
Browse files Browse the repository at this point in the history
Added portal powerup and optimized images.
  • Loading branch information
MattZ45986 authored Jan 15, 2019
2 parents d1681d4 + adeee48 commit aa93182
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
1.3.8
audioCache
replays

.idea
.bsac
.bsac2
.bsuuid
Expand Down
5 changes: 5 additions & 0 deletions mods/Portal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Portal powerup",
"author": "The Great",
"category": "libraries"
}
118 changes: 118 additions & 0 deletions mods/Portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import bs
import random
import bsUtils
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
if position1 is None:
self.position1 = self.getRandomPosition(activity)
else :
self.position1 = position1
self.position2 = self.getRandomPosition(activity)

self.portal1Material = bs.Material()
self.portal1Material.addActions(conditions=(('theyHaveMaterial', bs.getSharedObject('playerMaterial'))),actions=(("modifyPartCollision","collide",True),
("modifyPartCollision","physical",False),
("call","atConnect", self.Portal1)))

self.portal2Material = bs.Material()
self.portal2Material.addActions(conditions=(('theyHaveMaterial', bs.getSharedObject('playerMaterial'))),actions=(("modifyPartCollision","collide",True),
("modifyPartCollision","physical",False),
("call","atConnect", self.Portal2)))
# uncomment the following lines to teleport objects also
# self.portal1Material.addActions(conditions=(('theyHaveMaterial', bs.getSharedObject('objectMaterial')),'and',('theyDontHaveMaterial', bs.getSharedObject('playerMaterial'))),actions=(("modifyPartCollision","collide",True),
# ("modifyPartCollision","physical",False),
# ("call","atConnect", self.objPortal1)))
# self.portal2Material.addActions(conditions=(('theyHaveMaterial', bs.getSharedObject('objectMaterial')),'and',('theyDontHaveMaterial', bs.getSharedObject('playerMaterial'))),actions=(("modifyPartCollision","collide",True),
# ("modifyPartCollision","physical",False),
# ("call","atConnect", self.objPortal2)))


self.node1 = bs.newNode('region',
attrs={'position':(self.position1[0],self.position1[1],self.position1[2]),
'scale':(self.radius,self.radius,self.radius),
'type':'sphere',
'materials':[self.portal1Material]})
self.visualRadius = bs.newNode('shield',attrs={'position':self.position1,'color':color,'radius':0.1})
bsUtils.animate(self.visualRadius,"radius",{0:0,500:self.radius*2})
bsUtils.animateArray(self.node1,"scale",3,{0:(0,0,0),500:(self.radius,self.radius,self.radius)})


self.node2 = bs.newNode('region',
attrs={'position':(self.position2[0],self.position2[1],self.position2[2]),
'scale':(self.radius,self.radius,self.radius),
'type':'sphere',
'materials':[self.portal2Material]})
self.visualRadius2 = bs.newNode('shield',attrs={'position':self.position2,'color':color,'radius':0.1})
bsUtils.animate(self.visualRadius2,"radius",{0:0,500:self.radius*2})
bsUtils.animateArray(self.node2,"scale",3,{0:(0,0,0),500:(self.radius,self.radius,self.radius)})


def Portal1(self):
node = bs.getCollisionInfo('opposingNode')
node.handleMessage(bs.StandMessage(position = self.node2.position))

def Portal2(self):
node = bs.getCollisionInfo('opposingNode')
node.handleMessage(bs.StandMessage(position = self.node1.position))

def objPortal1(self):
node = bs.getCollisionInfo('opposingNode')
node.position = self.position2

def objPortal2(self):
node = bs.getCollisionInfo('opposingNode')
node.position = self.position1

def delete(self):
if self.node1.exists() and self.node2.exists():
self.node1.delete()
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):

pts = copy.copy(activity.getMap().ffaSpawnPoints)
pts2 = activity.getMap().powerupSpawnPoints
for i in pts2:
pts.append(i)
pos = [[999, -999], [999, -999], [999, -999]]
for pt in pts:
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 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)
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
2 changes: 1 addition & 1 deletion mods/snowyPowerup.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "Modified bsPowerup.py",
"author": "joshville79",
"category": "libraries",
"requires": ["BuddyBunny", "SnoBallz"]
"requires": ["BuddyBunny", "SnoBallz", "Portal"]
}
25 changes: 24 additions & 1 deletion mods/snowyPowerup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import BuddyBunny
import SnoBallz
import bsPowerup
import bsSpaz
import Portal
from bsPowerup import PowerupMessage, PowerupAcceptMessage, _TouchedMessage, PowerupFactory, Powerup


Expand Down Expand Up @@ -35,6 +37,7 @@ def __init__(self):
self.powerupSound = bs.getSound("powerup01")
self.powerdownSound = bs.getSound("powerdown01")
self.dropSound = bs.getSound("boxDrop")
self.texPort = bs.getTexture("ouyaOButton")

# material for powerups
self.powerupMaterial = bs.Material()
Expand Down Expand Up @@ -84,6 +87,7 @@ def getDefaultPowerupDistribution():
('shield',2),
('health',1),
('bunny',2),
('portal',2),
('curse',1),
('snoball',3))

Expand Down Expand Up @@ -111,6 +115,7 @@ def __init__(self,position=(0,1,0),powerupType='tripleBombs',expire=True):
elif powerupType == 'shield': tex = factory.texShield
elif powerupType == 'health': tex = factory.texHealth
elif powerupType == 'curse': tex = factory.texCurse
elif powerupType == 'portal': tex = factory.texPort
elif powerupType == 'bunny':
tex = factory.texEgg
mod = factory.eggModel
Expand Down Expand Up @@ -142,6 +147,10 @@ def __init__(self,position=(0,1,0),powerupType='tripleBombs',expire=True):
bs.gameTimer(defaultPowerupInterval-2500,bs.WeakCall(self._startFlashing))
bs.gameTimer(defaultPowerupInterval-1000,bs.WeakCall(self.handleMessage,bs.DieMessage()))

def delpor(self):
Portal.currentnum -= 1
self.port.delete()

def handleMessage(self,m):
self._handleMessageSanityCheck()

Expand All @@ -160,7 +169,7 @@ def handleMessage(self,m):
#We won't tell the spaz about the bunny. It'll just happen.
if self.powerupType == 'bunny':
p=node.getDelegate().getPlayer()
if not 'bunnies' in p.gameData:
if 'bunnies' not in p.gameData:
p.gameData['bunnies'] = BuddyBunny.BunnyBotSet(p)
p.gameData['bunnies'].doBunny()
self._powersGiven = True
Expand All @@ -172,6 +181,20 @@ def handleMessage(self,m):
SnoBallz.snoBall().getFactory().giveBallz(spaz)
self._powersGiven = True
self.handleMessage(bs.DieMessage())
elif self.powerupType == 'portal':
t = bsSpaz.gPowerupWearOffTime
if Portal.currentnum < Portal.maxportals :
Portal.currentnum += 1
if self.node.position in Portal.lastpos :
self.port = Portal.Portal(position1 = None,r = 0.9,color = (random.random(),random.random(),random.random()),activity = bs.getActivity())
bs.gameTimer(t,bs.Call(self.delpor))
else :
m = self.node.position
Portal.lastpos.append(m)
self.port = Portal.Portal(position1 = self.node.position,r = 0.9,color = (random.random(),random.random(),random.random()),activity = bs.getActivity())
bs.gameTimer(t,bs.Call(self.delpor))
self._powersGiven = True
self.handleMessage(bs.DieMessage())
else:
node.handleMessage(PowerupMessage(self.powerupType,sourceNode=self.node))

Expand Down
Binary file modified screenshots/ModManagerWindow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/SettingsWindow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aa93182

Please sign in to comment.