diff options
| author | jussi | 2024-08-27 21:41:31 +0300 |
|---|---|---|
| committer | jussi | 2024-08-27 21:41:31 +0300 |
| commit | 35e73465ace06e459fb3911dee9c714bb79e8974 (patch) | |
| tree | e12f57788a32314f196aad11a4fc50539510bd0c /examples/snake/main.lua | |
| parent | af2bf6f7a248d9b6e78305b4ac9dbc72d2d41ef0 (diff) | |
| download | reilua-enhanced-35e73465ace06e459fb3911dee9c714bb79e8974.tar.gz reilua-enhanced-35e73465ace06e459fb3911dee9c714bb79e8974.tar.bz2 reilua-enhanced-35e73465ace06e459fb3911dee9c714bb79e8974.zip | |
LoadBufferFormatted, SetBufferData and CopyBufferData. Compressed resource file example.
Diffstat (limited to 'examples/snake/main.lua')
| -rw-r--r-- | examples/snake/main.lua | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/examples/snake/main.lua b/examples/snake/main.lua index 026e621..fe30403 100644 --- a/examples/snake/main.lua +++ b/examples/snake/main.lua @@ -1,11 +1,11 @@ package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua" Util = require( "utillib" ) -Vec2 = require( "vector2" ) -Rect = require( "rectangle" ) +Vector2 = require( "vector2" ) +Rectangle = require( "rectangle" ) -- Defines -local RESOLUTION = Vec2:new( 128, 128 ) +local RESOLUTION = Vector2:new( 128, 128 ) local TILE_SIZE = 8 local LEVEL_SIZE = RESOLUTION.x / TILE_SIZE local STATE = { TITLE = 0, GAME = 1, OVER = 2 } -- Enum. @@ -13,10 +13,10 @@ local STATE = { TITLE = 0, GAME = 1, OVER = 2 } -- Enum. -- Resources local framebuffer = nil local monitor = 0 -local monitorPos = Vec2:newT( RL.GetMonitorPosition( monitor ) ) -local monitorSize = Vec2:newT( RL.GetMonitorSize( monitor ) ) +local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) ) +local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) ) local winScale = 6 -local winSize = Vec2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale ) +local winSize = Vector2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale ) local gameState = STATE.GAME local grassTexture = nil local snakeTexture = nil @@ -28,10 +28,10 @@ local applePos = {} local function setSnake() snake = { - heading = Vec2:new( 1, 0 ), - control = Vec2:new( 1, 0 ), - headPos = Vec2:new( LEVEL_SIZE / 2, LEVEL_SIZE / 2 ), - segments = {}, -- { pos Vec2, heading Vec2 } + heading = Vector2:new( 1, 0 ), + control = Vector2:new( 1, 0 ), + headPos = Vector2:new( LEVEL_SIZE / 2, LEVEL_SIZE / 2 ), + segments = {}, -- { pos Vector2, heading Vector2 } grow = 2, } end @@ -52,7 +52,7 @@ local function addSegment() end local function setApplePos() - applePos = Vec2:new( math.random( 0, LEVEL_SIZE - 1 ), math.random( 0, LEVEL_SIZE - 1 ) ) + applePos = Vector2:new( math.random( 0, LEVEL_SIZE - 1 ), math.random( 0, LEVEL_SIZE - 1 ) ) local search = true while search do @@ -167,16 +167,16 @@ end --[[ Check if next segment is on left side. There are more mathematically elegant solution to this, but there is only four possibilities so we can just check them all. ]]-- local function onLeft( this, nextSeg ) - return ( this == Vec2:temp( 0, -1 ) and nextSeg == Vec2:temp( -1, 0 ) ) - or ( this == Vec2:temp( -1, 0 ) and nextSeg == Vec2:temp( 0, 1 ) ) - or ( this == Vec2:temp( 0, 1 ) and nextSeg == Vec2:temp( 1, 0 ) ) - or ( this == Vec2:temp( 1, 0 ) and nextSeg == Vec2:temp( 0, -1 ) ) + return ( this == Vector2:temp( 0, -1 ) and nextSeg == Vector2:temp( -1, 0 ) ) + or ( this == Vector2:temp( -1, 0 ) and nextSeg == Vector2:temp( 0, 1 ) ) + or ( this == Vector2:temp( 0, 1 ) and nextSeg == Vector2:temp( 1, 0 ) ) + or ( this == Vector2:temp( 1, 0 ) and nextSeg == Vector2:temp( 0, -1 ) ) end local function drawSnake() for i, seg in ipairs( snake.segments ) do local angle = seg.heading:atan2() - local source = Rect:temp( 16, 0, 8, 8 ) + local source = Rectangle:temp( 16, 0, 8, 8 ) if i == 1 then -- Tail segment. Yes tail is actually the 'first' segment. source.x = 8 |
