Exemple #1
0
 def doNet(self):
     #if isServer:
     #	checktimeouts()
     while simplenet.checkdata():
         packet, peer = simplenet.nextpacket()
         if packet is None: break
         pType = packet[0]
         pData = packet[1]
         #print pType, pData
         if simplenet.isServer:
             cl = self.findclient(peer)
             if cl != None: cl.lastpackettime = 0
             if pType=="join":
                 cl = self.addClient(pData, peer)
                 if cl is None:
                     simplenet.sendto("joinfailed", "alreadyjoined?", peer)
                 else:
                     simplenet.sendto("yourein", "dosomethingcool", peer)
             elif cl is None:
                 simplenet.sendto("whoyou", "i didnt get join message", peer)
             elif pType == "event":
                 self.handleEvent(pData, cl)
         else:#client
             if pType=="gamestate":
                 self.gamestate = pData
                 self.clients = self.gamestate.clients
                 self.walkers = self.clients
                 for w in range(len(self.walkers)):
                     if self.walkers[w].name == self.name:
                         self.mywalker = self.walkers[w]
             elif pType=="boom":
                 terrain.explode(pData[0], pData[1], pData[2], pData[3])
             elif pType=="pastetex":
                 terrain.pastesurfID(pData[0], pData[1], pData[2], pData[3], pData[4])
             elif pType=="addtps":
                 particles.addTextParticle(pData[0], pData[1], pData[2], pData[3], pData[4], pData[5])
             elif pType=="addps":
                 particles.addParticle(pData[0], pData[1], pData[2], pData[3], pData[4], pData[5], pData[6])
                 #print pData
             elif pType=="msg":
                 #addmsg(pData[0], pData[1])
                 print(pData)
             elif pType=="whoyou":
                 simplenet.sendserv("join", self.name)
             elif pType=="wakeup":
                 simplenet.sendserv("keepalive", "dude")
Exemple #2
0
 def shootabullet(self):
     xv = self.owner.gmx-self.owner.cx
     yv = self.owner.gmy-self.owner.cy
     self.length = hypot(xv,yv)
     if self.length == 0:self.length = 0.001
     xvn=xv/self.length
     yvn=yv/self.length
     poix = self.owner.cx+xvn*26
     poiy = self.owner.cy+yvn*26
     terrain.explode(poix,poiy,30,10)
     for c in self.owner.gamestate.clients:
         if c is self.owner: continue
         xd = c.cx - poix
         yd = c.cy - poiy
         td = xd * xd + yd * yd
         if td < 29*29:
             c.xvel+=xvn*20
             c.yvel+=yvn*20
             c.damage(30, self.owner)
     self.timetofire = self.firedelay
     particles.addParticle(poix, poiy, 0.5, "sword2.png", 3, 1)
Exemple #3
0
    def fixpos(self, xm=0, ym=0):
        'called when the player is inside some land while moving'
        #self.x-=self.xn
        #self.y-=self.yn
        tn = terrain.getnormal(int(self.x)+xm, int(self.y)+ym)
        self.landcolour = terrain.getcolour(self.x,self.y)
        self.tnx = tn[0]
        self.tny = tn[1]
        impx = tn[0]*self.xvel
        impy = tn[1]*self.yvel
        impd = impx*impx+impy*impy
        if impd>(23*23):
          #print impd/100
          brad = int(impd/100)
          if brad > 30: brad = 30
          terrain.explode(self.x,self.y,brad)
          self.damage(impd/100,self)
          particles.addParticle(self.x, self.y, 0.4, "blood.png", 1.5, 3)
        #print self.tnx,self.tny
        if self.tny < 0.1:
            self.onground = 1
            self.canjump = 1

        self.x += self.tnx/2
        self.y += self.tny/2

        dp = self.xn*(-self.tny)+self.yn*self.tnx
        self.xn = -self.tny*dp
        self.yn = self.tnx*dp
        #else:
        self.xvel = self.xn*self.vel
        self.yvel = self.yn*self.vel
        if self.crouchkey == 1:
            self.xvel += -self.tnx#*self.vel wtf? FIXME whossis do
            self.yvel += -self.tny#*self.vel
        if self.digkey and self.lastdig+20 < timer.totaltime:
            terrain.explode(int(self.x), int(self.y), 30, 20)
            self.dugg = 1
            self.lastdig = timer.totaltime
Exemple #4
0
    def update(self):
        self.updatebullets()
        if self.resetcount > 0:
          if self.resetcount == 1:
            self.reset()
          self.resetcount-=1
          return
        self.yvel+=0.4#grav
        if self.vel > 5 and self.onground:
          particles.addParticle(self.x, self.y, 0.3, "smoke.png", 0.8, 2,self.landcolour)
        self.reaim()
        if self.isbot:
          self.beabot()
        self.wasonground = self.onground
        self.gun.update()
        self.altgun.update()
        if terrain.getalpha(int(self.x), int(self.y)) > 128:
            terrain.explode(int(self.x), int(self.y)-19, 20)



        #input
        self.dugg = 0
        self.jumpwait -= 1
        if self.jumpkey and self.canjump and self.jumpwait<0:
            particles.addParticle(self.x, self.y, 1, "smoke.png", 1.5, 3)
            self.canjump = self.onground
            self.jumpwait=5
            self.yvel-=3
            self.yvel+=self.tny*3
            self.xvel+=self.tnx*3
            #self.jumpsound.play()
        #if self.crouchkey == 1 and self.onground == 1:
        #    pass
        #else:
        '''if self.crouchkey == 0 or self.onground == 0:
            self.yvel+=0.225
            if self.onground == 0:
                self.yvel+=0.125
        '''
        movmult = 0.8-self.crouchkey*0.08
        if self.upkey:self.yvel-=0.12
        if self.dnkey:self.yvel+=0.4
        if self.ltkey:
            self.xvel-=movmult
            #self.yvel-=self.tnx*movmult
            #self.xvel+=self.tny*movmult
        if self.rtkey:
            self.xvel+=movmult
            #self.yvel+=self.tnx*movmult
            #self.xvel-=self.tny*movmult

        #figure some rotation
        #if self.tny> 0.5:self.tnx = 0.5
        self.dnx = self.dnx*0.9+self.tnx*0.1
        self.dny = self.dny*0.9+self.tny*0.1
        mag = hypot(self.dnx, self.dny)
        self.dnx/=mag
        self.dny/=mag


        self.tnx *=0.8
        self.tny = self.tny*0.8-0.2
        mag = hypot(self.tnx, self.tny)
        self.tnx/=mag
        self.tny/=mag
        turntime = timer.turntime
        #print turntime
        #self.xvel*=timer.turntime
        #self.yvel*=timer.turntime
        #phys
        self.yvel*=0.99#*timer.turntime
        self.xvel*=0.99#*timer.turntime
        self.vel = hypot(self.xvel, self.yvel)
        if self.vel < 1:
            self.xn = self.xvel
            self.yn = self.yvel
            self.movesleft = 1
        else:
            self.xn = self.xvel/self.vel
            self.yn = self.yvel/self.vel
            self.movesleft = self.vel
        self.onground = 0
        maxcol = 10
        while self.movesleft > 0 and maxcol > 0:
            self.x+=self.xn
            self.y+=self.yn
            self.checkbounds()
            self.movesleft-=1
            if terrain.getalpha(int(self.x), int(self.y)) > 128:
                self.fixpos()
                self.movesleft+=1
                maxcol-=1
            '''elif terrain.getalpha(int(self.x+3), int(self.y)) > 128:
                self.fixpos(3, 0)
                self.movesleft+=1
                maxcol-=1
            elif terrain.getalpha(int(self.x-3), int(self.y)) > 128:
                self.fixpos(-3, 0)
                self.movesleft+=1
                maxcol-=1
            elif terrain.getalpha(int(self.x), int(self.y-3)) > 128:
                self.fixpos(0, -3)
                self.movesleft+=1
                maxcol-=1
            elif terrain.getalpha(int(self.x), int(self.y-6)) > 128:
                self.fixpos(0, -6)
                self.movesleft+=1
                maxcol-=1'''

        self.cx = self.x+self.dnx*16
        self.cy = self.y+self.dny*16
        self.angle = -atan2(self.dnx, self.dny)/3.141573*180
        self.aimgle = -atan2(self.mx, self.my)/3.141573*180
Exemple #5
0
 def explode(self, radius):
     setto = self.destalpha
     terrain.explode(self.x, self.y, radius, setto)
     for p in self.owner.gamestate.walkers:
         p.bang(self.x, self.y+5, radius*1.8, setto,self.owner)