def movev(self, vx, vy): vel = hypot(vx, vy)+0.000000001 #if vel < 1: # xn = vx # yn = vy # movesleft = 1 #else: xn = vx/vel yn = vy/vel movesleft = int(vel) #self.onground = 0 maxcol = 10 while movesleft > 0 and maxcol > 0: self.x+=xn self.y+=yn self.checkbounds() movesleft-=1 if terrain.getalpha(int(self.x), int(self.y)) > 128: self.fixpos() xn = self.xn yn = self.yn movesleft+=1 maxcol-=1
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
def move(self): self.yvel +=self.grav self.yvel *=self.drag self.xvel *=self.drag self.vel = hypot(self.xvel, self.yvel) self.xn = self.xvel /self.vel self.yn = self.yvel /self.vel xs = self.x -self.xn*4 ys = self.y -self.yn*4 maxmoves = self.vel/5 if maxmoves > 15: maxmoves = 15 while maxmoves > 0: maxmoves -= 1 self.x += self.xn*5 self.y += self.yn*5 #if self.x > terrain.x2 - 10: # self.x-=terrain.x2-20 # #self.x = terrain.x2 - 10 # #self.finalHitLand() # break if self.y > terrain.y2*3: self.dead = 1 break #if self.y > terrain.y2 - 10: # self.y-=terrain.y2-20 # #self.y = terrain.y2 - 10 # #self.finalHitLand() # break #if self.x < 10: # self.x+=terrain.x2-20 # #self.x = 10 # #self.finalHitLand() # break #if self.y < 10: # self.y+=terrain.y2-20 # #self.y = 10 # #self.finalHitLand() # break if terrain.getalpha(int(self.x), int(self.y)) > 128: self.x -= self.xn*4 self.y -= self.yn*4 while terrain.getalpha(int(self.x), int(self.y)) < 128: self.x += self.xn self.y += self.yn self.bouncecount +=1 if self.bouncecount > self.maxbounces: self.finalHitLand() break self.hitLand() if self.bouncing: tn = terrain.getnormal(int(self.x), int(self.y)) self.x += tn[0]#*3 self.y += tn[1]#*3 nv = self.reflect(self.xn, self.yn, tn[0], tn[1]) self.xn = nv[0] self.yn = nv[1] self.xvel *= 0.7 self.yvel *= 0.7 self.xvel = self.xn * self.vel self.yvel = self.yn * self.vel #self.movPix() self.totalmoves -= 1 if self.totalmoves < 0: self.timeUp() self.dead = 1 for c in self.owner.gamestate.clients: if c is self.owner: continue xd = c.cx - self.x yd = c.cy - self.y td = xd * xd + yd * yd if td < 250: self.hitPlayer(c) self.movDone(xs, ys, self.x - self.xn * 4, self.y - self.yn * 4) return 0