local player = {}
player.x = 0
player.y = 500
player.width = 140
player.height = 160
player.speed = 200
player.speed_jumping = 400
player.speed_walking = 200
player.jump_height = 500
player.state = "idle"
player.direction = "right"
player.alive = true
player.init = function(self, sound_effects, spritesheets, game)
    self.sound_effects = sound_effects
    self.spritesheets = spritesheets
    self.game = game
    self.x = self.game.width / 2 + 8
    self.y = self.game.height + 8
    player.animation = spritesheets["player_idle"]
end

player.walk_right = function(self, dt)
    if self.x < self.game:getcurlevel().width - self.width - self.game.width - 8 and self.alive then
        self.x = self.x + self.speed * dt
        self.state = "walk_right"
        self.direction = "right"
        self.animation = self.spritesheets["player_walk_right"]
    end
end
player.walk_left = function(self, dt)
    if self.x > self.game.width / 2 + 8 and self.alive then
        self.x = self.x - self.speed * dt
        self.state = "walk_left"
        self.direction = "left"
        self.animation = self.spritesheets["player_walk_left"]
    end
end
player.jump = function(self, dt)
    if self.y > self.game.height / 2 + 8 and self.alive then
        self.y = self.y - self.jump_height * dt
        self.state = "jump"
        self.animation = self.spritesheets["player_jump"]
        self.sound_effects["jump"]:play()
    end
end
player.down = function(self, dt)
    if self.y < self.game:getcurlevel().height - self.height - self.game.height / 2 - 8 and self.alive then
        self.y = self.y + self.jump_height * dt
        self.state = "jump"
        self.animation = self.spritesheets["player_jump"]
        self.sound_effects["jump"]:play()
    end
end
player.die = function(self, dt)
    if self.alive then
        self.alive = false
        self.state = "die"
        self.animation = self.spritesheets["player_die"]
        self.sound_effects["die"]:play()
        self.spritesheets["player_die"]:setFrame(1)
    end
end
player.revive = function(self, dt)
    if not self.alive then
        self.alive = true
        self.state = "idle"
        self.animation = self.spritesheets["player_default"]
        self.sound_effects["revive"]:play()
        self.spritesheets["player_die"]:setFrame(1)

    end
end
player.idle = function(self, dt)
    if self.alive then
        self.state = "idle"
        self.animation = self.spritesheets["player_idle"]
    end
end
player.default = function(self, dt)
    if self.alive then
        self.state = "default"
        self.animation = self.spritesheets["player_default"]
    end
end
return player