diff options
author | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-17 19:09:33 -0400 |
---|---|---|
committer | Andy Belle-Isle <drumsetmonkey@gmail.com> | 2019-09-17 19:09:33 -0400 |
commit | 2cedd39a90fdb0387783b50446b16732517fb651 (patch) | |
tree | 78efc6f36096b7e0e0ff200220298c4ee7576bf1 /Scripts | |
parent | 0236eb7f6391c9d925dcaaddb8cb01ecfb7d5e55 (diff) |
World can now draw properly, and camera follows player
Diffstat (limited to 'Scripts')
-rw-r--r-- | Scripts/init.lua | 154 | ||||
-rw-r--r-- | Scripts/world.lua | 20 |
2 files changed, 44 insertions, 130 deletions
diff --git a/Scripts/init.lua b/Scripts/init.lua index 78b2a76..84d2073 100644 --- a/Scripts/init.lua +++ b/Scripts/init.lua @@ -1,30 +1,30 @@ -bird = { +player = { Player = 0, EventListeners = { MoveLeftPressed = function(self) - self.Velocity.x = self.Velocity.x - 100 + self.Velocity.x = self.Velocity.x - 3 self.Render.flipx = true; end, MoveLeftReleased = function(self) - self.Velocity.x = self.Velocity.x + 100 + self.Velocity.x = self.Velocity.x + 3 end, MoveRightPressed = function(self) - self.Velocity.x = self.Velocity.x + 100 + self.Velocity.x = self.Velocity.x + 3 self.Render.flipx = false; end, MoveRightReleased = function(self) - self.Velocity.x = self.Velocity.x - 100 + self.Velocity.x = self.Velocity.x - 3 end, JumpKeyPressed = function(self) if self.Physics.standing == true then - self.Velocity.y = self.Velocity.y + 210 + self.Velocity.y = self.Velocity.y + 9 end end, JumpKeyReleased = function(self) end }, Position = { - x = 150, + x = 15, y = 75 }, Velocity = { @@ -62,127 +62,35 @@ bird = { visibleTick = 0 } -cat = { - Velocity = { - x = 0.0, - y = 0.0 - }, - Position = { - x = 180, - y = -75 - }, - Render = { - texture = "Assets/cat.png", - normal = "Assets/cat_normal.png", - visible = true - }, - counter = 0; - Idle = function(self) - self.Velocity.x = -100 * math.sin(math.rad(self.counter)); - self.Velocity.y = 100 * math.cos(math.rad(self.counter)); - self.counter = self.counter + 5; - end, - PhysicsIdle = function(self) - if self.Velocity.x < 0 then - self.Render.flipx = true - elseif self.Velocity.x > 0 then - self.Render.flipx = false - end - end -} - -animal = { - Name = "animal", - Velocity = { -- This will automatically assign position to (0,0) - x = 0.0, - y = 0.0 - }, - Render = { - texture = "Assets/rabbit.png", - visible = true - }, - Light = { - r = 0.0, - b = 1.0, - g = 0.2, - strength = 1.0 - }, - Idle = function(self) - self.Velocity.x = -200 * math.sin(math.rad(self.counter)); - self.Velocity.y = 500 * math.cos(math.rad(self.counter*5)); - self.counter = self.counter + 5; - end, - counter = 0, - TestMe = function(self) - print("Light: rgb("..self.Light.r..","..self.Light.g..","..self.Light.b..")") - end -} - -wall = { - Position = { - y = -100 - }, - Render = { - texture = "Assets/rock.png", - normal = "Assets/rock_normal.png", - visible = true - } -} - -- Create the world dofile("Scripts/world.lua") -birdSpawn = game.spawn(bird); - -dogSpawn = game.spawn(cat); - -animalSpawn = game.spawn(animal); - -wallSpawn = game.spawn(wall); - -game.spawn({ - Velocity = { - x = 0, - y = 0 - }, - Light = { - r = 0.8, - g = 0.1, - b = 0.2, - strength = 0.75 - }, - counter = 0; - Idle = function(self) - self.Velocity.x = -100 * math.sin(math.rad(self.counter)); - self.Velocity.y = 100 * math.cos(math.rad(self.counter)); - self.counter = self.counter + 5; - end -}); +playerSpawn = game.spawn(player); ------------------- -- SERIALIZING -- ------------------- -function serial (before_ser) - binary = string.dump(before_ser) - formatted_binary = "" - for i = 1, string.len(binary) do - dec, _ = ("\\%3d"):format(binary:sub(i, i):byte()):gsub(' ', '0') - formatted_binary = formatted_binary .. dec - end - return formatted_binary -end - -function hello(herro) - print("Hello world ".. herro) -end - ---print(serial(hello)) - -local ser = string.dump(hello) -f2 = (loadstring or load)(ser) -f2("shite") - -local testPut = string.dump(animalSpawn.TestMe) -testRun = (loadstring or load)(testPut) -testRun(animalSpawn) +--function serial (before_ser) +-- binary = string.dump(before_ser) +-- formatted_binary = "" +-- for i = 1, string.len(binary) do +-- dec, _ = ("\\%3d"):format(binary:sub(i, i):byte()):gsub(' ', '0') +-- formatted_binary = formatted_binary .. dec +-- end +-- return formatted_binary +--end +-- +--function hello(herro) +-- print("Hello world ".. herro) +--end +-- +----print(serial(hello)) +-- +--local ser = string.dump(hello) +--f2 = (loadstring or load)(ser) +--f2("shite") +-- +--local testPut = string.dump(animalSpawn.TestMe) +--testRun = (loadstring or load)(testPut) +--testRun(animalSpawn) diff --git a/Scripts/world.lua b/Scripts/world.lua index 8fb3136..044559a 100644 --- a/Scripts/world.lua +++ b/Scripts/world.lua @@ -63,21 +63,27 @@ world = { Generate = function(self) math.randomseed(self.Seed) xsize, ysize, zsize = self:setSize(250, 128, 3) - --self.data = {} for Z = 0,zsize-1 do - --self.data[Z] = {} for X = 0,xsize-1 do - --self.data[Z][X] = {} - YGen = math.floor(6*math.sin(X/20) + Z) + 64 - YDepth = math.random(2,5) + if Z == 0 then + YGen = math.floor(6*math.sin(X/20)) + 64 + elseif Z == 1 then + YGen = math.floor(9*math.sin(X/20)) + 64 + else + YGen = math.floor(15*math.sin(X/20)) + 64 + end + YDepth = math.random(3,5) for Y = 0,ysize-1 do if Y == YGen then self:setData(X, Y, Z, "grass"); elseif Y < YGen and Y > (YGen - YDepth) then self:setData(X, Y, Z, "dirt"); elseif Y < YGen then - --self:setData(X, Y, Z, "stone"); - self:setData(X, Y, Z, "grass"); + self:setData(X, Y, Z, "stone"); + elseif Y == YGen + 1 then + if math.random(0, 100) == 53 then + self:setData(X, Y, Z, "flower"); + end end --print(X..","..Y..","..Z); end |