def CheckImp(self, position, direction): #use other funcs later if not self.buffer and self.accuracy == 0: #zero accuracy makes it melee if direction == 0: direction = 3 #doesn't go out of range else: direction -= 1 #goes left as melee attack change = 0 #the position change made if direction == 0: change -= funcs.DropLine() elif direction == 1: change += 1 elif direction == 2: change += funcs.DropLine() elif direction == 3: change -= 1 if self.IsEdge(position, direction) and self.accuracy == 0: return False if config.MAP[position + change] == config.Color9: #if hit zone self.Loss() #destroy bullet return False elif config.MAP[position + change] != config.Color0 and config.MAP[position + change] != config.Color5 and config.MAP[position + change] != config.Color8: #nothing or gun print("Projectile hit " + str(config.MAP[position + change])) self.CheckHit(config.MAP[position + change]) #check player hit self.toDie = True #kills projectile next elif self.IsEdge(position + change, direction) and self.accuracy != 0: #on edge self.toDie = True #kills projectile next return True
def ReceiveKey(array): #find a neater way to do this ply = GetPlayer(array[1]) #finds the player if ply != "null": #clears old position and renders the player if there is no collision if array[0] == config.UP: if not Collision(ply, ply.position - funcs.DropLine(), 0, NegNum(funcs.DropLine())): #ClearOld(ply) RenderPlayer(ply) elif array[0] == config.RIGHT: if not Collision(ply, ply.position + 1, 1, 1): #ClearOld(ply) RenderPlayer(ply) elif array[0] == config.LEFT: if not Collision(ply, ply.position - 1, 3, NegNum(1)): #ClearOld(ply) RenderPlayer(ply) elif array[0] == config.DOWN: if not Collision(ply, ply.position + funcs.DropLine(), 2, funcs.DropLine()): #ClearOld(ply) RenderPlayer(ply) elif array[0] == config.SHOOT: #shoots ply.Shoot(PosCheck) elif array[0] == config.CHANGE: #changes your weapon print("A player changed weapon") ply.weapon += 1 #ensures you never excede the weapon count if ply.weapon > len(weapon.WeaponList) - 1: ply.weapon = 0 ply.ChangeWep() #changes the weapon visual RenderPlayer(ply) #renders the player
def CloseZone(): global curTime global zonePoint global zoneDirection if curTime + config.ZoneSpeed < time.time( ): #if enough time has passed to move zone curTime = time.time() #resets timer #if its direction, moves forward and changes direction if necessary if zoneDirection == 1: zonePoint += 1 if zonePoint in right or config.MAP[zonePoint + 1] == config.Color9: zoneDirection = 2 elif zoneDirection == 2: zonePoint += funcs.DropLine() if zonePoint in bottom or config.MAP[ zonePoint + funcs.DropLine()] == config.Color9: zoneDirection = 3 elif zoneDirection == 3: zonePoint -= 1 if zonePoint in left or config.MAP[zonePoint - 1] == config.Color9: zoneDirection = 0 elif zoneDirection == 0: zonePoint -= funcs.DropLine() if zonePoint in top or config.MAP[ zonePoint - funcs.DropLine()] == config.Color9: zoneDirection = 1 #kills player if the player is in the zone if config.MAP[zonePoint] in config.PlayerColors: peep = player.PlayerList[config.PlayerColors.index( config.MAP[zonePoint])] #get the player the zone hit Kill(peep) config.MAP[zonePoint] = config.Color9 #sets the current point to the zone
def PosCheck(position, direction): #checks collisions from base position if direction == 0: return [position, position - 1] elif direction == 1: return [position, position + funcs.DropLine()] elif direction == 2: return [position + funcs.DropLine(), position + funcs.DropLine() - 1] elif direction == 3: return [position - 1, position - 1 + funcs.DropLine()]
def AcMove(self, direction): #moves the player if direction == 0: self.position -= funcs.DropLine() elif direction == 1: self.position += 1 elif direction == 2: self.position += funcs.DropLine() elif direction == 3: self.position -= 1 if not self.buffer: config.MAP[self.old] = config.Color0 #removes old position from map else: self.buffer = False
def AddPlayers(): #dodgy way to calculate spawn points pos1 = game.top[0] + 2 + funcs.DropLine() pos2 = game.right[0] - 1 + funcs.DropLine() pos3 = game.left[config.SIDELEN - 1] + 2 - (funcs.DropLine() * 2) pos4 = game.bottom[0] - 2 - funcs.DropLine() print("Spawn1 : " + str(pos1)) print("Spawn2 : " + str(pos2)) print("Spawn3 : " + str(pos3)) print("Spawn4 : " + str(pos4)) #initially adds all the players Player1 = Player(pos1, 1) Player2 = Player(pos2, 2) Player3 = Player(pos3, 3) Player4 = Player(pos4, 4)
def Collision(ply, position, direction, npos): if ply.lastfired + config.AFTER_FIRE > time.time(): return True if ply.direction != direction: #rotates if not facing that direction if not MoveBod(ply, direction): return True return False #doesn't allow you to move out of the array size if position + funcs.DropLine() >= len(config.MAP): return True #checks next pos elif not NextClear(position, direction): return True #check edge hit elif IsEdge(ply, direction): return True ClearOld(ply) #clears old pos ply.SetPos(npos) #sets the new pos return False
#import funcs PlayerList = [] import time import funcs import config import weapon import projectiles import game drop = funcs.DropLine() class Player: ###important - integrate with funcs### def __init__(self, position, ID): self.position = position #the base player pos #the body part positions self.body1 = position self.body2 = position - 1 self.wep1 = position + drop self.wep2 = position + drop - 1 #player's old positions self.old = [self.body1, self.body2, self.wep1, self.wep2] #current weapon self.weapon = 0 #the current weapon class self.curwep = weapon.WeaponList[self.weapon] #dead or alive self.alive = True #player id self.id = ID #currently reloading or not