Creating a GameMode

From Serious Sam's Bogus Detour
Revision as of 15:42, 24 June 2017 by Scratch (talk | contribs)

Jump to: navigation, search

Note

This article is describing features that are currently unreleased, but will be released in a future patch.


The plain and simple basic BaseGameMode example described here will cause null dereference exceptions.

Gamemodes define rules about what should happen on a level. They are set in a level file. Typically when making a gamemode, you'll want to inherit the class from either BaseGameMode, VersusGameMode, or TeamVersusGameMode. Or, if you're just adding something very simple to an existing gamemode, you can also inherit from Campaign, Survival, Deathmatch, etc.

Basic plain gamemode

The most basic plain gamemode you can make is this:

[GameMode]
class BasicGamemode : BaseGameMode
{
	BasicGamemode(Scene@ scene)
	{
		super(scene);
	}
}

The above script will simply spawn a player in the map without any weapons and no HUD. If we wanted to give the player a few weapons for example, we'd add the following override provided by BaseGameMode:

void SpawnPlayer(int i, vec2 pos = vec2(), int unitId = 0, uint team = 0) override
{
	BaseGameMode::SpawnPlayer(i, pos, unitId, team);

	// Give weapons
	g_players[i].AddWeapon("weapons/smg.sval");
	g_players[i].AddWeapon("weapons/railgun.sval");

	// Give ammo
	g_players[i].GiveAmmo("weapons/ammo/bolts.sval", 30);
	g_players[i].GiveAmmo("weapons/ammo/bullets.sval", 500);
}

At this point you probably also want to add a HUD so you know what's happening. To do this, we have to do a few things:

  • Instantiate a HUD object using the GUI builder
  • Return the object in the GetHUD() method
  • Update the HUD in the UpdateWidgets(...) method
  • Render the HUD in the RenderWidgets(...) method

This looks roughly like this:

HUD@ m_hud;

BasicGamemode(Scene@ scene)
{
	super(scene);
	@m_hud = HUD(m_guiBuilder, null);
}

HUD@ GetHUD() override { return m_hud; }

void UpdateWidgets(int ms, GameInput& gameInput, MenuInput& menuInput) override
{
	m_hud.Update(ms);
	BaseGameMode::UpdateWidgets(ms, gameInput, menuInput);
}

void RenderWidgets(PlayerRecord@ player, int idt, SpriteBatch& sb) override
{
	m_hud.Draw(sb, idt);
	BaseGameMode::RenderWidgets(player, idt, sb);
}

Functions

Further, you can implement any function you'd like from the below list in your class, and they will be called as events.

void Start(uint8, SValue@, StartMode)
SValue@ Save()

void AddPlayer(uint8)
void RemovePlayer(uint8, bool)

void UpdateFrame(int, GameInput&, MenuInput&)
void UpdatePausedFrame(int, GameInput&, MenuInput&)
void PreRenderFrame(int)
void RenderFrame(int, SpriteBatch&)

void ResizeWindow(int, int, float)
void Paused(bool)

vec2 GetCameraPos(int)
vec4 GetVignette(int)

// Advanced methods
void LobbyCreated(bool loadingSave)
void LobbyInviteAccepted()
void LobbyEntered()

void LobbyDataUpdate()
void LobbyMemberDataUpdate(uint8)
void LobbyList(array<uint64>@)

void SetMenuState(MenuState)
bool MenuBack()
void ShowMessage(MenuMessage)

void OnBindingInput(ControllerType, int)
void ChatMessage(uint8, string)