Fixed snake example after Vector2Angle change.

This commit is contained in:
jussi
2023-11-23 18:36:05 +02:00
parent 1ab9722875
commit 925afdf101
6 changed files with 29 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ DETAILED CHANGES:
- ADDED: SetTextLineSpacing. - ADDED: SetTextLineSpacing.
- ADDED: LoadSoundAlias and UnloadSoundAlias. - ADDED: LoadSoundAlias and UnloadSoundAlias.
- ADDED: GetApplicationDirectory. - ADDED: GetApplicationDirectory.
- FIXED: Snake example after Vector2Angle change.
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.6.0 Using Raylib 4.5 Release: ReiLua version 0.6.0 Using Raylib 4.5

View File

@@ -2,6 +2,8 @@ Current {
} }
Backlog { Backlog {
* Review events. Seems to be a lot of work for very little benefit if any.
Might just increase traffic between Lua and C needlessly.
* Platform specific API documentation. * Platform specific API documentation.
* Platform desktop SDL. * Platform desktop SDL.
* Thread safe Lua RL.event calling. * Thread safe Lua RL.event calling.

View File

@@ -110,6 +110,7 @@ function Rectangle:area()
return self.width * self.height return self.width * self.height
end end
--- Returns rectangle that fits both rectangles inside it
function Rectangle:fit( rec ) function Rectangle:fit( rec )
local pos = Vector2:new( math.min( self.x, rec.x ), math.min( self.y, rec.y ) ) local pos = Vector2:new( math.min( self.x, rec.x ), math.min( self.y, rec.y ) )
@@ -121,6 +122,12 @@ function Rectangle:fit( rec )
) )
end end
--- If rectangle is fully inside another rectangle
function Rectangle:isInside( rect )
return rect.x <= self.x and self.x + self.width <= rect.x + rect.width
and rect.y <= self.y and self.y + self.height <= rect.y + rect.height
end
function Rectangle:checkCollisionRec( rec ) function Rectangle:checkCollisionRec( rec )
return RL.CheckCollisionRecs( self, rec ) return RL.CheckCollisionRecs( self, rec )
end end

View File

@@ -130,8 +130,8 @@ function Vector2:lineAngle( v2 )
return RL.Vector2LineAngle( self, v2 ) return RL.Vector2LineAngle( self, v2 )
end end
function Vector2:atan() function Vector2:atan2()
return math.atan( self.x, self.y ) return math.atan( self.y, self.x )
end end
function Vector2:scale( scale ) function Vector2:scale( scale )

View File

@@ -3,6 +3,8 @@ if table.unpack == nil then
table.unpack = unpack table.unpack = unpack
end end
local Vector2 = require( "vector2" )
Vector3 = {} Vector3 = {}
Vector3.meta = { Vector3.meta = {
__index = Vector3, __index = Vector3,
@@ -78,6 +80,18 @@ function Vector3:clone()
return Vector3:new( self.x, self.y, self.z ) return Vector3:new( self.x, self.y, self.z )
end end
function Vector3:getVectorXY()
return Vector2:new( self.x, self.y )
end
function Vector3:getVectorXZ()
return Vector2:new( self.x, self.z )
end
function Vector3:getVectorZY()
return Vector2:new( self.z, self.y )
end
function Vector3:abs() function Vector3:abs()
return Vector3:new( math.abs( self.x ), math.abs( self.y ), math.abs( self.z ) ) return Vector3:new( math.abs( self.x ), math.abs( self.y ), math.abs( self.z ) )
end end

View File

@@ -175,14 +175,14 @@ end
local function drawSnake() local function drawSnake()
for i, seg in ipairs( snake.segments ) do for i, seg in ipairs( snake.segments ) do
local angle = -seg.heading:atan() + RL.PI / 2 local angle = seg.heading:atan2()
local source = Rect:new( 16, 0, 8, 8 ) local source = Rect:new( 16, 0, 8, 8 )
if i == 1 then -- Tail segment. Yes tail is actually the 'first' segment. if i == 1 then -- Tail segment. Yes tail is actually the 'first' segment.
source.x = 8 source.x = 8
if 1 < #snake.segments then if 1 < #snake.segments then
angle = -snake.segments[ 2 ].heading:atan() + RL.PI / 2 angle = snake.segments[ 2 ].heading:atan2()
end end
elseif i < #snake.segments and seg.heading ~= snake.segments[ i+1 ].heading then -- Turned middle segments. elseif i < #snake.segments and seg.heading ~= snake.segments[ i+1 ].heading then -- Turned middle segments.
source.x = 0 source.x = 0
@@ -209,8 +209,7 @@ local function drawSnake()
) )
end end
-- Let's draw the head last to keep it on top. -- Let's draw the head last to keep it on top.
-- local angle = -math.atan2( snake.heading.x, snake.heading.y ) + RL.PI / 2 local angle = snake.heading:atan2()
local angle = -snake.heading:atan() + RL.PI / 2
RL.DrawTexturePro( RL.DrawTexturePro(
snakeTexture, snakeTexture,
{ 24, 0, 8, 8 }, { 24, 0, 8, 8 },