public void attach(PlayerCharacter pc) { if (lastOwner == pc || owner == pc) return; owner = pc; this.velocity = Vector2.Zero; LevelUp(); }
// Should be called by the server to create a player entity in the current game state public PlayerCharacter createPlayer(int posX, int posY, PlayerCharacter.Type type) { PlayerCharacter pc; switch (type) // Create a new character based on the type { case PlayerCharacter.Type.Doctor: pc = new Doctor(context, posX, posY); break; case PlayerCharacter.Type.Rogue: pc = new Rogue(context, posX, posY); break; case PlayerCharacter.Type.Tank: pc = new Tank(context, posX, posY); break; case PlayerCharacter.Type.Wizard: pc = new Wizard(context, posX, posY); break; case PlayerCharacter.Type.JarCat: pc = new JarCat(context, posX, posY); break; default: throw new ArgumentException(); } // Add the new entity and create an appropriate state to accompany it addEntity(100, pc, pc.id); players.Add(pc); StateChange sc = StateChangeFactory.createEntityStateChange(pc.id, posX, posY, pc.frameWidth, pc.GetFrameTime(), pc.getDefaultTexture(), pc.scale, 100); changes.Add(sc); // Add a health bar to the player attachHealthWithStateChange(pc); return pc; }
/// <summary> /// Constructor. /// </summary> public GameplayScreen(bool isServer, bool isMultiplayer, int numPlayers, int playerId, PlayerCharacter.Type[] characterSelections, Dictionary<int, ConnectionID> playerIdToConnectionHash) { // Set up server, multiplayer and character information this.isServer = isServer; this.isMultiplayer = isMultiplayer; this.numPlayers = numPlayers; this.characterSelections = characterSelections; this.playerIdToConnectionHash = playerIdToConnectionHash; // Set the screen transition times TransitionOnTime = TimeSpan.FromSeconds(1.5); TransitionOffTime = TimeSpan.FromSeconds(0.5); // Set up the spawning rates and times maxMinEnemiesSpawn = 3 * numPlayers; minMinEnemiesSpawn = 1; maxMaxEnemiesSpawn = 4 * numPlayers; minMaxEnemiesSpawn = numPlayers; maxSpawnInterval = TimeSpan.FromSeconds(30.0); minSpawnInterval = TimeSpan.FromSeconds(20.0); currentSpawnInterval = maxSpawnInterval; currentMaxEnemiesSpawn = minMaxEnemiesSpawn; currentMinEnemiesSpawn = minMinEnemiesSpawn; nextEnemySpawnTime = DateTime.Now; spawnRandom = new Random(); spawnMinX = 300; spawnMaxX = 1550; spawnMinY = 600; spawnMaxY = 1250; // Set the game state gameState = new GameState(this); return; }
public void refire(PlayerCharacter pc, Vector2 velocity) { if (owner == pc) { lastOwner = owner; owner = null; this.velocity = velocity; hits.Clear(); } }