1-- most simple ruleset: for each mistake, the opponent gets a point 2-- includes comments for documentation purposes 3 4 5__AUTHOR__ = "Blobby Volley 2 Developers" 6__TITLE__ = "BV2 Default Rules" 7 8-- rules.lua doc 9-- function IsWinning 10-- IMPLEMENTED BY rules.lua 11-- called when it is determined whether a player has won 12-- params: lscore: score of left player 13-- rscore: score of right player 14-- return: whether a player has won 15function IsWinning(lscore, rscore) 16 -- constant SCORE_TO_WIN: number of points for a player to win 17 if lscore >= SCORE_TO_WIN and lscore >= rscore + 2 then 18 return true 19 end 20 if rscore >= SCORE_TO_WIN and rscore >= lscore + 2 then 21 return true 22 end 23 return false 24end 25 26-- function OnBallHitsPlayer 27-- IMPLEMENTEDBY rules.lua 28-- called when a valid collision between a player and the ball happens. 29-- params: player - the player that hit the ball 30-- return: none 31function OnBallHitsPlayer(player) 32 -- function touches 33 -- PREDEFINED 34 -- param: player - player whos touches you want to get 35 -- return: how many touches did player 36 37 -- function opponent 38 -- PREDEFINED 39 -- param: player - player of whom you want to get the opponent 40 -- return: opponent of the player, so, for LEFT_PLAYER, RIGHT_PLAYER is returned and vice-versa 41 42 -- function mistake 43 -- PREDEFINED 44 -- params: mistakeSide - player who made a mistake 45 -- serveSide - player who should make a serve 46 -- amount - how many points opponent of mistakeSide gets 47 -- return: none 48 49 if touches(player) > 3 then 50 mistake(player, opponent(player), 1) 51 end 52end 53 54-- function OnBallHitsWall 55-- IMPLEMENTEDBY rules.lua 56-- called when a valid collision between the ball and a wall happens. 57-- params: player - the player on whos side the ball hit a wall 58-- return: none 59function OnBallHitsWall(player) 60end 61 62-- function OnBallHitsNet 63-- IMPLEMENTEDBY rules.lua 64-- called when a valid collision between the ball and a net happens. 65-- params: player - the player on whos side the ball hits a net (NO_PLAYER for net top) 66-- return: none 67function OnBallHitsNet(player) 68end 69 70-- function OnBallHitsGround 71-- IMPLEMENTEDBY rules.lua 72-- called when the ball hits the ground. 73-- params: player - the player on whos side the ball hits the ground 74-- return: none 75function OnBallHitsGround(player) 76 mistake(player, opponent(player), 1) 77end 78 79-- function OnGame 80-- IMPLEMENTEDBY rules.lua 81-- called for every moment in the game. 82-- params: none 83-- return: none 84function OnGame() 85end 86 87-- function HandleInput 88-- IMPLEMENTEDBY rules.lua 89-- called to control player movement 90-- params: player - the player to check 91-- left, right, up - source user input 92-- return: new input values 93function HandleInput(player, left, right, up) 94 return left, right, up 95end 96 97-- uncomment this to change number of points for a player to win 98-- SCORE_TO_WIN = 15 99