Difference between revisions of "Creating a GameMode"
From Serious Sam's Bogus Detour
Line 1: | Line 1: | ||
+ | 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 <code>BaseGameMode</code>, <code>VersusGameMode</code>, or <code>TeamVersusGameMode</code>. Or, if you're just adding something very simple to an existing gamemode, you can also inherit from <code>Campaign</code>, <code>Survival</code>, <code>Deathmatch</code>, etc. | ||
+ | |||
+ | The most basic plain gamemode you can make is this: | ||
+ | |||
+ | <pre> | ||
+ | [GameMode] | ||
+ | class BasicGamemode : BaseGameMode | ||
+ | { | ||
+ | BasicGamemode(Scene@ scene) | ||
+ | { | ||
+ | super(scene); | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | 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 <code>BaseGameMode</code>: | ||
+ | |||
+ | <pre> | ||
+ | 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); | ||
+ | } | ||
+ | </pre> | ||
+ | |||
===Standard functions=== | ===Standard functions=== | ||
Revision as of 15:20, 24 June 2017
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.
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); }
Standard functions
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)
Menu functions
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)