am trying to make a little fish jump to the air and make a little rotation when its come back to the sea am using this code for this matter
Code: Select all
function love.load()
angle = 0
food1 = {
x = -50,
y = 500,
ySpeed = 0,
xspeed = 1, -- the Speed we'll add to the Y movement
gravSecond = 1.5, -- gravity amount
fish1 = love.graphics.newImage("images/fish1.png"),
rotate = math.pi,
rotspeed =1/2,
}
setmetatable(food1,{__index =food})
return food1
end
function love.update(dt)
food1.rotate = food1.rotate+food1.rotspeed*dt
frame = dt * 30 -- I do this just because I think better this way
food1.ySpeed = food1.ySpeed + food1.gravSecond * frame -- We add gravity to the ySpeed
food1.y = food1.y + food1.ySpeed * frame -- We add ySpeed to the player's y position
if food1.y > 800 then -- Are we on the ground?
food1.y = food1.y - food1.ySpeed * frame -- If we are, We undo that moving down
food1.ySpeed = 0 -- The ySpeed is reset
end
food1.x = food1.x+food1.xspeed
if food1.ySpeed == 0 then -- Should we be jumping, and can we?
--This works because the ySpeed is only zero when we aren't already jumping.
food1.ySpeed = -45 -- Make us add a negative, to move up
end
if food1.x > 800 then
food1.x = 0
end
end
function love.draw()
love.graphics.draw(food1.fish1, food1.x, food1.y,food1.rotate)
-- Draw it!
end
how to make it rotate just when its comeback to the sea ???
please help
thanks