Exemplo n.º 1
0
	def handle(self, dgram, addr):
		controls=control.ControlsFrame(dgram)
		if controls.uid not in self.clients:
			e=model.Entity.from_json(self, random.randint(0,9999), loader.assets("player"))
			self.entities[e.eid]=e
			self.clients[controls.uid]=control.ClientData(self, controls.uid, e)
			self.post_chat_message("SERVER", "Player "+controls.usrname+" has joined!")
			[self.sock.sendto(d, addr) for d in self.build_message(controls.uid, True)]
			thread.start_new_thread(self.send_loop, (controls.uid, addr))

		self.clients[controls.uid].process_frame(controls)
Exemplo n.º 2
0
import lobby, loader

loader.assets.load_dir("assets_shared")

server=lobby.LobbyServer(loader.assets("baseserver"))
server.loop()
Exemplo n.º 3
0
def respawn(self, message):
    if not self.dead:
        self.outgoing_chat_buffer.append(["[ERROR] You are alive", "SERVER"])
    else:
        self.dead = False
        self.player_entity = model.Entity.from_json(self.game, random.randint(0, 9999), loader.assets("player"))
        self.game.entities[self.player_entity.eid] = self.player_entity
Exemplo n.º 4
0
	def act(self, frame, dt):
		self.last_bullet_fired+=dt

		if frame.jump and self.player_entity.on_ground:
			self.player_entity.vel_y=-118

		if frame.left:
			self.player_entity.vel_x=-65

		if frame.right:
			self.player_entity.vel_x=65

		if frame.gun and self.player_entity.energy>=loader.assets("gun")["fire_cost"] and self.last_bullet_fired>loader.assets("gun")["fire_cooldown"]:
			e=model.Entity.from_json(self.game, None, loader.assets("gunbullet1"))
			mult=loader.assets("gun")["bullet_speed"]/(abs(frame.mousex-self.player_entity.x)+abs(frame.mousey-self.player_entity.y))
			e.vel_x=(frame.mousex-self.player_entity.x)*mult
			e.vel_y=(frame.mousey-self.player_entity.y)*mult
			e.x, e.y = self.player_entity.rect.center
			e.parent=self.player_entity.eid
			self.game.entities[e.eid]=e
			self.player_entity.energy-=loader.assets("gun")["fire_cost"]
			self.last_bullet_fired=0

		self.player_entity.joulegun_target=0
		if frame.suck or frame.blow:
			mouse_target=None
			for e in self.game.entities.values():
				if e.rect.collidepoint((frame.mousex, frame.mousey)):
					if isinstance(e, model.JouledEntity):
						mouse_target=e

			flow_rate=20*dt
			if mouse_target:
				# if frame.suck and mouse_target.energy>=flow_rate and self.player_entity.energy<=self.player_entity.energy_max:
				# 	mouse_target.energy-=flow_rate
				# 	self.player_entity.energy+=flow_rate
				# 	self.player_entity.sucking=True
				# 	self.player_entity.joulegun_target=mouse_target.eid

				# if frame.blow and self.player_entity.energy>=flow_rate and mouse_target.energy<=mouse_target.energy_max:
				# 	mouse_target.energy+=flow_rate
				# 	self.player_entity.energy-=flow_rate
				# 	self.player_entity.sucking=False
				# 	self.player_entity.joulegun_target=mouse_target.eid

				if frame.suck and mouse_target.energy>0 and self.player_entity.energy<self.player_entity.energy_max:
					mouse_target.energy-=flow_rate
					self.player_entity.energy+=flow_rate
					self.player_entity.sucking=True
					self.player_entity.joulegun_target=mouse_target.eid

					if mouse_target.energy<0:
						self.player_entity.energy+=mouse_target.energy
						mouse_target.energy=0
					if self.player_entity.energy>self.player_entity.energy_max:
						mouse_target.energy+=self.player_entity.energy-self.player_entity.energy_max

				elif frame.blow and self.player_entity.energy>0 and mouse_target.energy<mouse_target.energy_max:
					mouse_target.energy+=flow_rate
					self.player_entity.energy-=flow_rate
					self.player_entity.sucking=False
					self.player_entity.joulegun_target=mouse_target.eid

					if self.player_entity.energy<0:
						mouse_target.energy+=self.player_entity.energy
						self.player_entity.energy=0
					if mouse_target.energy>mouse_target.energy_max:
						self.player_entity.energy+=mouse_target.energy-mouse_target.energy_max

		self.player_entity.jetpacking=False
		if frame.jetpack:
			rate = loader.assets("jetpack")["accel"]*dt
			cost = rate*loader.assets("jetpack")["ratio"]
			if self.player_entity.energy>=cost:
				self.player_entity.jetpacking=True
				self.player_entity.energy-=cost
				self.player_entity.vel_y-=rate