local app = require 'app'

local Gamestate = require 'vendor/gamestate'
local window = require 'window'
local fonts = require 'fonts'
local camera = require 'camera'
local sound = require 'vendor/TEsound'
local state = Gamestate.new()

function state:init()
end

function state:enter(previous)
  fonts.set( 'big' )
  love.graphics.setBackgroundColor(0, 0, 0)
  sound.playMusic( "credits" )
  self.ty = 0
  camera:setPosition(0, self.ty)
  self.previous = previous
end

function state:leave()
  fonts.reset()
  camera:setPosition(0, 0)
end

function state:update(dt)
  self.ty = self.ty + 50 * dt
  camera:setPosition(0, self.ty)
  if self.ty > ( #self.credits * 25 ) + 500 then
    Gamestate.switch(self.previous)
  end
end

function state:keypressed( button )
  if button == 'UP' then
    self.ty = math.max( self.ty - 100, 300 )
  elseif button == 'DOWN' then
    self.ty = math.min( self.ty + 100, ( #self.credits * 25 ) + 30 )
  else
    Gamestate.switch(self.previous)
  end
end

state.credits = {
  app.i18n('credits'), '',
  '6sutters',
  '8bitgentleman',
  'a8252359',
  'aaronpetykowski',
  'academania',
  'acedia',
  'acharmee',
  'add_attack',
  'afiveseven',
  'afuturepresident',
  'ajay182',
  'akobrandon',
  'alfonz42',
  'alkhava',
  'alpenghandi',
  'andcat7',
  'andyantsypants',
  'anthonycoolcoolcoolpants',
  'anton9109',
  'aprgl',
  'archerman1988',
  'arrianj',
  'arthurpdent',
  'arussoh',
  'asdf',
  'ashadenoir',
  'atbvids',
  'austinofdoom',
  'automatic_taglines',
  'avatarkc',
  'bagofswagg',
  'bananasmonkey',
  'barry.se',
  'beebes',
  'beforemonsters',
  'ben3555',
  'benfranklinchang',
  'benlew',
  'bigchangtheory',
  'bigpet',
  'bluecalx2',
  'bobkanob',
  'boobatron4000',
  'bucketh3ad',
  'buckybrewer',
  'cabbo',
  'calebjohn',
  'calledieu',
  'cammo_1234',
  'campadrenalin',
  'can\'t remember',
  'chanchan88',
  'charlottemcewan',
  'charmee',
  'childish_gambino3',
  'childishgambino93',
  'chrissawyers',
  'ciocori',
  'ciziu',
  'clairelabear',
  'clairelebear',
  'claywin',
  'clogan1',
  'cmdoptesc',
  'communityfan1107',
  'condoreo',
  'coolcoolcoolabed',
  'coolman1081',
  'coray8',
  'coreyander',
  'covertpz',
  'cptbooyah',
  'creedogv',
  'creekee',
  'curtis81',
  'cyberpie118',
  'cynical_redditor',
  'dakkjaniels',
  'dancingshadow',
  'daniwa',
  'dano1163',
  'dard12',
  'daspectre',
  'davidgumberg',
  'de3ertf0x',
  'deadpoolismyhomeboy',
  'deckhipstername',
  'delicioussoma',
  'derferman',
  'derynator',
  'didory123',
  'diegothegnome',
  'dont do',
  'dontgochinatownme',
  'dr. awesome',
  'duncan de heusden',
  'durrel',
  'dyan654',
  'easilyremember',
  'echiro-oda-fan',
  'edisonout',
  'edsterman',
  'eighthmaster',
  'elduderino103',
  'eleetpancake',
  'elfaisa',
  'enshinohone',
  'erlendbv',
  'eron69',
  'errol333',
  'ethiophia1',
  'everydaymuffin',
  'evil_abed',
  'eviltimmy',
  'evman50',
  'evsboy123',
  'ezeled42',
  'fanjeta123',
  'fannyfeeny',
  'fapficionado',
  'fardy',
  'fawltywiring',
  'feldbergi14',
  'fieldafar',
  'filmsauce',
  'funkygorilla93',
  'gameboy09',
  'gameoftardises',
  'gingrbeard',
  'gizmo9002',
  'glasenator',
  'graf_rotz',
  'greetingsadm',
  'guyinhat',
  'gvx',
  'gyaruson',
  'habbie',
  'hbjudo17',
  'heikon',
  'hisfavouriteflavour',
  'holyhandgnade13',
  'hottaimale',
  'icanhas',
  'idontusereddit',
  'igotaxmastime4me',
  'ihumanable',
  'inspector-space-time',
  'ironsyndicate',
  'jackim',
  'jaketheda',
  'james92498',
  'jamesrustles1994',
  'janaya',
  'janaya1997',
  'jcoleondabeat',
  'jedi_idiot',
  'jewporn',
  'jgyori29',
  'jhoff',
  'jiggpig',
  'jjangu',
  'jjfresh814',
  'jollygoodshowoldbean',
  'jorbob',
  'josh1238',
  'joshcorr',
  'jpole1',
  'jrbossack',
  'jrcjer',
  'jscuur',
  'jvvb126',
  'kanuck94',
  'kastian',
  'kaworus_lover',
  'kazook',
  'kcig',
  'keviouk',
  'kevwasam',
  'kickpuncher08',
  'kidcudiwins',
  'kiharder',
  'kilakev',
  'kkris',
  'klosec12',
  'konyismydad',
  'lafncow',
  'lamboman10',
  'lasternom',
  'lavenenosa',
  'lc514',
  'letharg',
  'liberodark',
  'lifedreamcreate',
  'liwaldo',
  'lmol99',
  'logsiscute',
  'loubitek',
  'lvl5lazorlotus',
  'lyhome',
  'm_a_d',
  'maathewdavis',
  'majestic_moose',
  'malarchymike',
  'marbly',
  'mario3d',
  'masonnixon',
  'mateusrodcosta',
  'matthewbauer',
  'matthewdelacruz15',
  'max100101',
  'maxerj',
  'mcclellan',
  'mckriet',
  'megatruck',
  'metaridleyx',
  'mexicanace',
  'midnightbarber',
  'mikedem',
  'mikevin',
  'miltage',
  'mister_spider',
  'mminson',
  'mtwstudios',
  'muplah',
  'muugin',
  'myers78',
  'mystro256',
  'nachojarred',
  'nbieter',
  'necral',
  'necromanteion',
  'nerdsavvy',
  'niamu',
  'nicko21',
  'niksn',
  'niles_smiles',
  'nimbusbp1729',
  'nimnams',
  'nonisredael',
  'notablyconventional',
  'notfreshprince',
  'notryanclark',
  'nyan_swanson',
  'octocycle2',
  'ohsin',
  'omgimcobe',
  'operia',
  'ormagoden',
  'outlandishflamingo',
  'paintyfilms',
  'pankobro',
  'paperplatemasks',
  'paragon19',
  'period blood',
  'petter_w',
  'philoctitties',
  'piratejesus',
  'pmaynard',
  'prene7',
  'profbauer',
  'professorianduncan',
  'protuhj',
  'rahmeeroh',
  'rainfly_x',
  'ramblinfirefox',
  'reddfawks',
  'redecho',
  'renako',
  'retromation',
  'ronjon13',
  'roundy210',
  'rydershea',
  'ryneweir',
  'safetytorch',
  'sallybranch',
  'sandytreee',
  'saracenar',
  'seanbroney',
  'sherlockholme',
  'shinzura',
  'shnook21',
  'sillyboots',
  'simmonsisfinished',
  'simsoy',
  'sirdregan',
  'skipants',
  'skovsgaard',
  'slamindingo',
  'smilingkevin',
  'smoorejunk',
  'snokone',
  'sowhy',
  'spartyfan',
  'spla08',
  'spritefan',
  'sprneon',
  'spuddeh',
  'stevensmiley',
  'streetsahead',
  'suspicious_37',
  'systemsoverload',
  'tenshinohone',
  'tgnsd',
  'the gov\'nor',
  'theadam',
  'thedanefromspain',
  'thegreenhat',
  'thejordyd',
  'thekurtin',
  'thewill2live',
  'thisisthefoxe',
  'thomasmb',
  'tigeris',
  'tjvezina',
  'tlivingston15',
  'tonyator',
  'townhouseindustries',
  'trevorstarick',
  'tristian',
  'tristianshaut',
  'tyhannasaurus',
  'uiradev',
  'ultraelite',
  'unameriquinn',
  'username1979',
  'vilhelmsmurphy',
  'vintagefuture',
  'viper61989',
  'vontd',
  'vrachno',
  'wandersfar',
  'wilburwright',
  'wubbledaddy',
  'wyken',
  'xequalsalex',
  'xiaorobear',
  'yigabar',
  'zaxerone',
  'zchmhssn89',
  'zhai',
  'znuese',
  }

function state:draw()
  local shift = math.floor(self.ty/25)
  for i = shift - 14, shift + 1 do
    local name = self.credits[i]
    if name then
      love.graphics.printf(name, 0, window.height + 25 * i, window.width, 'center')
    end
  end
end

return state
