From d08f9e82d51b984a9402aedc87ae3b730c02b041 Mon Sep 17 00:00:00 2001 From: beppe Date: Thu, 14 Oct 2021 15:20:38 +0200 Subject: [PATCH] trying to get a "character" in the engine --- main.lua | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/main.lua b/main.lua index 79d052d..d41bd28 100644 --- a/main.lua +++ b/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