Skip to content

Commit

Permalink
0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Jan 7, 2021
1 parent 1ec6fdf commit 794d229
Show file tree
Hide file tree
Showing 22 changed files with 403 additions and 148 deletions.
43 changes: 43 additions & 0 deletions Data/Maps/Map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"tileset": "Blocks",
"sheet_size": [512, 512],
"tile_size": 32,
"blocks": {
"$default": {
"shape": "Cube",
"unwrap_mode": "Collapsed",
"orientation": 0
},
"9": {
"$name": "grass_plains",
"unwrap_mode": "Custom",
"mapping": [[10, 2], [1, 2], [2, 2], [2, 2], [2, 2], [2, 2], [2, 2]]
},
"10": {
"$name": "grass_forest",
"unwrap_mode": "Custom",
"mapping": [[11, 2], [1, 2], [3, 2], [3, 2], [3, 2], [3, 2], [3, 2]]
},
"11": {
"$name": "grass_snowy",
"unwrap_mode": "Custom",
"mapping": [[12, 2], [1, 2], [4, 2], [4, 2], [4, 2], [4, 2], [4, 2]]
},
"16": {
"$name": "log_oak",
"unwrap_mode": "Custom",
"mapping": [[9, 3], [9, 3], [1, 3], [1, 3], [1, 3], [1, 3], [1, 3]]
},
"17": {
"$name": "log_redwood",
"unwrap_mode": "Custom",
"mapping": [[10, 3], [10, 3], [2, 3], [2, 3], [2, 3], [2, 3], [2, 3]]
},
"18": {
"$name": "log_spruce",
"unwrap_mode": "Custom",
"mapping": [[11, 3], [11, 3], [3, 3], [3, 3], [3, 3], [3, 3], [3, 3]]
}
},
"$mapping_order": ["top", "bottom", "left", "right", "back", "front"]
}
Binary file removed Data/Models/Menu/Button.png
Binary file not shown.
Binary file added Data/Models/Menu/ButtonSquare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data/Models/Menu/ButtonSquareThin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data/Models/Menu/ButtonWide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Data/Models/Square.png
Binary file not shown.
36 changes: 36 additions & 0 deletions Data/Scenes/Game.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- Player
- PlayerContainer
- PlayerModel
- CameraPivot
- Camera
- GUI
- F3
- Version
- Coords
- Crosshair
- SavedText
- Hotbar
- SelectedBlock
- BlockPlacer
- PauseMenu
- PauseTitle
- ResumeButton
- ResumeButtonText
- SaveButton
- SaveButtonText
- QuitButton
- QuitButtonText
- SaveMenu
- SaveTitle
- World1Button
- World1ButtonText
- World2Button
- World2ButtonText
- World3Button
- World3ButtonText
- BackButton
- BackButtonText
- Map
- BlockPreview
- Sky
- Exit
22 changes: 22 additions & 0 deletions Data/Scenes/MainMenu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- Scripts
- Camera
- Background
- Version
- Logo
- LoadingBox
- LoadingText
- Buttons
- Main
- PlayButton
- ExitButton
- Play
- LoadWorldButton
- NewWorldButton
- WorldSelect
- World1Button
- World2Button
- World3Button
- WorldType
- NormalWorldButton
- FlatWorldButton
- BackButton
Binary file added Data/Scripts/Game/CharacterControl_.csscript
Binary file not shown.
10 changes: 0 additions & 10 deletions Data/Scripts/Game/EscapeToMenu.lua

This file was deleted.

91 changes: 91 additions & 0 deletions Data/Scripts/Game/PauseMenu.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
local currentMenu = 'pause'
local buttons = {"resume", "save", "world1", "world2", "world3", "back", "quit"}
local hovered = {}
local pos = {}

local savedText
local savedTick = 0

function Behavior:Update()
savedTick = savedTick + 1

local camera = CS.FindGameObject("Camera")
local mousePos = CS.Input.GetMousePosition()
local ray = camera:GetComponent("Camera"):CreateRay(mousePos)

local pauseMenu = CS.FindGameObject("PauseMenu")
local saveMenu = CS.FindGameObject("SaveMenu")

if not savedText then savedText = CS.FindGameObject("SavedText"):GetComponent("TextRenderer") end

local size = {large = Vector3:New(.9, .9, .9), regular = Vector3:New(.8, .8, .8)}

-- Pause menu open/close
if CS.Input.WasButtonJustPressed("Escape") then
ingame = not ingame
currentMenu = 'pause'
end
self.gameObject.transform:SetLocalPosition(Vector3:New(0, 0, ingame and .5 or -.5))
CS.FindGameObject("GUI").transform:SetLocalPosition(Vector3:New(0, 0, ingame and -.25 or .25))

-- Initialise buttons
for _,name in ipairs(buttons) do
buttons[name] = CS.FindGameObject(name:sub(1,1):upper() .. name:sub(2) .. "Button")
if not pos[name] then pos[name] = buttons[name].transform:GetPosition() end
hovered[name] = ray:IntersectsModelRenderer(buttons[name]:GetComponent("ModelRenderer")) ~= nil
buttons[name].transform:SetLocalScale(hovered[name] and size.large or size.regular)
end

-- Button clicks
if CS.Input.WasButtonJustPressed("LClick") then
if currentMenu == 'pause' then
if hovered.resume then ingame = true
elseif hovered.save then currentMenu = 'save'
elseif hovered.quit then CS.Exit()
end
elseif currentMenu == 'save' then
if hovered.back then currentMenu = 'pause'
elseif hovered.world1 then SaveWorld(1)
elseif hovered.world2 then SaveWorld(2)
elseif hovered.world3 then SaveWorld(3)
end
end
end

-- Switch menus
local positions = {visible = Vector3:New(0, 0, -0.5), hidden = Vector3:New(0, 0, 0.5)}
if not ingame then
if currentMenu == 'pause' then
pauseMenu.transform:SetLocalPosition(positions.visible)
saveMenu.transform:SetLocalPosition(positions.hidden)
elseif currentMenu == 'save' then
saveMenu.transform:SetLocalPosition(positions.visible)
pauseMenu.transform:SetLocalPosition(positions.hidden)
end
else
saveMenu.transform:SetLocalPosition(positions.hidden)
pauseMenu.transform:SetLocalPosition(positions.hidden)
end

-- Saved text
if savedTick > 3*60 then
savedText:SetOpacity(0)
savedTick = 0
end

-- Mouse locking
if ingame then CS.Input.LockMouse() else CS.Input.UnlockMouse() end


end

function SaveWorld(id)
CS.Storage.Save(
"World" .. id,
{seed = worldSeed, biomeCoords = biomeCoords, worldType = worldType, placedBlocks = placedBlocks},
function(err) print(err ~= nil and "Unknown error" or "Successfully saved world " .. id) end
)
ingame = not ingame
currentMenu = 'pause'
savedText:SetOpacity(1)
end
48 changes: 22 additions & 26 deletions Data/Scripts/Game/PlayerActions.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
hotbar = { -- blocks obj is in 'World generation'
local hotbar = {
blocks.stone, blocks.clay, blocks.dirt, blocks.grass, blocks.oak_log,
blocks.oak_leaf, blocks.sand, blocks.tin, blocks.copper, blocks.asphalt
}

selectedBlock = blocks.stone
currentSlot = 1
showCoords = 1
canBuild = true

local selectedBlock = blocks.stone
local currentSlot = 1
local showF3 = false
local canBuild = true
local tick = 0

function Behavior:Update()
function Behavior:Update()
if ingame then
tick = tick + 1

local player = CS.FindGameObject("Player")
Expand All @@ -27,9 +26,7 @@ function Behavior:Update()
local blockSelection = CS.FindGameObject("SelectedBlock")

-- Toggle build
if CS.Input.WasButtonJustPressed("ToggleBuild") then
canBuild = not canBuild
end
if CS.Input.WasButtonJustPressed("ToggleBuild") then canBuild = not canBuild end

-- Change item slot
for i=1,10,1 do
Expand Down Expand Up @@ -60,45 +57,44 @@ function Behavior:Update()
end

-- Build
if CS.Input.IsButtonDown("RClick") and canBuild and tick > 10 then
if map:GetBlockIDAt(x,y,z) == blocks.air then
if CS.Input.IsButtonDown("RClick") and canBuild and tick > clickDelay then
if map:GetBlockIDAt(x,y-worldYOffset,z) == blocks.air then
map:SetBlockAt(x,y-worldYOffset,z, selectedBlock, north)
placedBlocks[x .. '/' .. y-worldYOffset .. '/' .. z] = selectedBlock
tick = 0
end
end
if CS.Input.IsButtonDown("LClick") and canBuild and tick > 10 then
if CS.Input.IsButtonDown("LClick") and canBuild and tick > clickDelay then
map:SetBlockAt(x,y-worldYOffset,z, blocks.air, north)
placedBlocks[x .. '/' .. y-worldYOffset .. '/' .. z] = blocks.air
tick = 0
end

-- Nuke
local nukeSize = 2 -- 5x5x5
if CS.Input.WasButtonJustPressed("Nuke") then
if CS.Input.WasButtonJustPressed("Nuke") and tick > clickDelay then
for i=-nukeSize,nukeSize,1 do
for j=-nukeSize,nukeSize,1 do
for k=-nukeSize,nukeSize,1 do
if math.randomrange(0,5) > 1 then
map:SetBlockAt(x+i,y+j-worldYOffset,z+k, blocks.air, north)
map:SetBlockAt(x+i, y+j-worldYOffset, z+k, blocks.air, north)
placedBlocks[x+i .. '/' .. y+j-worldYOffset .. '/' .. z+k] = blocks.air
end
end
end
end
tick = 0
end

-- Coords
-- F3
if CS.Input.WasButtonJustReleased("ToggleCoords") then showF3 = not showF3 end
local posX = tostring(playerPos.y).format("%.1f", playerPos.x/2)
local posY = tostring(playerPos.y).format("%.1f", playerPos.y/2-worldYOffset-0.25)
local posZ = tostring(playerPos.y).format("%.1f", playerPos.z/2)
local posText = posX .. ' / ' .. posY .. ' / ' .. posZ

if CS.Input.WasButtonJustReleased("ToggleCoords") then
showCoords = showCoords + 1
end

if showCoords % 2 == 0 then
coords.textRenderer:SetText(posText)
else
coords.textRenderer:SetText('')
end
CS.FindGameObject("Version"):GetComponent("TextRenderer"):SetText(showF3 and version or '')
coords.textRenderer:SetText(showF3 and posText or '')

end
end
Loading

0 comments on commit 794d229

Please sign in to comment.