trying to make a click and drag curling rock demo
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: trying to make a click and drag curling rock demo
I can not download files from non https adresses mkaaay And no, I dont trust Google.
You can learn anything, but you cannot learn everything!
Re: trying to make a click and drag curling rock demo
No problem Yell0w since you've helped more than anyone.
Extract the zip and the unfinished version with the entity system is in it's own directory, it also contains .love files so it's much larger than what even the final game will be.
Extract the zip and the unfinished version with the entity system is in it's own directory, it also contains .love files so it's much larger than what even the final game will be.
- Attachments
-
- GYRO19012013.zip
- latest version of the curling game
- (2.19 MiB) Downloaded 214 times
Re: trying to make a click and drag curling rock demo
ATM I'm trying to figure out how to and could use some help w/:
1. Get the entity system working for red and blue rocks which will be an array of ents 0-7
2. Alternate between the two depending on which rock was released last and if that rock has stopped. The Object:GetLinearVelocity function seems to be broken or I can't get it to work.
Future goals include:
-A score counter which I'm guessing would be most efficient to get the square pixels from the button position and keep counting that ent until the opposite colour ent is counted. The number is then added to that colours part of the score board, the score counter function is only called once all the ents have stopped or been killed.
-making the rocks curl
-making sure collisions work properly
-a title screen, sounds, and music (I'll do this one myself)
1. Get the entity system working for red and blue rocks which will be an array of ents 0-7
2. Alternate between the two depending on which rock was released last and if that rock has stopped. The Object:GetLinearVelocity function seems to be broken or I can't get it to work.
Future goals include:
-A score counter which I'm guessing would be most efficient to get the square pixels from the button position and keep counting that ent until the opposite colour ent is counted. The number is then added to that colours part of the score board, the score counter function is only called once all the ents have stopped or been killed.
-making the rocks curl
-making sure collisions work properly
-a title screen, sounds, and music (I'll do this one myself)
Re: trying to make a click and drag curling rock demo
So my entity system is probably FUBAR'd beyond repair but does anybody have an idea of how to do 16 rock entities?
Re: trying to make a click and drag curling rock demo
So I'll have to start over with the entity system, but in the interim I've been trying to get a little test with just two rocks working. Any ideas? Yell0w?
Code: Select all
function love.load()
--initial graphics and physics setup
love.graphics.setMode(1280, 720, false, true, 8) --sets the window dimensions to 720p
love.physics.setMeter(64)
world = love.physics.newWorld(0, 0, 1280, 720, 500, 500, true )
objects = {}
objects.ice = {}
objects.ice.body = love.physics.newBody(world, 0, 0, "dynamic")
objects.ice.shape = love.physics.newRectangleShape(1280, 720)
--objects.ice.fixture = love.physics.newFixture(objects.ice.body, objects.ice.shape)
objects.rrock = {}
objects.rrock.body = love.physics.newBody(world, 64, 310, "dynamic")
objects.rrock.shape = love.physics.newCircleShape(32)
objects.rrock.fixture = love.physics.newFixture(objects.rrock.body, objects.rrock.shape, 1)
objects.rrock.fixture:setRestitution(0)
objects.rrock.body:setMassData(0, 0, 0, 0)
objects.rrock.body:setLinearDamping(0.5)
objects.brock = {}
objects.brock.body = love.physics.newBody(world, 64, 310, "dynamic")
objects.brock.shape = love.physics.newCircleShape(32)
objects.brock.fixture = love.physics.newFixture(objects.brock.body, objects.brock.shape, 1)
objects.brock.fixture:setRestitution(0)
objects.brock.body:setMassData(0, 0, 0, 0)
objects.brock.body:setLinearDamping(0.5)
rrock = love.graphics.newImage("rrock.png")
brock = love.graphics.newImage("brock.png")
ice = love.graphics.newImage("ice.png")
power = love.graphics.newImage("power.png")
mouse = love.mouse
stonepower = 0
love.graphics.setCaption ("Get Your Rocks Off | Version 0.1")
curl = 0 --going to make this a sine or cosine (depending on in or out turn) function
jointr = love.physics.newFrictionJoint( objects.ice.body, objects.rrock.body, 0, 0, 1280, 720, true )
jointb = love.physics.newFrictionJoint( objects.ice.body, objects.brock.body, 0, 0, 1280, 720, true )
forcer = jointr:setMaxForce(1)
forceb = jointb:setMaxForce(1)
end
function love.update(dt)
world:update(dt) --updates every frame (important)
if drag then
objects.rrock.body:setPosition(love.mouse.getX()-32,love.mouse.getY()-64)
end
if love.mouse.isDown("l") then
stonepower = stonepower + (dt*1000) -- increases the variable by 100 for every second the button is held down
end
function love.mousepressed(x,y,button)
if button == "l" then
if drag == false then
MousePositionSaved = { x= love.mouse.getX(), y=love.mouse.getY() }
end
drag = true
end
end
function love.mousereleasedred()
if drag then
drag = false
objects.rrock.body:setLinearVelocity(0, 0)
objects.rrock.body:setAngularVelocity(0)
objects.rrock.body:applyForce((stonepower*30), 0 )
stonepower = 0
end
end
function love.mousereleasedblue()
if drag then
drag = false
objects.brock.body:setLinearVelocity(0, 0)
objects.brock.body:setAngularVelocity(0)
objects.brock.body:applyForce((stonepower*30), 0 )
stonepower = 0
end
end
end
function love.draw()
love.graphics.draw(ice, 0, 0, 0)
love.graphics.draw(brock, objects.brock.body:getX(), objects.brock.body:getY(), objects.brock.shape:getRadius())
love.graphics.draw(rrock, objects.rrock.body:getX(), objects.rrock.body:getY(), objects.rrock.shape:getRadius())
love.graphics.draw(power, 640, 360, stonepower/200, stonepower/2000)
end
Re: trying to make a click and drag curling rock demo
Ill try to hook you up with a way to create more rocks in a simpler way, im at work right now so it will have to wait a bit.
I have some code here tho that might help a bit, basically replace missiles with curlingrocks, and missile (singular) with rock or any other identifier
-- this function adds a missile to the missiles table, you can use this instead of declaring each individual rock.
function create_missile(x, y)
local missile = {}
missile.body = love.physics.newBody(world, x, y, "dynamic")
--missile.body:setMass(10)
missile.shape = love.physics.newCircleShape(7)
missile.visible = true
missile.created = love.timer.getTime()
missile.fixture = love.physics.newFixture(missile.body , missile.shape, 1 )
missile.fixture:setRestitution(0.0)
missile.fixture:setUserData("Cannonball")
missile.body:applyForce(cannonangle*cannonpowermodifier, cannonpowermodifier*cannonpower*-1) -- Snu til negativ
table.insert(missiles, missile)
end
-- Can i haz loop of all items in missiles table plx:
love.graphics.setColor(255, 255, 255)
for key, missile in ipairs(missiles) do
if missiles[key].visible == true then
love.graphics.circle("fill", missiles[key].body:getX(), missiles[key].body:getY(), missiles[key].shape:getRadius())
mytower = love.graphics.draw(gfxCannonball, missiles[key].body:getX()-10, missiles[key].body:getY()-10, 0,0.8)
if missiles[key].created < drawtime-4 then -- Cannonballs can live for 4 seconds (should be on impact)
missiles[key].visible = false
missiles[key].fixture:destroy()
end
end
end
I have some code here tho that might help a bit, basically replace missiles with curlingrocks, and missile (singular) with rock or any other identifier
-- this function adds a missile to the missiles table, you can use this instead of declaring each individual rock.
function create_missile(x, y)
local missile = {}
missile.body = love.physics.newBody(world, x, y, "dynamic")
--missile.body:setMass(10)
missile.shape = love.physics.newCircleShape(7)
missile.visible = true
missile.created = love.timer.getTime()
missile.fixture = love.physics.newFixture(missile.body , missile.shape, 1 )
missile.fixture:setRestitution(0.0)
missile.fixture:setUserData("Cannonball")
missile.body:applyForce(cannonangle*cannonpowermodifier, cannonpowermodifier*cannonpower*-1) -- Snu til negativ
table.insert(missiles, missile)
end
-- Can i haz loop of all items in missiles table plx:
love.graphics.setColor(255, 255, 255)
for key, missile in ipairs(missiles) do
if missiles[key].visible == true then
love.graphics.circle("fill", missiles[key].body:getX(), missiles[key].body:getY(), missiles[key].shape:getRadius())
mytower = love.graphics.draw(gfxCannonball, missiles[key].body:getX()-10, missiles[key].body:getY()-10, 0,0.8)
if missiles[key].created < drawtime-4 then -- Cannonballs can live for 4 seconds (should be on impact)
missiles[key].visible = false
missiles[key].fixture:destroy()
end
end
end
You can learn anything, but you cannot learn everything!
Re: trying to make a click and drag curling rock demo
I can see how having a set of rocks variables, a table, and a timer or other kill mechanism will allow for multiple rocks but the code still needs to alternate between the two types of rocks. Maybe something like:
Code: Select all
if love.mousereleased() == true and objects.rrock.body:getLinearVelocity() > 1 then
objects.rrock = shot
elseif love.mousereleased() == true and objects.brock.body:getLinearVelocity() > 1 then
objects.brock = shot
end
end
if objects.rrock == shot then
rocks = objects.rrock
else rocks = objects.brock
end
function love.mousereleased()
if drag then
drag = false
objects.rocks.body:setLinearVelocity(0, 0)
objects.rocks.body:setAngularVelocity(0)
objects.rocks.body:applyForce((stonepower*30), 0 )
stonepower = 0
end
end
Re: trying to make a click and drag curling rock demo
If you only want the latest rock (or a rock in a sequence from 1 to 16) to be moved you could apply some kind of logic to this, like after a rock has been thrown it is locked for mouse dragging ?
You can learn anything, but you cannot learn everything!
Re: trying to make a click and drag curling rock demo
Yeah preventing it from being dragged is needed but so is a way of detecting whether or not the previous rock is still in motion. The get linear and angular velocity functions seem to be broken in Love 0.8 or maybe I just wasn't using them correctly.
Re: trying to make a click and drag curling rock demo
i think that getLinearVelocity supplies two values, the velocity change for the X axis and the velocity change for the Y axis.
Code: Select all
if love.mousereleased() == true then
x,y = objects.rrock.body:getLinearVelocity() -- define the velocity change for the x and y axis.
if x>1 then
objects.rrock = shot
elseif love.mousereleased() == true and objects.brock.body:getLinearVelocity() > 1 then
objects.brock = shot
end
if y>1 then
same etc.
end
end
You can learn anything, but you cannot learn everything!
Who is online
Users browsing this forum: No registered users and 6 guests