SIRIN404

Clicker

Aug 10th, 2025 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. local love = require "love"
  2. local constants = require "constants"
  3.  
  4. local Button = {}
  5. Button.__index = Button
  6. function Button.new(shape, x, y, width, height, func, text)
  7. local self = setmetatable({}, Button)
  8. self.shape = shape
  9. self.x = x
  10. self.y = y
  11. self.width = width
  12. self.height = height
  13. self.func = func or function () end
  14. self.text = text or ''
  15. if self.shape == "circle" then
  16. self.x_min = self.x - self.width
  17. self.x_max = self.x + self.width
  18. self.y_min = self.y - self.width
  19. self.y_max = self.y + self.width
  20. else
  21. self.x_min = self.x
  22. self.x_max = self.x + self.width
  23. self.y_min = self.y
  24. self.y_max = self.y + self.height
  25. end
  26. return self
  27. end
  28. function Button:clicked(mouse_x, mouse_y)
  29. if mouse_x > self.x_min and
  30. mouse_x < self.x_max and
  31. mouse_y > self.y_min and
  32. mouse_y < self.y_max then
  33. self.func()
  34. end
  35. end
  36. function Button:draw()
  37. if self.func_con then
  38. love.graphics.setColor(255,255,255)
  39. else
  40. love.graphics.setColor(200,200,200)
  41. end
  42. if self.shape == "circle" then
  43. love.graphics.circle ("fill", self.x, self.y, self.height)
  44. else
  45. love.graphics.rectangle ("fill", self.x, self.y, self.width, self.height)
  46. end
  47. love.graphics.setColor(0,0,0)
  48. if self.shape == "circle" then
  49. love.graphics.printf (self.text, self.x_min, self.y-7.5, self.width*2, "center")
  50. else
  51. love.graphics.printf (self.text, self.x_min, (self.y_max + self.y_min)/2-7.5, self.width, "center")
  52. end
  53. end
  54.  
  55. local Resource = {}
  56. Resource.__index = Resource
  57. function Resource.new(startvalue, isshown)
  58. self.startvalue = startvalue
  59. self.isshown = isshown
  60. self.currvalue = self.startvalue
  61. return self
  62. end
  63. function Resource:add(value)
  64. self.currvalue = self.currvalue + value
  65. end
  66.  
  67. local Soul = {}
  68. Soul.__index = Soul
  69. function Soul.new(Name, Price, PRate, PValue)
  70. local self = setmetatable({}, Soul)
  71. self.name = Name
  72. self.ascensionlvl = 1
  73. self.lvl = 1
  74. self.price = price
  75. self.pRate = PRate
  76. self.PValue = PValue
  77. return self
  78. end
  79. function Soul:buy()
  80. if self.lvl + 1 <= 100 then
  81. self.lvl = self.lvl + 1
  82. self.price = self.price * (1.01)
  83. end
  84. end
  85. --ignore these, they have been replaced with the appropriate values for simplicity's sake
  86. function Soul:getLvlCap()
  87. return getLvlCap[self.ascensionlvl]
  88. end
  89. function Soul:getPriceUp()
  90. return getPriceUp[self.lvl]
  91. end
  92.  
  93.  
  94.  
  95. local x_size, y_size = love.graphics.getDimensions()
  96. local x_mid = x_size/2
  97. local y_mid = y_size/2
  98. local coins = 0
  99. function addcoins()
  100. coins = coins + 1
  101. end
  102.  
  103. function love.load()
  104. bigButton = Button.new("circle", x_mid, y_mid, 100, 100, addcoins, "button :D")
  105. wheat = Soul.new(wheat, 100, 100, 100)
  106. wheat.button = Button.new("rectangle", 0, 15, 100, 30, wheat:buy, 100)
  107. end
  108.  
  109. function love.update()
  110. end
  111.  
  112. function love.mousepressed(x, y)
  113. bigButton:clicked(x, y)
  114. wheat.button:clicked(x,y)
  115. end
  116.  
  117. function love.draw()
  118. bigButton:draw()
  119. wheat.button:draw()
  120. love.graphics.setColor(255,255,255)
  121. love.graphics.print(coins,0,0)
  122. love.graphics.print(wheat.lvl,0,45)
  123. end
Advertisement
Add Comment
Please, Sign In to add comment