Issue using Hardon Collider

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
destinyschilde
Prole
Posts: 7
Joined: Mon Jan 16, 2017 11:48 pm

Issue using Hardon Collider

Post by destinyschilde »

I am having this silly issue with my collisions. I chose this library HC to detect collisions, but there's not a lot of actual examples of it in use anywhere that i can find in order to reverse engineer. Has anyone used this library?
this is what my code looks like:

Code: Select all

require "AnimatedSprite"
HC = require 'hardoncollider'
Polygon = require 'hardoncollider.polygon' --Including the file
diag = 0
collide = false
x = 400
y = 400

function love.load()

    love.graphics.setDefaultFilter("nearest", "nearest")
    player = GetInstance ("player.lua")
    level = GetInstance ("level.lua")
    subject = GetInstance ("subject.lua")
    beam = GetInstance ("beam.lua")
    emitter = HC.circle(400,300,20)
    poly = HC.polygon(10,35, 40,50, 70,35, 40,20)
    poly:moveTo(x+25,y+80)
end

function love.update(dt)
    love.mouse.setVisible(false)
    UpdateInstance(player, dt)
    UpdateInstance(level, dt)
    UpdateInstance(beam, dt)
    UpdateInstance(subject, dt)  
    poly:moveTo(x+25,y+80)
   
    for shape, delta in pairs(HC.collisions(poly)) do 
        collide=true
    end

    if collide == false then
    if(love.keyboard.areDown('s','a')) then
        y=y+dt+0.83
        x=x-dt-1.7
        player.curr_anim = player.sprite.animations_names[4]
        diag = 1
        frozen=false
    elseif(love.keyboard.areDown('s','d')) then
        y=y+dt+0.83
        x=x+dt+1.7
        player.curr_anim = player.sprite.animations_names[10]
        diag=2
    elseif(love.keyboard.areDown('w','a')) then
        y=y-dt-0.83
        x=x-dt-1.7
        player.curr_anim = player.sprite.animations_names[6]
        diag=3
    elseif(love.keyboard.areDown('w','d')) then
        y=y-dt-0.83
        x=x+dt+1.7
        player.curr_anim = player.sprite.animations_names[8]
        diag=4
    elseif(love.keyboard.isDown('w')) then
        y=y-dt-1.6
        player.curr_anim = player.sprite.animations_names[7]
        diag=0
    elseif(love.keyboard.isDown('a')) then
        x=x-dt-1.6
        player.curr_anim = player.sprite.animations_names[5]
    elseif(love.keyboard.isDown('s')) then
        y=y+dt+1.6
        diag=0
        player.curr_anim = player.sprite.animations_names[3]
    elseif(love.keyboard.isDown('d')) then
        x=x+dt+1.6
        player.curr_anim = player.sprite.animations_names[9]
    end
    end
end

now obviously, when the shapes collide it turns this boolean off breaking my movement code. but i cant seem to figure out any other way to have my stuff stop moving when it collides. This is an amateurish problem to be having, but i'm pretty new to love2d. I'm not using tile-maps or anything like that, i'm just trying to effect collision between these two shapes. What am i missing?
User avatar
D0NM
Party member
Posts: 250
Joined: Mon Feb 08, 2016 10:35 am
Location: Zabuyaki
Contact:

Re: Issue using Hardon Collider

Post by D0NM »

man ))) look at my signature
and dl our open source Zabuyaki.
Recently I migrated from BUMP to HC.

Hope it'll help u with your HC issue.
Our LÖVE Gamedev blog Zabuyaki (an open source retro beat 'em up game). Twitter: @Zabuyaki.
:joker: LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua :joker:
destinyschilde
Prole
Posts: 7
Joined: Mon Jan 16, 2017 11:48 pm

Re: Issue using Hardon Collider

Post by destinyschilde »

im still trying to find the actual collision code in there. :( it seems like my problem is something to do with the fundamental logic behind collisions or maybe even booleans. either way i'm still pretty screwed with this. i even cleaned up my movement code a lot and still no luck. Im only just starting out here.
destinyschilde
Prole
Posts: 7
Joined: Mon Jan 16, 2017 11:48 pm

Re: Issue using Hardon Collider

Post by destinyschilde »

here's my now more legible code that still doesn't work:

Code: Select all

local baton = require 'baton'
love.joystick.loadGamepadMappings('gamecontrollerdb.txt')
HC = require 'hardoncollider'
x = 400
y = 300

local controls = {
  left = {'key:left', 'axis:leftx-', 'button:dpleft'},
  right = {'key:right', 'axis:leftx+', 'button:dpright'},
  up = {'key:up', 'axis:lefty-', 'button:dpup'},
  down = {'key:down', 'axis:lefty+', 'button:dpdown'},
  primary = {'sc:x', 'button:a'},
  secondary = {'sc:z', 'button:x'},
}

input = baton.new(controls, love.joystick.getJoysticks()[1])

function love.load()
    love.graphics.setDefaultFilter("nearest", "nearest")
    player = GetInstance ("player.lua")
    collide = false
    polyy = HC.polygon(10,35, 40,50, 70,35, 40,20)
    poly = HC.polygon(10,35, 40,50, 70,35, 40,20)
    speed= 1.6
end

function love.update(dt)
  input:update()
  UpdateInstance(player, dt)
  poly:moveTo(x+25,y+80)
  x = x + speed * input:get 'right'
  x = x - speed * input:get 'left'
  y = y + speed * input:get 'down'
  y = y - speed * input:get 'up'

    for shape, delta in pairs(HC.collisions(poly)) do
        collide = true
    end

    if collide==true then
        speed = speed*-1
    end


end

function love.draw()

  DrawInstance (player, x, y)
  love.graphics.print(tostring(input:getActiveDevice()))
  polyy:draw('fill')
  poly:draw('fill')
end

Its detecting collision( the shapes are in pairs ) but i dont know how to make it work after...
destinyschilde
Prole
Posts: 7
Joined: Mon Jan 16, 2017 11:48 pm

Re: Issue using Hardon Collider

Post by destinyschilde »

THAnK yOU YOUR CODE SAVED MY LIFE <3
User avatar
D0NM
Party member
Posts: 250
Joined: Mon Feb 08, 2016 10:35 am
Location: Zabuyaki
Contact:

Re: Issue using Hardon Collider

Post by D0NM »

destinyschilde wrote: Sun Apr 16, 2017 5:30 am THAnK yOU YOUR CODE SAVED MY LIFE <3
NP :nyu:
Our LÖVE Gamedev blog Zabuyaki (an open source retro beat 'em up game). Twitter: @Zabuyaki.
:joker: LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua :joker:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 63 guests