<commit_before>class = require 'class'

Character = class()

-- Constants
Character.max_vy = 3000
Character.max_vx = 1000
Character.wall_fall_g_friction = 0.95 -- Relative to char.g
Character.max_grab_fall_speed = 1000
Character.x_friction_threshold = 10
Character.x_friction = 0.99
Character.walk_acceleration = 30
Character.jump_speed = 330
Character.wall_jump_xspeed = 800
Character.wall_jump_yspeed = 400
Character.g = 1100

-- Graphics setup
Character.quad = love.graphics.newQuad(3, 2, 26, 42, 32, 48)

function Character:init()
	self.textures = {}

	-- Variables
	self.magics = { 'fireball' }
	self.crystals = 0
	self.maximum_lives = 3
	self.current_lives = 2
	self.is_vulnerable = true

	self.x = 32*4
	self.y = 170
	self.width = 24
	self.height = 42
	self.px = x
	self.py = y
	self.vx = 0
	self.vy = 0
	self.jump_key_active_last_frame = false
	self.flipped = false
	self.state = 'normal'
	self.active_magic = self.magics[1]
	self.can_cast = true
	self.can_move = true
	self.move_cooldown_state = 0

	-- Textures
	self.textures.cast_front = love.graphics.newImage('common/char-cast-front.png')
	self.textures.cast_general = love.graphics.newImage('common/char-cast-general.png')
	self.textures.dead = love.graphics.newImage('common/char-dead.png')
	self.textures.normal = love.graphics.newImage('common/char-normal.png')
	self.textures.grab_wall = love.graphics.newImage('common/char-grab-wall.png')
end

function Character:draw()
	local xscale = self.flipped and -1 or 1
	local ox = self.flipped and self.width or 0

	love.graphics.draw(self.textures[self.state], Character.quad, self.x, self.y, 0, xscale, 1, ox, 0)
end

function Character:update(map, dt)
	self.px = self.x
	self.py = self.y

	self.x = self.x + self.vx * dt
	self.y = self.y + self.vy * dt

	if self.vx > self.x_friction_threshold or self.vx < -self.x_friction_threshold then
		self.vx = self.vx * math.pow(1 - self.x_friction, dt)
	else
		self.vx = 0
	end<commit_msg>Visual effect for (now temporary) invulnerability<commit_after>class = require 'class'

Character = class()

-- Constants
Character.max_vy = 3000
Character.max_vx = 1000
Character.wall_fall_g_friction = 0.95 -- Relative to char.g
Character.max_grab_fall_speed = 1000
Character.x_friction_threshold = 10
Character.x_friction = 0.99
Character.walk_acceleration = 30
Character.jump_speed = 330
Character.wall_jump_xspeed = 800
Character.wall_jump_yspeed = 400
Character.g = 1100
Character.default_invulnerability_time = 3

-- Graphics setup
Character.quad = love.graphics.newQuad(3, 2, 26, 42, 32, 48)

function Character:init()
	self.textures = {}

	-- Variables
	self.magics = { 'fireball' }
	self.crystals = 0
	self.maximum_lives = 3
	self.current_lives = 3
	self.is_vulnerable = true

	self.x = 32*4
	self.y = 170
	self.width = 24
	self.height = 42
	self.px = x
	self.py = y
	self.vx = 0
	self.vy = 0
	self.jump_key_active_last_frame = false
	self.flipped = false
	self.state = 'normal'
	self.active_magic = self.magics[1]
	self.can_cast = true
	self.can_move = true
	self.move_cooldown_state = 0

	-- Textures
	self.textures.cast_front = love.graphics.newImage('common/char-cast-front.png')
	self.textures.cast_general = love.graphics.newImage('common/char-cast-general.png')
	self.textures.dead = love.graphics.newImage('common/char-dead.png')
	self.textures.normal = love.graphics.newImage('common/char-normal.png')
	self.textures.grab_wall = love.graphics.newImage('common/char-grab-wall.png')
end

function Character:draw()
	local xscale = self.flipped and -1 or 1
	local ox = self.flipped and self.width or 0

	if not self.is_vulnerable then
		love.graphics.setColor(255, 255, 255, 128)
	end

	love.graphics.draw(self.textures[self.state], Character.quad, self.x, self.y, 0, xscale, 1, ox, 0)

	love.graphics.setColor(255, 255, 255)
end

function Character:update(map, dt)
	if not self.is_vulnerable then
		if self.invulnerability_time == nil then
			self.invulnerability_time = self.default_invulnerability_time
		elseif self.invulnerability_time < dt then
			self.invulnerability_time = nil
			self.is_vulnerable = true
		else
			self.invulnerability_time = self.invulnerability_time - dt
		end
	end

	self.px = self.x
	self.py = self.y

	self.x = self.x + self.vx * dt
	self.y = self.y + self.vy * dt

	if self.vx > self.x_friction_threshold or self.vx < -self.x_friction_threshold then
		self.vx = self.vx * math.pow(1 - self.x_friction, dt)
	else
		self.vx = 0
	end
{'fraction_non_alphanumeric': 0.1182722749886929, 'fraction_numerical': 0.036635006784260515, 'mean_word_length': 4.049086757990867, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1822858', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1650, 'n_words': 348}