import bge import socket import fcntl import os import string import time import random import bpy sce = bge.logic.getCurrentScene() cont = bge.logic.getCurrentController() obj = cont.owner keyboard = bge.logic.keyboard keyb = cont.sensors['keyb'] JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED PLAY = bge.logic.KX_ACTIONACT_PLAY nick = "testblender" + str(random.randint(0, 9)) #host = "localhost" host = "irc.geeknode.net" #host = "irc.freenode.net" port = 6667 ident = "ofrii" channel = "#bigrec" owner = "ourii" charset = "utf-8" #print(dir(sce.objects["Armature.cheval"])) #print(dir(bpy.data)) class RingBuffer: def __init__(self, size, fill=None): self.data = [fill for i in range(size)] def append(self, x): self.data.pop(0) self.data.append(x) def get(self): return self.data #print(keyboard.events.get(0)) def init(): if not 'init' in obj: obj['init'] = 1 print('ININIIT') try: s = socket.socket() s.connect((host, int(port))) except: print("pas de connectyzion") pass print("NICK " + nick + "\r\n") s.send(bytes("NICK " + nick + "\r\n", charset)) s.send(bytes("USER " + ident + " " + host + " pythonstuff :" + owner + "\r\n", charset)) s.send(bytes("JOIN " + channel + "\r\n", charset)) fl = fcntl.fcntl(s, fcntl.F_GETFL) fcntl.fcntl(s, fcntl.F_SETFL, fl | os.O_NONBLOCK) obj['socket'] = s obj['readbuffer'] = "" obj['debut'] = 0 obj['prompt'] = " " obj['buf'] = RingBuffer(4, "") obj['cheval'] = 0 obj['serpent'] = 0 return obj['socket'] def send(msg): print("SEND: " + msg) s.send(bytes(msg, charset)) def readlines(s): try: data = s.recv(1024) except: return [] readbuffer= obj['readbuffer'] readbuffer=readbuffer+data.decode('UTF-8') lines = readbuffer.split("\n") obj['readbuffer'] = lines.pop() return lines def reagit(): if keyboard.events[bge.events.ZKEY]: print("Activate Forward!") obj.applyForce([0,-2,0], True) if keyboard.events[bge.events.SKEY]: obj.applyForce([0,2,0], True) if keyboard.events[bge.events.AKEY] == JUST_ACTIVATED: print("Activate Left!") obj.applyForce([-18,0,0], True) if keyboard.events[bge.events.DKEY] == JUST_ACTIVATED: print("Activate Right!") obj.applyForce([18,0,0], True) if keyboard.events[bge.events.ENTERKEY]: obj['debut'] = 1 sce.objects["oba"]["debug"] = 'pri' #.objects["cheval"]) #["Armature.cheval"] # sce.objects["Armature.cheval"]["debug"] def prompt(): # print(keyb.events) for key,status in keyb.events: if status == JUST_ACTIVATED: pro = (("%c") % (key)) obj['prompt'] += pro sce.objects["Text.001"].text = obj['prompt'] if key == bge.events.ENTERKEY: # s.send(bytes(obj['prompt'], charset)) send("PRIVMSG #bigrec :"+ obj['prompt'] + "\r\n") # s.send('PRIVMSG ' + channel + ' :Hello.\r\n') obj['prompt'] = " " sce.objects["Text.001"].text = obj['prompt'] def cheval (action): obj['marche'] = 0 if action == 'cheval': obj['cheval'] = 1 ob2 = sce.addObject("chal",sce.objects["oba"]) sce.objects["Armature.cheval"].playAction('patiente', 1, 80,layer=0,priority=1, blendin=0,layer_weight=0.5, play_mode=bge.logic.KX_ACTION_MODE_LOOP) if action == 'marche': obj['marche'] = 1 if obj['marche'] != 0: sce.objects["chal"].setLinearVelocity([3.2, 0.0 , 0.0], 1) sce.objects["Armature.cheval"].stopAction() sce.objects["Armature.cheval"].playAction('chevmarche1', 1, 50,layer=0,priority=1, blendin=0,layer_weight=0.5, play_mode=bge.logic.KX_ACTION_MODE_LOOP) if action == 'stop': obj['marche'] = 0 # sce.objects["chal"].setLinearVelocity([0.0, 0.0, 0.0], 1) sce.objects["Armature.cheval"].stopAction() sce.objects["Armature.cheval"].playAction('patiente', 1, 80,layer=0,priority=1, blendin=0,layer_weight=0.5, play_mode=bge.logic.KX_ACTION_MODE_LOOP) def serpent (action): if action == 'serpent': obj['serpent'] = 1 ob2 = sce.addObject("snak",sce.objects["obo"]) if action =='danse': sce.objects["Armature.serpent"].playAction('danse', 1, 188,layer=0,priority=1, blendin=0,layer_weight=0.5, play_mode=bge.logic.KX_ACTION_MODE_LOOP) if action =='arretedanse': sce.objects["Armature.serpent"].stopAction() def chaussure (action): if action == 'chaussure': ob2 = sce.addObject("chaussure",sce.objects["obu"]) ###[MAIN CODE]### s = init() for line in readlines(s): print (line) if (line.find("PING")): s.send(bytes("PONG " + line + "\r\n", charset)) if obj['debut'] != 0: #ecran_général : |||||||||||||||||||||||||||||||||| if line.find("PRIVMSG"): dog = line[line.find("#")+ (len(channel)) :line.find("\r")] #message obj['buf'].append(dog) # print(str(obj['duu'])) sce.objects["Text"].text = ("[%s]" % " ! ".join(obj['buf'].get())) # fin ecran\||||||||||||||||||||||||||||||||||||||| #cheval if str(line).find ( "cheval" ) != -1: cheval('cheval') if obj['cheval'] != 0: if str(line).find ( "marche" ) != -1: cheval('marche') if str(line).find ( "stop" ) != -1: cheval('stop') # if obj['avance'] != : #\cheval #serpent if str(line).find ( "serpent" ) != -1: serpent('serpent') if str(line).find ( "danse" ) != -1: serpent('danse') if str(line).find ( "arretedanse" ) != -1: serpent('arretedanse') if str(line).find ( "chaussure" ) != -1: chaussure('chaussure') #/serpent # deplacement cube suivant longueur for i in range(len(line)): obj.applyForce([1,0,0], True) # fin deplacement cube\ if str(line).find ( "jaune" ) != -1: obj.color = [1,1,0,1] if str(line).find ( "vert" ) != -1: obj.color = [0,1,0,1] if str(line).find ( "rouge" ) != -1: obj.color = [1,0,0,1] if str(line).find ( "noir" ) != -1: obj.color = [0,0,0,1] if str(line).find ( "transparent" ) != -1: obj.color = [0,0,0,0.5] # ob2.position.z += (random.randfloat(void)) reagit() prompt() # souvenirs # 00101011000 # | 00010000000 # ------------- # = 00111011000 # 00111011000 # | 00010000000 # ------------- # = 00111011000