Skip to content

Entity: Player

UnbelievableFlavour edited this page Jun 20, 2022 · 3 revisions

Introduction

There are different types of Players to be configured in Cotton. You can change the player type by changing the config.playerType variable in the config.lua. (More info can be found here: Config Variables)

Updating player image

Player images can be updated just as you would do with an entity. You would call the following from the Player script:

self:setImage("images/computer")

This would change the player image to a computer!

If you want an animated sprite, do it like so:

self:setImage("images/floppy", { animated = true, delay = 500, loop = true })

This would change the player image to a moving floppy!

Updating playertype specific settings

Player specific settings are a little different from updating config settings and have it's own function called setProperty. For instance, if you would want to update the transitionMovement variable of the player.

You would call the following from the Player script:

self:setProperty("transitionMovement", true)

Player types

Grid

In Grid mode, you are viewing the player from above, but locked to a grid. It can move freely in all directions but only to locations on the grid. This is also the player style which probably reminds you the most of how things would work in Pulp.

Settings

tileSize

self:setProperty("tileSize", 16)

Controls the size of the tiles in the grid that the player moves in.

transitionMovement

self:setProperty("transitionMovement", false)

Controls if the player moves to a tile instantly OR with transition.

transitionSpeed

self:setProperty("transitionSpeed", 2)

Controls the speed of the transition that a player moves between tiles.

TileSize has to be in table of transitionSpeed. Examples if tileSize = 16:

  • 2=OK
  • 3=NOT OK
  • 4=OK
  • 6=NOT OK
  • 8=OK

allowDiagonalMovement

self:setProperty("allowDiagonalMovement", false)

Controls if the player can move on the diagonal axis.

Topdown

In topdown mode, you are viewing the player from above, but not locked to a grid. It can move freely in all directions.

Settings

playerSpeed

self:setProperty("playerSpeed", 4)

Controls the max speed of the player.

playerAcceleration

self:setProperty("playerAcceleration", 1)

Controls the acceleration speed till max speed is reached.

playerGroundFriction

self:setProperty("playerGroundFriction", 0.8)

Controls the friction (speed decrease) of the player after moving.

Platformer

With Platformer, you are viewing the player from the side. This player type has gravity, AND is not locked to a grid. It can move freely in all directions except up and down. Moving up and down is possible by button and is affected by gravity.

Settings

playerSpeed

self:setProperty("playerSpeed", 5)

Controls the max speed of the player.

playerAcceleration

self:setProperty("playerAcceleration", 1)

Controls the acceleration speed till max speed is reached.

playerGroundFriction

self:setProperty("playerGroundFriction", 0.8)

Controls the friction (speed decrease) of the player after moving on ground.

playerAirFriction

self:setProperty("playerAirFriction", 0.2)

Controls the friction (speed decrease) of the player after moving in the air.

Event more settings for platformer!

jumpGrace = 0.1,
jumpBuffer = 0.1,
jumpLongPress = 0.12,
jumpVelocity = -15,
gravityUp = 80,
gravityDown = 130,
playerMaxGravity = 40