Advertisement
Guest User

Cornelius

a guest
May 22nd, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.31 KB | None | 0 0
  1. local Enemy = require 'nodes/enemy'
  2. local gamestate = require 'vendor/gamestate'
  3. local sound = require 'vendor/TEsound'
  4. local Timer = require 'vendor/timer'
  5. local Fireball = require 'nodes/fire_cornelius_big'
  6. local utils = require 'utils'
  7. local Dialog = require 'dialog'
  8. local anim8 = require 'vendor/anim8'
  9.  
  10. local window = require 'window'
  11. local camera = require 'camera'
  12. local fonts = require 'fonts'
  13. local cheat = require 'cheat'
  14. local Sprite = require 'nodes/sprite'
  15.  
  16. return {
  17.   name = 'cornelius',
  18.   attackDelay = 1,
  19.   height = 192,
  20.   width = 144,
  21.   damage = 30,
  22.   special_damage = {cornelius = 5000},
  23.   --attack_bb = true,
  24.   jumpkill = false,
  25.   knockback = 0,
  26.   player_rebound = 400,
  27.   antigravity = true,
  28.   bb_width = 124,
  29.   bb_height = 182,
  30.   bb_offset = { x = 0, y = -5},
  31.   attack_width = 40,
  32.   velocity = {x = 0, y = 10},
  33.   hp = 100,
  34.   tokens = 100,
  35.   dyingdelay = 2,
  36.   fadeIn = true,
  37.   enterScript ={
  38.         "{{grey}}Welcome{{white}}, you are the first to make it to the {{orange}}Throne of Hawkthorne{{white}}.",
  39.         "Let me take a look at you...",
  40.         "According to your {{olive}}complexion{{white}}, I think you might be...{{purple}}" .. player.character.name .. "{{white}}.",
  41.         "You don't deserve my fortune!",
  42.       },
  43.   deathScript ={
  44.         "{{grey}}*heavy breathing*{{white}} I suppose you're wondering,{{purple}} player{{white}}. ",
  45.         "Why record myself breathing weird and letting you destroy me?",
  46.             "Because I am a man of {{red}}Honor!{{white}}",
  47.             "So you've earned the pleasure of my death!",
  48.   },
  49.  
  50.   tokenTypes = { -- p is probability ceiling and this list should be sorted by it, with the last being 1
  51.     { item = 'coin', v = 1, p = 0.9 },
  52.     { item = 'health', v = 1, p = 1 }
  53.   },
  54.   animations = {
  55.      default = {
  56.       right = {'loop', {'1,1'}, 0.25},
  57.       left = {'loop', {'1,1'}, 0.25}
  58.     },
  59.     talking = {
  60.       right = {'loop', {'1-3,1','2,1'}, 0.15},
  61.       left = {'loop', {'1-3,1','2,1'}, 0.15}
  62.     },
  63.     attack = {
  64.       right = {'loop', {'1-3,2','2,2'}, 0.1},
  65.       left = {'loop', {'1-3,2','2,2'}, 0.1}
  66.     },
  67.     hurt = {
  68.       right = {'loop', {'1-3,2','2,2'}, 0.1},
  69.       left = {'loop', {'1-3,2','2,2'}, 0.1}
  70.     },
  71.     dying = {
  72.       right = {'loop', {'1-3,1','2,1'}, 0.15},
  73.       left = {'loop', {'1-3,1','2,1'}, 0.15}
  74.     },
  75.     enter = {
  76.       right = {'once', {'1,1'}, 0.2},
  77.       left = {'once', {'1,1'}, 0.2}
  78.     },
  79.     teleport = {
  80.       right = {'loop', {'1-3,3','2,3'}, 0.1},
  81.       left = {'loop', {'1-3,3','2,3'}, 0.1}
  82.     },
  83.   },
  84.  
  85.   enter = function( enemy )
  86.     enemy.direction = math.random(2) == 1 and 'left' or 'right'
  87.     enemy.directionY = math.random(2) == 1 and 'up' or 'down'
  88.     enemy.state = 'attack'
  89.     enemy.maxy = enemy.position.y + 10
  90.     enemy.miny = enemy.position.y - 10
  91.     enemy.hatched = false
  92.     enemy.last_teleport = 0
  93.     enemy.last_attack = 0
  94.     enemy.last_fireball = 0
  95.     enemy.swoop_speed = 150
  96.     enemy.fly_speed = 75
  97.     enemy.swoop_distance = 150
  98.     enemy.swoop_ratio = 0.25
  99.     sound.playMusic("cornelius-attacks")
  100.     --enemy.velocity.x = 100
  101.     cheat:fairfight()
  102.  
  103.     --remove this after testing
  104.     --enemy.rage = true
  105.  
  106.     --sparkles
  107.     enemy.props.sparkleRotated( enemy, 45, 0 )
  108.     enemy.props.sparkleRotated( enemy, 50, 60 )
  109.     enemy.props.sparkleRotated( enemy, 110, 150 )
  110.     Timer.add(.2, function()
  111.       enemy.props.sparkle( enemy, 0, 100 )
  112.       enemy.props.sparkleRotated( enemy, 120, 100 )
  113.       Timer.add(.2, function()
  114.         enemy.props.sparkleRotated( enemy, 70, 140 )
  115.         enemy.props.sparkle( enemy, 0, 0 )
  116.         Timer.add(.2, function()
  117.           enemy.props.sparkleRotated( enemy, 45, 0 )
  118.           enemy.props.sparkleRotated( enemy, 50, 60 )
  119.           enemy.props.sparkleRotated( enemy, 110, 150 )
  120.           end)
  121.         end)
  122.     end)
  123.  
  124.     --enter dialog
  125.         if enemy.enterScript then
  126.       enemy.state = 'talking'
  127.         Dialog.new(enemy.enterScript, function()
  128.         enemy.hatched = true
  129.         enemy.state = 'attack'
  130.         enemy.rage = true
  131.           end, nil, 'small')
  132.       end
  133.      
  134.   end,
  135.  
  136.   sparkleRotated = function(enemy, offsetX, offestY)
  137.     local node = {
  138.       type = 'sprite',
  139.       name = 'sparkle_rotated',
  140.       x = enemy.position.x+offsetX,
  141.       y = enemy.position.y+offestY,
  142.       width = 45,
  143.       height = 45,
  144.       properties = {sheet = 'images/sprites/castle/cornelius_sparkles_big_rotated.png',
  145.                     speed = .2,
  146.                     animation = '1-4,1',
  147.                     width = 45,
  148.                     height = 45,
  149.                     mode = 'once',
  150.                     foreground = true}
  151.     }
  152.     local sparkleR = Sprite.new( node, enemy.collider )
  153.     local level = enemy.containerLevel
  154.     level:addNode(sparkleR)
  155.   end,
  156.  
  157.   sparkle = function(enemy, offsetX, offestY)
  158.     local node = {
  159.       type = 'sprite',
  160.       name = 'sparkle',
  161.      x = enemy.position.x+offsetX,
  162.       y = enemy.position.y+offestY,
  163.       width = 45,
  164.       height = 45,
  165.       properties = {sheet = 'images/sprites/castle/cornelius_sparkles_big.png',
  166.                     speed = .2,
  167.                     animation = '1-4,1',
  168.                     width = 45,
  169.                     height = 45,
  170.                     mode = 'once',
  171.                     foreground = true}
  172.     }
  173.     local sparkle = Sprite.new( node, enemy.collider )
  174.     local level = enemy.containerLevel
  175.     level:addNode(sparkle)
  176.  
  177.   end,
  178.  
  179.   fireball = function( enemy, player )
  180.     enemy.last_fireball = 0
  181.     enemy.last_attack = 0
  182.     local Fireball = require('nodes/fire_cornelius_big')
  183.     local node = {
  184.           type = 'fire_cornelius_big',
  185.           name = 'fireball',
  186.           x = player.position.x,
  187.           y = enemy.position.y,
  188.           width = 34,
  189.           height = 110,
  190.           properties = {}
  191.         }
  192.         local fireball = Fireball.new( node, enemy.collider )
  193.         local level = enemy.containerLevel
  194.         level:addNode(fireball)
  195.   end,
  196.  
  197.   teleport = function ( enemy, player, dt )
  198.     enemy.state = 'teleport'
  199.     enemy.last_teleport = 0
  200.     enemy.last_attack = 0
  201.     sound.playSfx("teleport")
  202.     Timer.add(.5, function()  
  203.       if enemy.position.x >= player.position.x then
  204.        
  205.         enemy.position.x = player.position.x - (math.abs((enemy.position.x+(enemy.width/2))-player.position.x))
  206.         enemy.state = 'attack'
  207.       elseif enemy.position.x <= player.position.x then
  208.         enemy.position.x = player.position.x - (math.abs((enemy.position.x+(enemy.width/2))-player.position.x))
  209.         enemy.state = 'attack'
  210.       end
  211.     end)  
  212.   end,
  213.  
  214.   -- adjusts values needed to initialize swooping
  215.   targetDive = function ( enemy, player, direction )
  216.     enemy.fly_dir = direction
  217.     enemy.launch_y = enemy.position.y
  218.     local p_x = player.position.x - player.character.bbox.x
  219.     local p_y = player.position.y - player.character.bbox.y
  220.     enemy.swoop_distance = math.abs(p_y - enemy.position.y)
  221.     enemy.swoop_ratio = math.abs(p_x - enemy.position.x) / enemy.swoop_distance
  222.     -- experimentally determined max and min swoop_ratio values
  223.     enemy.swoop_ratio = math.min(1.4, math.max(0.7, enemy.swoop_ratio))
  224.   end,
  225.  
  226.   startDive = function ( enemy )
  227.   enemy.last_attack = 0
  228.   enemy.last_teleport = 0
  229.     enemy.velocity.y = enemy.swoop_speed
  230.   -- swoop ratio used to center bat on target
  231.     enemy.velocity.x = -( enemy.swoop_speed * enemy.swoop_ratio ) * enemy.fly_dir
  232.     Timer.add(.5, function()  
  233.       enemy.velocity.y = -enemy.fly_speed
  234.       enemy.velocity.x = -(enemy.swoop_speed / 1.5) * enemy.fly_dir
  235.       print('undive')
  236.    
  237.     end)
  238.  
  239.   end,
  240.  
  241.   -- Compares vulnerabilities to a weapons special damage and sums up total damage
  242.   calculateDamage = function(self, damage, special_damage)
  243.     if not special_damage then
  244.       if self.state =='teleport' then
  245.         print('double damage')
  246.         damage = 2*damage
  247.         return damage
  248.       else
  249.         print('regular damage')
  250.         return damage
  251.       end
  252.     end
  253.     for _, value in ipairs(self.vulnerabilities) do
  254.       if special_damage[value] ~= nil then
  255.         if enemy.state =='teleport' then
  256.           damage = (damage + special_damage[value])*2
  257.           print('double damage')
  258.         else
  259.           damage = damage + special_damage[value]
  260.           print('regular damage')
  261.         end
  262.       end
  263.     end
  264.  
  265.     return damage
  266.   end,
  267.  
  268.   die = function( enemy )
  269.     sound.playMusic("cornelius-forfeiting")
  270.     Dialog.new(enemy.deathScript, function()
  271.       enemy:die()
  272.       sound.playSfx("cornelius-ending")
  273.       sound.stopMusic()
  274.  
  275.       local NodeClass = require('nodes/key')
  276.       local node = {
  277.         type = 'key',
  278.         name = 'greendale',
  279.         x = enemy.position.x + enemy.width / 2 ,
  280.         y = enemy.position.y + enemy.height+48,
  281.         width = 24,
  282.         height = 24,
  283.         properties = {info = "Congratulations. You have found the {{green_dark}}Greendale{{white}} key. If you want more to explore, you now have access to the {{green_dark}}Greendale{{white}} campus!",
  284.                               'To get there, exit the study room then use the door to the left. Remember to bring the key!',
  285.         },
  286.       }
  287.       local spawnedNode = NodeClass.new(node, enemy.collider)
  288.       local level = gamestate.currentState()
  289.       level:addNode(spawnedNode)
  290.  
  291.       end, nil, 'small')
  292.  
  293.   end,
  294.  
  295.   draw = function( enemy )
  296.     fonts.set( 'small' )
  297.  
  298.     --love.graphics.setStencil( )
  299.  
  300.     local energy = love.graphics.newImage('images/enemies/bossHud/energy.png')
  301.     local bossChevron = love.graphics.newImage('images/enemies/bossHud/bossChevron.png')
  302.     local bossPic = love.graphics.newImage('images/enemies/bossHud/cornelius.png')
  303.  
  304.     energy:setFilter('nearest', 'nearest')
  305.     bossChevron:setFilter('nearest', 'nearest')
  306.     bossPic:setFilter('nearest', 'nearest')
  307.  
  308.  
  309.     x, y = camera.x + window.width - 130 , camera.y + 10
  310.  
  311.   end,
  312.  
  313.   update = function( dt, enemy, player, level )
  314.     if enemy.dead then return end
  315.     local direction = player.position.x > enemy.position.x + 70 and -1 or 1
  316.     local offset = math.random(0,200)
  317.  
  318.     if enemy.state == 'default' and not enemy.hatched then
  319.       --enemy.velocity.y = -25
  320.       --enemy.velocity.x = 100
  321.     elseif enemy.hatched then
  322.       --[[if enemy.position.x > player.position.x then
  323.                     enemy.velocity.x = -enemy.velocity.x
  324.                   elseif enemy.position.x < player.position.x then
  325.                     enemy.velocity.x = -enemy.velocity.x
  326.                   end
  327.                   if enemy.position.y <= enemy.miny then
  328.                     enemy.velocity.y = -enemy.velocity.y
  329.                   elseif enemy.position.y >= enemy.maxy then
  330.                     enemy.velocity.y = -enemy.velocity.y
  331.                   end]]
  332.         enemy.rage = true
  333.         enemy.glow = true
  334.         enemy.lightning = true
  335.         --enemy.props.fire(enemy)
  336.       enemy.last_teleport = enemy.last_teleport + dt
  337.       enemy.last_attack = enemy.last_attack + dt
  338.       enemy.last_fireball = enemy.last_fireball + dt
  339.       enemy.props.targetDive( enemy, player, -direction )
  340.      
  341.       if enemy.last_attack > 2 and enemy.last_teleport > 3 then
  342.         enemy.props.fireball( enemy, player )
  343.         --enemy.props.teleport( enemy, player, dt )
  344.         --enemy.props.startDive ( enemy )
  345.       end
  346.      
  347.     end
  348.  
  349.  
  350.   end
  351. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement