Adjusting radius size in HardonCollider

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
mizza
Prole
Posts: 2
Joined: Wed Jan 29, 2020 9:44 am

Adjusting radius size in HardonCollider

Post by mizza »

Hello people,

Currently 3 days into experimenting with Lua and Love2d, finding it splendid; I have found myself with a little bit of a problem. I am trying to detect collision between a 'playerCircle' and a 'enemyCircle'. Upon collision the enemy will disappear and the 'playerCircle' will grow in radius. I stumbled upon another forum topic about collision and seen that most people would prefer to use the library HC and decided to implement it into my current project. From my understanding HC gives you the tools to easily create hit-boxes for objects such as sprites, circles etc. I have not implemented player graphics and quite frankly will be sticking to utilising Loves draw functions for my player and enemy characters. My question is does anyone have any experience in changing the radius variable of the HC.circle() function on the go. I am finding myself encountering issues whenever I try to manipulate this. This may be due to my lucklustre understanding of Lua or plain ignorance. I have attached my project code and would appreciate any assistance I could get.

Code: Select all

HC = require 'hardoncollider'

function love.load()
    love.window.setMode(400, 400, {resizable=false, vsync=false, minwidth=0, minheight=0})

    --Collision world ?
    collider = HC.new(150)

    --Main Player variables declarations
    Player = HC.circle(200,200,radius)
    Player:moveTo(200, 200)
    radius = 3

    --Enemy variables declarations
    Enemy = HC.circle(200,300, 2)
    Enemy:moveTo(200, 300)
end

function love.update(dt)

  --Keystrokes for player movement
  if love.keyboard.isDown('d') then
    Player:move(50 * dt, 0)
  elseif love.keyboard.isDown('a') then
    Player:move(-50 * dt, 0)
  end

  if love.keyboard.isDown('w') then
    Player:move(0, -50 * dt)
  elseif love.keyboard.isDown('s') then
    Player:move(0, 50 * dt)
  end

  --Check for collisions
  for shape, delta in pairs(HC.collisions(Enemy)) do
    Enemy:moveTo(5000, 5000)
  end

end

function love.draw()
    love.graphics.setColor(1, 1, 1)

    --HC documentation reccomends only using draw functions for debug purposes
    --will need to implement love2d draw func at later date.
    --Draw Main Player
    Player:draw('fill')

    --Draw Enemy
    Enemy:draw('fill')
end
Many thanks.
mizza
Prole
Posts: 2
Joined: Wed Jan 29, 2020 9:44 am

Re: Adjusting radius size in HardonCollider

Post by mizza »

Update.

Managed to resolve this issue by creating my own function within HC's shapes.lua

Code: Select all

function CircleShape:radiusIncrease(r)
	self._radius = self._radius + r
end
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 7 guests