本文整理汇总了Python中net.ConnectionManager.ConnectionManager.startConnection方法的典型用法代码示例。如果您正苦于以下问题:Python ConnectionManager.startConnection方法的具体用法?Python ConnectionManager.startConnection怎么用?Python ConnectionManager.startConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.ConnectionManager.ConnectionManager
的用法示例。
在下文中一共展示了ConnectionManager.startConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Main
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class Main(DirectObject):
def __init__(self):
# Network Setup
self.cManager = ConnectionManager()
self.startConnection()
print "Ran Main"
#taskMgr.add(self.menu, "Menu")
self.login = login()
print "Finished"
def startConnection(self):
"""Create a connection to the remote host.
If a connection cannot be created, it will ask the user to perform
additional retries.
"""
if self.cManager.connection == None:
if not self.cManager.startConnection():
return False
return True
def menu(self, task):
# Accept raw_input choice
self.login = login()
if self.login.getStatus() == "Authorized":
print "going to character Select Menu"
return task.done
return task.again
示例2: Main
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class Main(DirectObject):
def __init__(self):
# Network Setup
self.cManager = ConnectionManager(self)
self.cManager.startConnection()
taskMgr.add(self.menu, "Menu")
def startConnection(self):
"""Create a connection to the remote host.
If a connection cannot be created, it will ask the user to perform
additional retries.
"""
if self.cManager.connection == None:
if not self.cManager.startConnection():
return False
return True
def menu(self, task):
# Accept raw_input choice
choice = input("1 - Rand int\n2 - Rand string\n3 - Rand short\n4 - Rand float\n101 - login\n6 - Exit\n")
msg = 0
username = 0
password = 0
if choice is 1: msg = random.randint(-(2**16), 2**16 - 1)
elif choice is 2: msg = ''.join(random.choice('abcdefghijklmnopqrstuvwxyz') for x in range(7))
elif choice is 3: msg = random.randint(0, 2**16 - 1)
elif choice is 4: msg = 100 * random.random()
elif choice is 101:
username = "user"
password = "pass"
elif choice is 6: sys.exit()
else: print "Invalid input"
if choice is 101:
self.cManager.sendRequest(choice, username+" "+password)
else:
self.cManager.sendRequest(choice, msg);
return task.again
示例3: Main
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class Main(DirectObject):
def __init__(self):
# Network Setup
self.cManager = ConnectionManager()
self.startConnection()
#taskMgr.add(self.menu, "Menu")
base.win.setClearColor(Vec4(0,0,0,1))
self.imageObject = OnscreenImage(parent = render2d, image = 'images/mainPage.png', pos = (0,0,0), scale = (1.444, 1, 1.444))
self.imageObject.setTransparency(TransparencyAttrib.MAlpha)
self.button = DirectButton(image ='images/button.png',pos = (-.1,0,-.25), relief = None, scale = .40,
command = self.startWorld)
self.button.setTransparency(TransparencyAttrib.MAlpha)
#self.cAudio =
def startConnection(self):
"""Create a connection to the remote host.
If a connection cannot be created, it will ask the user to perform
additional retries.
"""
if self.cManager.connection == None:
if not self.cManager.startConnection():
return False
return True
def menu(self, task):
# Accept raw_input choice
choice = input("1 - Rand int\n2 - Rand string\n3 - Rand short\n4 - Rand float\n6 - Exit\n")
msg = 0
if choice is 1: msg = random.randint(-(2**16), 2**16 - 1)
elif choice is 2: msg = ''.join(random.choice('abcdefghijklmnopqrstuvwxyz') for x in range(7))
elif choice is 3: msg = random.randint(0, 2**16 - 1)
elif choice is 4: msg = 100 * random.random()
elif choice is 6: sys.exit()
else: print "Invalid input"
self.cManager.sendRequest(choice, msg);
def startWorld(self):
#send login request
print "elll"
示例4: Main
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class Main(ShowBase):
def __init__(self):
self.state = Constants.GAMESTATE_NOT_LOGGED_IN
self.cManager = ConnectionManager(self)
if self.startConnection():
ShowBase.__init__(self)
self.cManager.initTasks()
self.login = Login(self)
self.characterSelection = CharacterSelection(self)
self.game = Game(self)
self.login.createLoginWindow()
#self.characterSelection.createSelectionWindow()
#self.game.init()
self.run()
def startConnection(self):
"""Create a connection to the remote host.
If a connection cannot be created, it will ask the user to perform
additional retries.
"""
if self.cManager.connection == None:
print 'Connecting...'
if not self.cManager.startConnection():
print 'Connection failed!'
answer = raw_input('Reconnect? (Y/N): ').lower()
if answer == 'y':
return self.startConnection()
else:
return False
return True
示例5: Main
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class Main(ShowBase):
def __init__(self):
self.emitter = EventEmitter()
self.cManager = ConnectionManager(self)
self.tester = Tester(self)
if self.startConnection():
loadPrcFileData("", "window-type none") # disable graphics
loadPrcFileData("", "audio-library-name null") # disable audio
ShowBase.__init__(self)
self.cManager.initTasks()
self.emitter.emit('connection')
self.run()
def startConnection(self):
"""Create a connection to the remote host.
If a connection cannot be created, it will ask the user to perform
additional retries.
"""
if self.cManager.connection == None:
print 'Connecting...'
if not self.cManager.startConnection():
print 'Connection failed!'
answer = raw_input('Reconnect? (Y/N): ').lower()
if answer == 'y':
return self.startConnection()
else:
return False
return True
def emit(event, data = {}): # terrible alias but I already wrote protocol code
self.emitter.emit(event, data)
示例6: Main
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class Main(DirectObject):
def __init__(self):
# Network Setup
self.cManager = ConnectionManager(self)
self.startConnection()
self.login = login(self)
self.name = ""
self.w = None
#taskMgr.add(self.menu, "Menu")
def sendHeartbeat(self, task):
self.cManager.sendRequest(Constants.REQ_HEARTBEAT);
return task.again
def loadWorld(self, x, y, type, name):
character = Character(self.cManager, x, y, type, name)
self.w = World(self, character)
self.characters = {name: character}
#taskMgr.doMethodLater(1, self.sendHeartbeat, 'heartbeat-routine')
taskMgr.doMethodLater(1, self.sendHeartbeat, 'heartbeat-routine')
def startConnection(self):
"""Create a connection to the remote host.
If a connection cannot be created, it will ask the user to perform
additional retries.
"""
if self.cManager.connection == None:
if not self.cManager.startConnection():
return False
return True
示例7: World
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class World(DirectObject):
gameStateDict = {"Login" : 0,"CreateLobby":4, "EnterGame": 1, "BeginGame": 2, "InitializeGame":3}
gameState = -1
# Login , EnterGame , BeginGame
responseValue = -1
currentTime = 0
idleTime = 0
mySequence = None
pandaPace = None
jumpState = False
isWalk = False
previousPos = None # used to store the mainChar pos from one frame to another
host = ""
port = 0
vehiclelist = {} # Stores the list of all the others players characters
characters = []
login = "test2"
def __init__(self):
self.loading = LoadingScreen()
base.setFrameRateMeter(True)
#input states
inputState.watchWithModifiers('forward', 'w')
inputState.watchWithModifiers('left', 'a')
inputState.watchWithModifiers('brake', 's')
inputState.watchWithModifiers('right', 'd')
inputState.watchWithModifiers('turnLeft', 'q')
inputState.watchWithModifiers('turnRight', 'e')
self.keyMap = {"hello": 0, "left": 0, "right": 0, "forward": 0, "backward": 0, "cam-left": 0, "cam-right": 0,
"chat0": 0, "powerup": 0, "reset": 0}
base.win.setClearColor(Vec4(0, 0, 0, 1))
# Network Setup
self.cManager = ConnectionManager(self)
self.startConnection()
#self.cManager.sendRequest(Constants.CMSG_LOGIN, ["username", "password"])
# chat box
# self.chatbox = Chat(self.cManager, self)
# Set up the environment
#
self.initializeBulletWorld(False)
#self.createEnvironment()
Track(self.bulletWorld)
# Create the main character, Ralph
self.mainCharRef = Vehicle(self.bulletWorld, (0, 25, 16, 0, 0, 0), self.login)
#self.mainCharRef = Character(self, self.bulletWorld, 0, "Me")
self.mainChar = self.mainCharRef.chassisNP
#self.mainChar.setPos(0, 25, 16)
# self.characters.append(self.mainCharRef)
# self.TestChar = Character(self, self.bulletWorld, 0, "test")
# self.TestChar.actor.setPos(0, 0, 0)
self.previousPos = self.mainChar.getPos()
taskMgr.doMethodLater(.1, self.updateMove, 'updateMove')
# Set Dashboard
self.dashboard = Dashboard(self.mainCharRef, taskMgr)
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
# Accept the control keys for movement and rotation
self.accept("escape", self.doExit)
self.accept("a", self.setKey, ["left", 1])
self.accept("d", self.setKey, ["right", 1])
self.accept("w", self.setKey, ["forward", 1])
self.accept("s", self.setKey, ["backward", 1])
self.accept("arrow_left", self.setKey, ["cam-left", 1])
self.accept("arrow_right", self.setKey, ["cam-right", 1])
self.accept("a-up", self.setKey, ["left", 0])
self.accept("d-up", self.setKey, ["right", 0])
self.accept("w-up", self.setKey, ["forward", 0])
self.accept("s-up", self.setKey, ["backward", 0])
self.accept("arrow_left-up", self.setKey, ["cam-left", 0])
self.accept("arrow_right-up", self.setKey, ["cam-right", 0])
self.accept("h", self.setKey, ["hello", 1])
self.accept("h-up", self.setKey, ["hello", 0])
self.accept("0", self.setKey, ["chat0", 1])
self.accept("0-up", self.setKey, ["chat0", 0])
self.accept("1", self.setKey,["powerup", 1])
self.accept("1-up", self.setKey,["powerup", 0])
self.accept("2", self.setKey,["powerup", 2])
self.accept("2-up", self.setKey,["powerup", 0])
self.accept("3", self.setKey,["powerup", 3])
self.accept("3-up", self.setKey,["powerup", 0])
self.accept("r", self.doReset)
self.accept("p", self.setTime)
#self.loading.finish()
#.........这里部分代码省略.........
示例8: __init__
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class UserGUIHandler:
endCharId = 0
def __init__(self):
self.frame = None
self.buttonFrame = None
self.dl = None
self.dl2 = None
self.dl3 = None
self.regSel = None
self.loginSel = None
self.uid = None
self.pwd = None
self.reg = None
self.submit = None
self.lbl = None
self.errorLbl = None
self.directRadioButtonHandler = None
print "UserGUIHandler Init"
self.playerId = ""
self.loginState = -1
self.registerState = -1
self.worldManager = finalhw1.WorldManager()
self.world = self.worldManager.w
self.connectionManager = ConnectionManager(self)
self.world.setConnectionManager(self.connectionManager)
self.connectionManager.startConnection()
def register(self):
self.clearEverything()
self.createFrame(-0.7)
self.errorLbl = DirectLabel(text="", pos=Vec3(0, 0, 0.55), frameColor=(0.5, 0.5, 0.5, 0.5), scale=0.11)
self.dl = DirectLabel(text="", pos=Vec3(0, 0, 0.8), frameColor=(0.3, 0.2, 0.1, 0.5), scale=0.11)
self.dl["text"] = "Welcome To Game Registration Page"
self.dl2 = DirectLabel(text="", pos=Vec3(0, 0, 0.4), frameColor=(0.5, 0.5, 0.5, 0.5), scale=0.1)
self.dl2["text"] = "USERNAME"
self.uid = DirectEntryHandler(0.2, 0)
self.dl3 = DirectLabel(text="", pos=Vec3(0, 0, 0.0), frameColor=(0.5, 0.5, 0.5, 0.5), scale=0.1)
self.dl3["text"] = "PASSWORD"
self.pwd = DirectEntryHandler(-0.2, 1)
self.reg = DirectButtonHandler("Register", -0.4, self)
self.reg.setUidPwd(self.uid, self.pwd)
def showFirstPage(self):
self.createFrame(-0.7)
self.dl = DirectLabel(text="", pos=Vec3(0, 0, 0.8), frameColor=(0.3, 0.2, 0.1, 0.5), scale=0.11)
self.dl["text"] = "Welcome To New Game"
self.dl2 = DirectLabel(text="", pos=Vec3(0, 0, 0.5), frameColor=(0.5, 0.5, 0.5, 0.5), scale=0.11)
self.dl2["text"] = "Click for Registration"
self.dl3 = DirectLabel(text="", pos=Vec3(0, 0, -0.1), frameColor=(0.5, 0.5, 0.5, 0.5), scale=0.11)
self.dl3["text"] = "Click for Login"
self.regSel = DirectButton(text="Register", scale=0.1, pos=(0, 0, 0.3), command=self.initRegister)
self.loginSel = DirectButton(text="Login", scale=0.1, pos=(0, 0, -0.3), command=self.initLogin)
def initRegister(self):
self.clearEverything()
self.register()
def initLogin(self):
self.clearEverything()
self.login()
def setLogin(self, state, inCharId, x, y, h):
self.loginState = state
self.chosenCharId = inCharId
self.x = x
self.y = y
self.h = h
def setRegister(self, state):
self.registerState = state
def createFrame(self, inLength):
self.clearEverything()
self.frame = DirectFrame(
relief=DGG.RAISED, borderWidth=(0.05, 0.05), frameSize=(-1, 1, -1, 1), frameColor=(0.3, 0.2, 0.1, 0.5)
)
self.buttonFrame = DirectFrame(
parent=self.frame,
relief=DGG.RAISED,
borderWidth=(0.05, 0.05),
frameSize=(-0.7, 0.7, inLength, 0.7),
frameColor=(0.5, 0.5, 0.5, 0.5),
pos=(-0, 0, 0),
)
def login(self):
self.clearEverything()
self.createFrame(-0.7)
self.dl = DirectLabel(text="", pos=Vec3(0, 0, 0.8), frameColor=(0.3, 0.2, 0.1, 0.5), scale=0.11)
self.dl["text"] = "Enter Your Personal Details To Login"
self.errorLbl = DirectLabel(text="", pos=Vec3(0, 0, 0.55), frameColor=(0.5, 0.5, 0.5, 0.5), scale=0.11)
#.........这里部分代码省略.........
示例9: selectcharandteamtype
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class selectcharandteamtype(DirectObject):
TEXT_COLOR = (1,1,1,1)
FONT_TYPE_01 = 0
TEXT_SHADOW_COLOR = (0,0,0,0.5)
characterSelectionInput = ""
output = ""
frame = DirectFrame()
#character creation varaiables
v=[0]
v1=[0]
nameOfChar = OnscreenText()
nameOfCharTextbox = DirectEntry()
factionSelection = OnscreenText()
nameOfCharInput =''
charactertype = OnscreenText()
def __init__(self):
print 'Loading character selection...'
self.cManager = ConnectionManager()
self.startConnection()
frame = DirectFrame(frameColor=(0, 0, 0, 1), #(R,G,B,A)
frameSize=(-3, 3, -3, 3),#(Left,Right,Bottom,Top)
pos=(-0.5, 0, 0.5))
self.createCreateCharWindow()
def startConnection(self):
"""Create a connection to the remote host.
If a connection cannot be created, it will ask the user to perform
additional retries.
"""
if self.cManager.connection == None:
if not self.cManager.startConnection():
return False
return True
#character Creation
def createCreateCharWindow(self):
self.frame = DirectFrame(frameColor=(0, 0, 0, 1), #(R,G,B,A)
frameSize=(-3, 3, -3, 3),#(Left,Right,Bottom,Top)
pos=(-0.5, 0, 0.9))
self.charactertype = OnscreenText(text = "Character type :", pos = (-0.60, 0.32), scale = 0.08,fg=(1,0.5,0.5,1),align=TextNode.ACenter,mayChange=0)
self.factionSelection.reparentTo(self.frame)
self.buttons = [
DirectRadioButton(text = ' Axe ', variable=self.v, value=[0], scale=0.07, pos=(-0.05,0,0.32), command=self.setText),
DirectRadioButton(text = ' Sword ', variable=self.v, value=[1], scale=0.07, pos=(0.3,0,0.32), command=self.setText)
]
for button in self.buttons:
button.setOthers(self.buttons)
self.factionSelection = OnscreenText(text = "Faction Selection :", pos = (-0.15, -0.95), scale = 0.08,fg=(1,0.5,0.5,1),align=TextNode.ACenter,mayChange=0)
self.factionSelection.reparentTo(self.frame)
self.factionBtns = [
DirectRadioButton(text = ' Blue ', variable=self.v1, value=[0], scale=0.07, pos=(-0.05,0,-0.05), command=self.setfaction),
DirectRadioButton(text = ' Red ', variable=self.v1, value=[1], scale=0.07, pos=(0.3,0,-0.05), command=self.setfaction)
]
for button1 in self.factionBtns:
button1.setOthers(self.factionBtns)
self.okForCreateBtn = DirectButton(text = ("Start", "Start", "Start", "disabled"), scale=.08, command=self.clickedOkForCreateBtn, pos=(-0.05, 0.0, -1.25))
self.cancelForCreateBtn = DirectButton(text = ("Cancel", "Cancel", "Cancel", "disabled"), scale=.08, command=self.clickedCancelForCreateBtn, pos=(0.4, 0.0, -1.25))
self.okForCreateBtn.reparentTo(self.frame)
self.cancelForCreateBtn.reparentTo(self.frame)
def destroyCreateCharWindow(self):
self.frame.destroy()
self.nameOfChar.destroy()
self.nameOfCharTextbox.destroy()
self.factionSelection.destroy()
self.okForCreateBtn.destroy()
self.cancelForCreateBtn.destroy()
def clearnameOfChar(self):
self.nameOfCharTextbox.enterText('')
def getnameOfChar(self):
self.nameOfCharInput = self.nameOfCharTextbox.get()
def setnameOfChar(self, textEntered):
print "name Of Char: ",textEntered
self.nameOfChar = textEntered
def clickedOkForCreateBtn(self):
self.nameOfCharInput = self.nameOfCharTextbox.get().strip()
print "you have pressed the ok button for creating a character"
print "you have Created a char of type",self.chartitle,";Faction : ",self.factiontitle
self.cManager.sendRequest(Constants.CMSG_CREATE_CHARACTER, (self.chartitle, self.factiontitle));
def clickedCancelForCreateBtn(self):
#.........这里部分代码省略.........
示例10: World
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class World(DirectObject):
def __init__(self):
__builtin__.main = self
self.taskMgr = taskMgr
self.base = base
# Connect to the server
self.cManager = ConnectionManager()
self.startConnection()
self.characters = dict()
self.cpList = dict()
# Login as 'CPHandler'
# Temporary workaround, can add a seperate request/response for client/NPC client logins later
self.username = "CPHandler"
type = 0
factionId = 0
self.cManager.sendRequest(Constants.CMSG_AUTH, [self.username, type, factionId])
# Create control points
self.cpList[1] = BasicControlPoint(1, 210.984, 115.005, 0, 10, RED)
self.cpList[2] = BasicControlPoint(2, 141.016, 0.440607, 0, 10, RED)
self.cpList[3] = BasicControlPoint(3, -0.766843, 9.40588, 0, 10, RED)
self.cpList[4] = BasicControlPoint(4, -210.771, 113.753, 0, 10, BLUE)
self.cpList[5] = BasicControlPoint(5, -149.953, 0.674369, 0, 10, BLUE)
taskMgr.doMethodLater(0.1, self.refresh, "heartbeat")
taskMgr.doMethodLater(1, self.CPHandler, 'CPHandler')
def startConnection(self):
if self.cManager.connection == None:
if not self.cManager.startConnection():
return False
return True
def refresh(self,task):
self.cManager.sendRequest(Constants.REQ_HEARTBEAT)
return task.again
def CPHandler(self, task):
for cp in self.cpList.values():
if cp.factionId == RED:
if cp.checkContested(self.characters):
print("CP [", cp.id, "] is contested")
elif cp.checkBluePresence(self.characters):
cp.timer -= 1
print(cp.id, cp.timer)
if cp.timer == 0:
print("CP [", cp.id, "] taken by Blue")
cp.factionId = BLUE
#main.controlNpc.switchControl(cp.id)
self.cManager.sendRequest(Constants.CMSG_NPCDEATH, [cp.id])
print "Sending Message : ",
print cp.id
else:
cp.timer = 30
elif cp.factionId == BLUE:
if cp.checkContested(self.characters):
print("CP [", cp.id, "] contested")
elif cp.checkRedPresence(self.characters):
cp.timer += 1
print(cp.id, cp.timer)
if cp.timer == 30:
print("CP [", cp.id, "] taken by Red")
cp.factionId = RED
#main.controlNpc.switchControl(cp.id)
self.cManager.sendRequest(Constants.CMSG_NPCDEATH, [cp.id])
else:
cp.timer = 0
# Send 'timer' to server, which send to all clients
self.cManager.sendRequest(Constants.CMSG_CONTROL_POINT_STATE, [cp.id, cp.timer, cp.factionId])
return task.again;
示例11: World
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class World(DirectObject):
def __init__(self):
#create Queue to hold the incoming chat
#request the heartbeat so that the caht interface is being refreshed in order to get the message from other player
self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0, "charge":0}
base.win.setClearColor(Vec4(0,0,0,1))
self.cManager = ConnectionManager()
self.cManager.startConnection()
#------------------------------
#Chat
Chat(self.cManager)
#send dummy login info of the particular client
#send first chat info
#---------------------------------------
self.userName = username
dummy_login ={'user_id' : self.userName, 'factionId': faction, 'password': '1234'}
self.cManager.sendRequest(Constants.RAND_STRING, dummy_login)
chat = { 'userName' : self.userName, #username
'message' : '-------Login------' }
self.cManager.sendRequest(Constants.CMSG_CHAT, chat)
#--------------------------------------
#self.minimap = OnscreenImage(image="images/minimap.png", scale=(0.2,1,0.2), pos=(-1.1,0,0.8))
#frame = DirectFrame(text="Resource Bar", scale=0.001)
resource_bar = DirectWaitBar(text="",
value=35, range=100, pos=(0,0,0.9), barColor=(255,255,0,1),
frameSize=(-0.3,0.3,0,0.03))
cp_bar = DirectWaitBar(text="",
value=70, range=100, pos=(1.0,0,0.9), barColor=(0,0,255,1),
frameSize=(-0.3,0.3,0,0.03), frameColor=(255,0,0,1))
# Set up the environment
#
# This environment model contains collision meshes. If you look
# in the egg file, you will see the following:
#
# <Collide> { Polyset keep descend }
#
# This tag causes the following mesh to be converted to a collision
# mesh -- a mesh which is optimized for collision, not rendering.
# It also keeps the original mesh, so there are now two copies ---
# one optimized for rendering, one for collisions.
self.environ = loader.loadModel("models/world")
self.environ.reparentTo(render)
self.environ.setPos(0,0,0)
# Create the main character, Ralph
ralphStartPos = self.environ.find("**/start_point").getPos()
self.ralph = Actor("models/ralph",
{"run":"models/ralph-run",
"walk":"models/ralph-walk"})
self.ralph.reparentTo(render)
self.ralph.setScale(.2)
self.ralph.setPos(ralphStartPos)
nameplate = TextNode('textNode username_' + str(self.userName))
nameplate.setText(self.userName)
npNodePath = self.ralph.attachNewNode(nameplate)
npNodePath.setScale(0.8)
npNodePath.setBillboardPointEye()
#npNodePath.setPos(1.0,0,6.0)
npNodePath.setZ(6.5)
bar = DirectWaitBar(value=100, scale=1.0)
bar.setColor(255,0,0)
#bar.setBarRelief()
bar.setZ(6.0)
bar.setBillboardPointEye()
bar.reparentTo(self.ralph)
# Create a floater object. We use the "floater" as a temporary
# variable in a variety of calculations.
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
# Accept the control keys for movement and rotation
self.accept("escape", sys.exit)
self.accept("arrow_left", self.setKey, ["left",1])
self.accept("arrow_right", self.setKey, ["right",1])
self.accept("arrow_up", self.setKey, ["forward",1])
self.accept("a", self.setKey, ["cam-left",1])
self.accept("s", self.setKey, ["cam-right",1])
self.accept("arrow_left-up", self.setKey, ["left",0])
self.accept("arrow_right-up", self.setKey, ["right",0])
self.accept("arrow_up-up", self.setKey, ["forward",0])
#.........这里部分代码省略.........
示例12: characterSelection
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class characterSelection(DirectObject):
TEXT_COLOR = (1,1,1,1)
FONT_TYPE_01 = 0
TEXT_SHADOW_COLOR = (0,0,0,0.5)
characterSelectionInput = ""
output = ""
frame = DirectFrame()
#character selection varaiables
createCharacter = DirectButton()
deleteCharacter = DirectButton()
selectCharacter = OnscreenText()
selectCharacterTextbox = DirectEntry()
selectCharacterInput=''
referenceForSelection = OnscreenText()
myScrolledList = DirectScrolledList()
submitBtn = DirectButton()
cancelBtn = DirectButton()
#character deletion varaiables
selectCharactertodelete = OnscreenText()
deleteBtn = DirectButton()
delCancelBtn = DirectButton()
CharacterToDeleteTextbox = DirectEntry()
referenceForDeletion = OnscreenText()
CharacterToDeleteInput = ' '
#character creation varaiables
v=[0]
v1=[0]
nameOfChar = OnscreenText()
nameOfCharTextbox = DirectEntry()
factionSelection = OnscreenText()
nameOfCharInput =''
def __init__(self, usernameInput):
self.currentUser = usernameInput
print 'Loading character selection...'
self.cManager = ConnectionManager(self)
self.startConnection()
frame = DirectFrame(frameColor=(0, 0, 0, 1), #(R,G,B,A)
frameSize=(-3, 3, -3, 3),#(Left,Right,Bottom,Top)
pos=(-0.5, 0, 0.5))
self.createSelectionWindow()
def startConnection(self):
"""Create a connection to the remote host.
If a connection cannot be created, it will ask the user to perform
additional retries.
"""
if self.cManager.connection == None:
if not self.cManager.startConnection():
return False
return True
#character Creation
def createCreateCharWindow(self):
self.frame = DirectFrame(frameColor=(0, 0, 0, 1), #(R,G,B,A)
frameSize=(-3, 3, -3, 3),#(Left,Right,Bottom,Top)
pos=(-0.5, 0, 0.9))
self.buttons = [
DirectRadioButton(text = ' Ralph ', variable=self.v, value=[0], scale=0.07, pos=(-0.4,0,0.32), command=self.setText),
DirectRadioButton(text = ' Car ', variable=self.v, value=[1], scale=0.07, pos=(0.0,0,0.32), command=self.setText),
DirectRadioButton(text = ' Panda ', variable=self.v, value=[2], scale=0.07, pos=(0.4,0,0.32), command=self.setText)
]
for button in self.buttons:
button.setOthers(self.buttons)
self.nameOfChar = OnscreenText(text = "Name The Character :", pos = (-0.2, -0.75), scale = 0.08,fg=(1,0.5,0.5,1),align=TextNode.ACenter,mayChange=0)
self.nameOfChar.reparentTo(self.frame)
self.nameOfCharTextbox = DirectEntry(text = "" ,scale=.07,pos=(0.25,0, -.75),command=self.setnameOfChar,initialText="name of character", numLines = 1,focus=0,focusInCommand=self.clearnameOfChar, focusOutCommand=self.getnameOfChar)
self.nameOfCharTextbox.reparentTo(self.frame)
self.okForCreateBtn = DirectButton(text = ("Ok", "Ok", "Ok", "disabled"), scale=.08, command=self.clickedOkForCreateBtn, pos=(-0.05, 0.0, -1.25))
self.cancelForCreateBtn = DirectButton(text = ("Cancel", "Cancel", "Cancel", "disabled"), scale=.08, command=self.clickedCancelForCreateBtn, pos=(0.4, 0.0, -1.25))
self.okForCreateBtn.reparentTo(self.frame)
self.cancelForCreateBtn.reparentTo(self.frame)
def destroyCreateCharWindow(self):
self.frame.destroy()
self.nameOfChar.destroy()
self.nameOfCharTextbox.destroy()
self.factionSelection.destroy()
self.okForCreateBtn.destroy()
self.cancelForCreateBtn.destroy()
def clearnameOfChar(self):
self.nameOfCharTextbox.enterText('')
def getnameOfChar(self):
self.nameOfCharInput = self.nameOfCharTextbox.get()
def setnameOfChar(self, textEntered):
print "name Of Char: ",textEntered
self.nameOfChar = textEntered
#.........这里部分代码省略.........
示例13: World
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class World(DirectObject):
gameStateDict = {"Login" : 0,"CreateLobby":4, "EnterGame": 1, "BeginGame": 2, "InitializeGame":3}
gameState = -1
# Login , EnterGame , BeginGame
responseValue = -1
currentTime = 0
idleTime = 0
mySequence = None
pandaPace = None
jumpState = False
isWalk = False
previousPos = None # used to store the mainChar pos from one frame to another
host = ""
port = 0
vehiclelist = {} # Stores the list of all the others players characters
characters = []
def __init__(self):
self.login = "test2"
base.setFrameRateMeter(True)
#input states
inputState.watchWithModifiers('forward', 'w')
inputState.watchWithModifiers('left', 'a')
inputState.watchWithModifiers('brake', 's')
inputState.watchWithModifiers('right', 'd')
inputState.watchWithModifiers('turnLeft', 'q')
inputState.watchWithModifiers('turnRight', 'e')
self.keyMap = {"hello": 0, "left": 0, "right": 0, "forward": 0, "backward": 0, "cam-left": 0, "cam-right": 0,
"chat0": 0, "powerup": 0, "reset": 0}
base.win.setClearColor(Vec4(0, 0, 0, 1))
# Network Setup
self.cManager = ConnectionManager(self)
self.startConnection()
#self.cManager.sendRequest(Constants.CMSG_LOGIN, ["username", "password"])
# chat box
# self.chatbox = Chat(self.cManager, self)
# Set up the environment
#
self.initializeBulletWorld(False)
#self.createEnvironment()
Track(self.bulletWorld)
# Create the main character, Ralph
self.mainCharRef = Vehicle(self.bulletWorld, (100, 10, 5, 0, 0, 0), self.login)
#self.mainCharRef = Character(self, self.bulletWorld, 0, "Me")
self.mainChar = self.mainCharRef.chassisNP
#self.mainChar.setPos(0, 25, 16)
# self.characters.append(self.mainCharRef)
# self.TestChar = Character(self, self.bulletWorld, 0, "test")
# self.TestChar.actor.setPos(0, 0, 0)
self.previousPos = self.mainChar.getPos()
taskMgr.doMethodLater(.1, self.updateMove, 'updateMove')
# Set Dashboard
self.dashboard = Dashboard(self.mainCharRef, taskMgr)
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
# Accept the control keys for movement and rotation
self.accept("escape", self.doExit)
self.accept("a", self.setKey, ["left", 1])
self.accept("d", self.setKey, ["right", 1])
self.accept("w", self.setKey, ["forward", 1])
self.accept("s", self.setKey, ["backward", 1])
self.accept("arrow_left", self.setKey, ["cam-left", 1])
self.accept("arrow_right", self.setKey, ["cam-right", 1])
self.accept("a-up", self.setKey, ["left", 0])
self.accept("d-up", self.setKey, ["right", 0])
self.accept("w-up", self.setKey, ["forward", 0])
self.accept("s-up", self.setKey, ["backward", 0])
self.accept("arrow_left-up", self.setKey, ["cam-left", 0])
self.accept("arrow_right-up", self.setKey, ["cam-right", 0])
self.accept("h", self.setKey, ["hello", 1])
self.accept("h-up", self.setKey, ["hello", 0])
self.accept("0", self.setKey, ["chat0", 1])
self.accept("0-up", self.setKey, ["chat0", 0])
self.accept("1", self.setKey,["powerup", 1])
self.accept("1-up", self.setKey,["powerup", 0])
self.accept("2", self.setKey,["powerup", 2])
self.accept("2-up", self.setKey,["powerup", 0])
self.accept("3", self.setKey,["powerup", 3])
self.accept("3-up", self.setKey,["powerup", 0])
self.accept("r", self.doReset)
self.accept("p", self.setTime)
#taskMgr.add(self.move, "moveTask")
# Game state variables
#.........这里部分代码省略.........
示例14: Main
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class Main(DirectObject):
def __init__(self):
# Network Setup
self.cManager = ConnectionManager(self)
self.cManager.startConnection()
# self.login = login(self)
taskMgr.add(self.menu, "Menu")
def menu(self, task):
self.option = 0
choice = input("1-Register\n2-Login\n3-Exit\n")
msg = 0
self.username = ""
self.password = ""
self.cpassword = ""
if choice is 1:
self.username = str(raw_input("Enter the username\n"))
self.password = str(raw_input("Enter the password\n"))
self.cpassword = str(raw_input("Confirm password\n"))
if self.password == self.cpassword:
self.cManager.sendRequest(Constants.CMSG_REGISTER, self.username+" "+self.password)
elif choice is 2:
self.username = str(raw_input("Enter the username\n"))
self.password = str(raw_input("Enter the password\n"))
self.cManager.sendRequest(Constants.CMSG_AUTH, self.username+" "+self.password);
elif choice is 3:
sys.exit()
else: print "Invalid input"
def processingLoginResponse(self, data):
self.msg1 = data.getInt32()
if self.msg1:
self.pl_list = []
self.user = data.getString().split(" ")
self.pl_count = data.getInt32()
print "welcome ",self.user[1]
print "No of players logged in- ", self.pl_count
for num in range (0,self.pl_count):
self.pl_list.append([num+1,data.getString()])
# print self.pl_list
#h(self,self.welcome,self.pl_list)
charlist =["Car","Ralph","Panda1","Panda2"]
usedlist =[]
for l in self.pl_list :
pl = l[1].split(",")
usedlist.append(pl[1])
charlist.remove(pl[1])
print "Pick a Available Charactor", charlist
role = raw_input("")
print self.user[1]
print role
self.cManager.sendRequest(Constants.CMSG_CREATE_CHARACTER, self.user[1]+" "+role)
# self.world.CharSelect(self.welcome,self.pl_list)
else :
print "Username Or Password invalid"
def processingCreateResponse(self, data):
self.msg1 = data.getInt32()
if self.msg1:
self.pl_list = []
self.name = data.getString()
self.char = data.getString()
self.pl_count = data.getInt32()
for num in range (0,self.pl_count):
self.pl_list.append([num+1,data.getString()])
# print self.pl_list
self.StartGame = self.Start(self)
# def CharSelect(self, welcome, userList):
# self.welcome = welcome
# self.userList = userList
# self.charSelect = characterSelection(self)
# def Logout(self):
# print "Logout"
# def Game(self,user,char,count,playerlist):
# self.user = user
# self.char = char
# self.count = count
# self.playerlist = playerlist
# print self.user
# print self.char
#.........这里部分代码省略.........
示例15: Main
# 需要导入模块: from net.ConnectionManager import ConnectionManager [as 别名]
# 或者: from net.ConnectionManager.ConnectionManager import startConnection [as 别名]
class Main(DirectObject):
def __init__(self):
# Network Setup
self.cManager = ConnectionManager()
self.startConnection()
taskMgr.add(self.menu, "Menu")
def startConnection(self):
"""Create a connection to the remote host.
If a connection cannot be created, it will ask the user to perform
additional retries.
"""
if self.cManager.connection == None:
if not self.cManager.startConnection():
return False
return True
def menu(self, task):
# Accept raw_input choice
choice = input("1 - Rand int\n2 - Rand string\n3 - Rand short\n4 - Rand float\n6 - Exit\n101 - login\n102 - Disconnect\n103 - Register\n104 - Forget Password\n105 - Create Character\n106 - Chat\n107 - Move\n108 - Power Up\n109 - Power Pick Up\n110 - Health\n122 - Results\n123 - Rankings\n124 - Prizes\n125 - Collistion\n126 - Dead\n127 - Ready\n")
msg = 0
username = 0
password = 0
if choice is 1: msg = random.randint(-(2**16), 2**16 - 1)
elif choice is 2: msg = ''.join(random.choice('abcdefghijklmnopqrstuvwxyz') for x in range(7))
elif choice is 3: msg = random.randint(0, 2**16 - 1)
elif choice is 4: msg = 100 * random.random()
elif choice is 100:
self.cManager.sendRequest(101, "username password")
elif choice is 101:
username = "vatsal"
password = "sevak"
self.cManager.sendRequest(choice, username+" "+password)
elif choice is 102:
self.cManager.sendRequest(choice, msg)
elif choice is 103:
username = "test2"
password = "1234"
#email = "[email protected]"
self.cManager.sendRequest(choice, username+" "+password)
elif choice is 104:
username = "vatsal"
email = "[email protected]"
self.cManager.sendRequest(choice, username+" "+email)
elif choice is 105:
username = "vatsal"
classtype = 1
self.cManager.sendRequest(choice, username+" "+str(classtype))
elif choice is 106:
message = "Hi How are you?"
self.cManager.sendRequest(choice, message)
elif choice is 107:
x = 0
y = 0
z = 0
h = 0
self.cManager.sendRequest(choice, ""+str(x)+" "+str(y)+" "+str(z)+" "+str(h))
elif choice is 108:
x = 5
self.cManager.sendRequest(choice, x)
elif choice is 109:
x = 10
self.cManager.sendRequest(choice, x)
elif choice is 110:
username = "vatsal"
healthChange = 2
self.cManager.sendRequest(choice, username+" "+str(healthChange))
elif choice is 122:
gameId = 1
self.cManager.sendRequest(choice, gameId)
elif choice is 123:
gameId = 1
self.cManager.sendRequest(choice, gameId)
elif choice is 124:
username = "vatsal"
self.cManager.sendRequest(choice, username)
elif choice is 125:
playerId = 1
damage = 1
self.cManager.sendRequest(choice, ""+str(playerId)+" "+str(damage))
elif choice is 126:
dead = 1
self.cManager.sendRequest(choice, dead)
elif choice is 127:
ready = 1
self.cManager.sendRequest(choice, ready)
elif choice is 128:
self.cManager.sendRequest(301)
elif choice is 6:
sys.exit()
else:
print "Invalid input"
#.........这里部分代码省略.........