add angle
This commit is contained in:
parent
76e61ed233
commit
20b0b26e29
BIN
game/love_src/asset/image/arrow_right.png
Normal file
BIN
game/love_src/asset/image/arrow_right.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 620 B |
@ -58,10 +58,11 @@ local function get(e)
|
||||
e[race.dict.decel].data
|
||||
end
|
||||
|
||||
local function draw(text, x, y, sx, sy, angle)
|
||||
local function draw(text, x, y, sx, sy, angle, image, origin)
|
||||
love.graphics.push()
|
||||
love.graphics.scale(sx, sy)
|
||||
love.graphics.rotate(angle)
|
||||
-- love.graphics.rotate(angle)
|
||||
love.graphics.draw(image, x, y, angle, 1, 1, origin[1], origin[2])
|
||||
love.graphics.print(text, x, y)
|
||||
love.graphics.pop()
|
||||
end
|
||||
@ -76,17 +77,25 @@ function system:load()
|
||||
component.component("race.angle", function (c, x)
|
||||
c.data = x
|
||||
end)
|
||||
component.component("race.image", function (c, x)
|
||||
c.data = {
|
||||
image = love.graphics.newImage(x)
|
||||
}
|
||||
c.data.origin = vm.vec2(c.data.image:getWidth()/2, c.data.image:getHeight()/2)
|
||||
end)
|
||||
|
||||
for _, e in ipairs(self.pool) do
|
||||
e:give("race.pos", 10, 10)
|
||||
e:give("race.scale", 1, 1)
|
||||
e:give("race.angle", 0)
|
||||
e:give("race.image", "love_src/asset/image/arrow_right.png")
|
||||
end
|
||||
end
|
||||
|
||||
function system:update(dt)
|
||||
for _, e in ipairs(self.pool) do
|
||||
local accel, brake, grip, max_speed, steer, velocity, drag, decel = get(e)
|
||||
|
||||
local up = love.keyboard.isDown("up")
|
||||
local down = love.keyboard.isDown("down")
|
||||
local left = love.keyboard.isDown("left")
|
||||
@ -100,16 +109,22 @@ function system:update(dt)
|
||||
e[race.dict.velocity].data = racing_phy.accelerate(dt, 1, velocity, max_speed, -drag -decel)
|
||||
end
|
||||
|
||||
local angle = e["race.angle"].data
|
||||
if (left) then
|
||||
e["race.angle"].data = e["race.angle"].data - 1 * dt
|
||||
e["race.angle"].data = angle - 1 * dt
|
||||
end
|
||||
if (right) then
|
||||
e["race.angle"].data = e["race.angle"].data + 1 * dt
|
||||
e["race.angle"].data = angle + 1 * dt
|
||||
end
|
||||
|
||||
angle = e["race.angle"].data
|
||||
cos = math.cos(angle)
|
||||
sin = math.sin(angle)
|
||||
|
||||
velocity = e[race.dict.velocity].data
|
||||
|
||||
e["race.pos"].data = vm.vec2(e["race.pos"].data[1] + velocity, e["race.pos"].data[2])
|
||||
e["race.pos"].data[1] = e["race.pos"].data[1] + velocity * cos
|
||||
e["race.pos"].data[2] = e["race.pos"].data[2] + velocity * sin
|
||||
-- print(racing_phy.drift(dt, 1, velocity, max_speed, 2, 10))
|
||||
end
|
||||
end
|
||||
@ -118,7 +133,9 @@ function system:draw()
|
||||
for _, e in ipairs(self.pool) do
|
||||
local accel, brake, grip, max_speed, steer, velocity = get(e)
|
||||
local x, y, sx, sy, angle = e["race.pos"].data[1], e["race.pos"].data[2], e["race.scale"].data[1], e["race.scale"].data[2], e["race.angle"].data
|
||||
draw(velocity, x, y, sx, sy, angle)
|
||||
local image = e["race.image"].data.image
|
||||
local origin = e["race.image"].data.origin
|
||||
draw(velocity, x, y, sx, sy, angle, image, origin)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user