mirror of
https://github.com/bvanroll/love2d-shaders.git
synced 2025-08-28 11:32:40 +00:00
trying to get a "character" in the engine
This commit is contained in:
39
main.lua
39
main.lua
@@ -1,5 +1,5 @@
|
||||
LOGLEVEL = 2
|
||||
|
||||
LOGLEVEL = 0
|
||||
HC = require 'lib/HC'
|
||||
|
||||
|
||||
-- severity levels:
|
||||
@@ -13,13 +13,14 @@ local pixelcode = [[
|
||||
extern number h;
|
||||
extern number lum;
|
||||
extern vec2 mouse;
|
||||
extern vec2 player;
|
||||
vec4 effect( vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords )
|
||||
{
|
||||
float r = screen_coords.x/w;
|
||||
float g = screen_coords.y/h;
|
||||
float b = (r + g) / 2;
|
||||
float a = 1 - distance(screen_coords, mouse)/ (lum) ;
|
||||
color = vec4(r, g, b, a+0.5);
|
||||
float b = 1 - distance(screen_coords, mouse)/ (lum) ;
|
||||
float a = 1 - distance(screen_coords, player)/ (lum) ;
|
||||
color = vec4(r, g, b, a+1);
|
||||
return Texel(tex, texture_coords) * color;
|
||||
}
|
||||
]]
|
||||
@@ -50,22 +51,24 @@ end
|
||||
function love.load()
|
||||
|
||||
shader = love.graphics.newShader(pixelcode, vertexcode)
|
||||
|
||||
world = love.physics.newWorld( 0, 0, true )
|
||||
h = love.graphics.getHeight( )
|
||||
w = love.graphics.getWidth( )
|
||||
player = love.physics.newBody( world, 500, 500, "dynamic")
|
||||
circle = HC.circle(400,300,20)
|
||||
end
|
||||
|
||||
|
||||
function love.update(dt)
|
||||
t = t + dt
|
||||
mouse_x, mouse_y = love.mouse.getPosition( )
|
||||
log("mouse x " .. mouse_x)
|
||||
log("mouse y " .. mouse_y)
|
||||
player_x, player_y = mouse_x, mouse_y
|
||||
--player:applyForce()
|
||||
shader:send("w", w)
|
||||
shader:send("h", h)
|
||||
shader:send("mouse", {mouse_x, mouse_y})
|
||||
shader:send("player", {player_x, player_y})
|
||||
shader:send("lum", lum)
|
||||
log("dt = " .. dt)
|
||||
if love.keyboard.isDown('space') then
|
||||
lum = lum + 1
|
||||
elseif love.keyboard.isDown('rctrl') then
|
||||
@@ -75,13 +78,27 @@ function love.update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
function getAngle(x1, y1, x2, y2)
|
||||
return math.atan2(y2 - y1, x2 - x1) * 180 / math.pi
|
||||
end
|
||||
|
||||
function drawPlayer()
|
||||
x, y = player:getPosition( )
|
||||
angle = getAngle(x, y, mouse_x, mouse_y)
|
||||
love.graphics.print( angle, 0, 0, 0, 1, 1, 0, 0, 0, 0 )
|
||||
player:setAngle(angle)
|
||||
player:applyForce(100, 100)
|
||||
log(player:getAngularVelocity())
|
||||
|
||||
love.graphics.circle( "fill", x, y, 5 )
|
||||
end
|
||||
|
||||
|
||||
function love.draw(dt)
|
||||
love.graphics.setShader(shader)
|
||||
love.graphics.rectangle("fill", 0, 0, w, h)
|
||||
love.graphics.setShader()
|
||||
love.graphics.rectangle("fill", 400, 400, 100, 100)
|
||||
|
||||
drawPlayer()
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user