Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.50 KB | None | 0 0
  1. local Player = {
  2.   Character = "unknown",
  3.   Label = "unknown",
  4.   Sprite = {
  5.     Default = {
  6.         delay = 1,
  7.         list = {"Player/Sprite/character.png"}
  8.       },
  9.     OnAttack = {
  10.         delay = 1,
  11.         list = {}
  12.       },
  13.     OnSkill = {
  14.         delay = 1,
  15.         list = {}
  16.       }
  17.   },
  18.   Effect = {
  19.     Strength = 0,
  20.     Healing = 0,
  21.     Dex = 0,
  22.   },
  23.   Shield = 0,
  24.   Deck = DefaultCardList,
  25.   HandCard = {},
  26.   DiscardsPile = {},
  27.   DrawPile = DefaultCardList,
  28.   DrawHandCard = true,
  29.   RemoveCard = {},
  30.   Relic = {},
  31.   MaxCardOnHand = 10,
  32.   Hp = 50,
  33.   HpMax = 50,
  34.   Gold = 0,
  35.   Mana = 3,
  36.   MaxMana =3,
  37.   x = 25,
  38.   y = 450
  39. }
  40. function Player:TakeDamage(count)
  41.     if self.Shield > count then
  42.         self.Shield = self.Shield - count
  43.     else
  44.         count = count - self.Shield
  45.         self.Shield = 0
  46.         self.Hp = self.Hp - count
  47.         if self.Hp < 0 then
  48.            self.Hp = 0
  49.         end
  50.     end
  51. end
  52. function Player:MixedDrawPile()
  53.    local newDrawPile = {}
  54.    local tempCurrentDraw = self.DrawPile
  55.    for i = 1 , #self.DrawPile do
  56.       local random = math.random(1,#tempCurrentDraw)
  57.       table.insert(newDrawPile,tempCurrentDraw[random])
  58.       table.remove(tempCurrentDraw,random)
  59.    end
  60.    self.DrawPile = newDrawPile
  61. end
  62. function Player:ApplyEffect(pStrength,pHealing,pDex,pShield)
  63.     self.Effect.Strength = Effect.Strength + pStrength
  64.     self.Effect.Healing = Effect.Healing + pHealing
  65.     self.Effect.Dex = Effect.Dex + pDex
  66.     self.Effect.Shield = Effect.Shield + pShield
  67. end
  68. function Player:MixedCard()
  69.    local newPile = {}
  70.    local discard = self.DiscardsPile
  71.    local pile = self.DrawPile
  72.    for i = 1 , #self.DiscardsPile do
  73.       local random = math.random(1,#discard)
  74.       table.insert(pile,discard[random])
  75.       table.remove(discard,random)
  76.    end
  77.    self.DrawPile = pile
  78. end
  79. function Player:IsAlive()
  80.     if self.Hp <= 0 then
  81.       return false
  82.     else
  83.       return true
  84.     end
  85. end
  86. function Player:Discard(index)
  87.     if index ~= -1 then
  88.       table.insert(self.DiscardsPile,self.HandCard[index])
  89.       self.HandCard[index].OnDiscard()
  90.       table.remove(self.HandCard,index)
  91.     else
  92.         for k,v in pairs(self.HandCard) do
  93.             table.insert(self.DiscardsPile,v)
  94.         end
  95.         self.HandCard = {}
  96.     end
  97. end
  98. function Player:Exhaust(index)
  99.     if index ~= -1 then
  100.       table.insert(self.RemoveCard,self.HandCard[index])
  101.       table.remove(self.HandCard,index)
  102.     else
  103.         for k,v in pairs(self.HandCard) do
  104.             table.insert(self.RemoveCard,v)
  105.         end
  106.         self.HandCard = {}
  107.     end
  108. end
  109. function Player:DrawCard(count)
  110.    for i = 1 ,tonumber(count) do
  111.         if #self.DrawPile < 1 then
  112.             self:MixedCard()
  113.         end
  114.         if #self.HandCard < self.MaxCardOnHand then
  115.           table.insert(self.HandCard,self.DrawPile[#self.DrawPile])
  116.           table.remove(self.DrawPile,#self.DrawPile)
  117.           self.HandCard[#self.HandCard].OnDraw(Player)
  118.         end
  119.     end
  120. end
  121. function Player:Draw()
  122.   if self.HandCard ~= nil then
  123.       if self.DrawHandCard then
  124.           for i = 1,#self.HandCard do
  125.             self.HandCard[i].x = 250 + (220*i)
  126.             if love.mouse.getX() > self.HandCard[i].x and love.mouse.getX() < self.HandCard[i].x +200 and love.mouse.getY() > self.HandCard[i].y and love.mouse.isDown(1) then
  127.                   self.HandCard[i].y = love.mouse.getY() -100
  128.                   if self.HandCard[i].y > 600 then
  129.                      self.HandCard[i].y = 600
  130.                   end
  131.             end
  132.             love.graphics.rectangle("fill", self.HandCard[i].x, self.HandCard[i].y, 200, 250)
  133.             love.graphics.setColor(0,0,0,1)
  134.             love.graphics.printf(self.HandCard[i].costMana,self.HandCard[i].x, self.HandCard[i].y, 200,"left",0,1.25,1.25,1)
  135.             love.graphics.printf(self.HandCard[i].info,self.HandCard[i].x, self.HandCard[i].y+160, 200,"center")
  136.             love.graphics.setColor(1,1,1,1)
  137.           end
  138.       end
  139.   end
  140.     love.graphics.printf("Mana : ".. self.Mana.." / "..self.MaxMana,25,640,100,"left")
  141.     love.graphics.printf("Hp : "..self.Hp.." / "..self.HpMax,25,660,100,"left")
  142.     love.graphics.printf("Shield : "..self.Shield,25,680,100,"left")
  143.     love.graphics.printf("Strength : "..self.Effect.Strength,25,700,100,"left")
  144.     love.graphics.printf("Dex : "..self.Effect.Dex,25,720,100,"left")
  145.     love.graphics.draw(love.graphics.newImage(self.Sprite.Default.list[1]),self.x,self.y,0,1,1,0,0)
  146. end
  147. return Player
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement