Player
Player contains the things necessary to player control of units.
Player class taken from PlayerController made by Sean. Added around 2000 self.'s, changed while loop to update class. Entity updating and time moved to main.
9:00pm 17/05/06 file : Player.py
from visual import *
from Entity import *
from random import *
class Player:
TroopList=[]
selection=[] #currently selected Entities
def __init__(self,ARandomEntity): #class needs init
temp = ARandomEntity
self.TroopList.append(temp)
ARandomEntity = ARandomEntity.nextEnt
while(temp !=ARandomEntity):
self.TroopList.append(ARandomEntity)
ARandomEntity = ARandomEntity.nextEnt
def getObj(self, obj):
for i in range (0,len(self.TroopList)):
if(self.TroopList[i].graphic==obj):
return self.TroopList[i] #will want to put conditions to see if it should be selected
def AddObjectToSelection(self, obj):
picked=self.getObj(obj)
if (picked!=None):
self.selection.append(picked)
def dumpList(self, list):
for i in range (0,len(list)):
list.pop()
def Update(self): #replaced while loop with update
if scene.mouse.clicked:
m=scene.mouse.getclick()
if(scene.mouse.pick==None and len(self.selection)>0 and m.alt==1): #deselect all
self.dumpList(selection)
print "deselected"
elif(scene.mouse.pick!=None and m.ctrl==1): #add a unit to selection
self.AddObjectToSelection(scene.mouse.pick)
print "added object to selection"
elif(scene.mouse.pick!=None): #select one unit
self.dumpList(self.selection)
self.AddObjectToSelection(scene.mouse.pick)
print("selected an object")
elif(len(self.selection)>0): #issue move order(s)
print "order given"
for i in range (0,len(self.selection)):
self.selection[i].orderMove(m.pos)