window_set = "no" --Control Variables | |
world_finished = "no" | |
tempy = 0 | |
tree_y = 0 | |
tree_y2 = 0 | |
tree_x = 0 | |
PlayerMapX = 25 --These are where the player should spawn. | |
PlayerMapY = 20 --see last comment | |
map_mov_x = 0 | |
World = {} --Mapdata needs to be global...other than that, it's somewhat done. | |
--height is sorted as 1 = lowest layer. | |
--mapdata is also rendered as vertical lines... | |
function set_window() | |
if window_set == "no" then | |
love.window.setMode(800, 640, {resizable=false, vsync=true,}) | |
love.window.setTitle("LoveTest") | |
window_set = "yes" | |
end | |
end | |
function FlatPlains() | |
for x=1,50 do | |
for y=2,stone_height do | |
World[x][y] = 19 | |
end | |
for y2=stone_height+1,(stone_height+1+dirt_height) do | |
World[x][y2] = 2 | |
tempy = y2 | |
end | |
for y3 = stone_height+1+dirt_height, 1+stone_height+dirt_height do | |
World[x][y3] = 3 | |
end | |
end | |
world_finished = "yes" | |
end | |
function GrassPlains() | |
for x=-5000,5000 do | |
variance = math.random(-1,1) | |
grass_chance = math.random(1,5) | |
for y1=2,stone_height+variance do | |
World[x][y1] = 19 | |
end | |
for y2 = stone_height+1, stone_height+dirt_height+1 + variance do | |
World[x][y2] = 2 | |
World[x][y2-1] = 2 | |
World[x][y2+1] = 3 | |
if grass_chance == 2 or grass_chance == 5 then | |
World[x][y2+2] = math.random(8,12) | |
end | |
end | |
end | |
world_finished = "yes" | |
end | |
function MakeLeaf() | |
World[tree_x-1][tree_y2+tree_y] = 20 | |
World[tree_x-1][tree_y2+tree_y+1] = 20 | |
World[tree_x-1][tree_y2+tree_y+2]=20 | |
World[tree_x][tree_y2+tree_y+1] = 20 | |
World[tree_x][tree_y2+tree_y+2] = 20 | |
World[tree_x+1][tree_y2+tree_y] = 20 | |
World[tree_x+1][tree_y2+tree_y+1] = 20 | |
World[tree_x+1][tree_y+tree_y2+2] = 20 | |
end | |
function GrassForest() | |
for x=1,50 do | |
variance = math.random(-1,1) | |
grass_chance = math.random(1,5) | |
tree_chance = math.random(1,20) | |
for y1=2,stone_height+variance do | |
World[x][y1] = 19 | |
end | |
for y2 = stone_height+1, stone_height+dirt_height+1 + variance do | |
World[x][y2] = 2 | |
World[x][y2-1] = 2 | |
World[x][y2+1] = 3 | |
if grass_chance == 2 or grass_chance == 5 then | |
World[x][y2+2] = math.random(8,12) | |
end | |
if tree_chance == 2 or tree_chance == 17 or treechance == 9 then | |
tree_height = math.random(3,5) | |
for ty=1, tree_height do | |
World[x][ty+y2] = 6 | |
end | |
tree_y = y2 | |
tree_x = x | |
tree_y2 = tree_height | |
MakeLeaf() | |
end | |
end | |
end | |
world_finished = "yes" | |
end | |
-- our tiles | |
tile = {} | |
for i=1,20 do -- tile loader. | |
tile[i] = love.graphics.newImage( "tile"..i..".png" ) | |
end | |
function generate_world() | |
if world_finished == "no" then | |
stone_height = math.random(15,20) | |
dirt_height = math.random(2,5) | |
biome = 2 --math.random(1,10) --see biome.txt to see biome defs. | |
for i=-5000,5000 do | |
World[i] = {} --World is now treated as World[i][<new>] 512 is the entire map height | |
end | |
for x=-5000,5000 do | |
xr = x | |
for y=1,40 do | |
yr = y | |
if y == 1 then | |
World[xr][yr] = 4 -- Generate bedrock | |
else | |
World[xr][yr] = 1 -- Generate air | |
end | |
end | |
end | |
if biome == 1 then | |
FlatPlains() | |
end | |
if biome == 2 then | |
GrassPlains() | |
end | |
if biome == 3 then | |
GrassForest() | |
end | |
end | |
end | |
play_x = 0 | |
function render_world() | |
love.graphics.setBackgroundColor(0,181,255) | |
for y=1,40 do | |
for x=0,51 do | |
if y == 1 and x == 1 then | |
love.graphics.draw(tile[World[play_x+x][y]], (x-1)*16+(map_mov_x%16), 640-16) | |
else | |
love.graphics.draw(tile[World[play_x+x][y]], (x-1)*16+(map_mov_x%16), 640-16*y) | |
end | |
end | |
end | |
end | |
hotbar_bg = love.graphics.newImage("hotbar_bg.png") | |
function PlayerHotBar() | |
love.graphics.draw(hotbar_bg, 400-34, 640 - 24) | |
love.graphics.draw(hotbar_bg, 400-68, 640 - 24) | |
love.graphics.draw(hotbar_bg, 400-(34*3), 640 - 24) | |
love.graphics.draw(hotbar_bg, 400-(34*4), 640 - 24) | |
love.graphics.draw(hotbar_bg, 400, 640 - 24) | |
love.graphics.draw(hotbar_bg, 400+34, 640 - 24) | |
love.graphics.draw(hotbar_bg, 400+68, 640 - 24) | |
love.graphics.draw(hotbar_bg, 400+(34*3), 640 - 24) | |
end | |
function DisplayHealth() | |
half_heart = love.graphics.newImage("half_heart.png") | |
heart = love.graphics.newImage("heart.png") | |
if health >= 2 then | |
love.graphics.draw(heart, 264+3, 640 - 46) | |
elseif health == 1 then | |
love.graphics.draw(half_heart, 264+3, 640-46) | |
else | |
--do bugger all | |
end | |
if health >= 4 then | |
love.graphics.draw(heart, 298+3, 640 - 46) | |
elseif health == 3 then | |
love.graphics.draw(half_heart, 298+3, 640 - 46) | |
else | |
--do bugger all | |
end | |
if health >= 6 then | |
love.graphics.draw(heart, 332+3, 640 - 46) | |
elseif health == 5 then | |
love.graphics.draw(half_heart, 332+3, 640 - 46) | |
else | |
--do bugger all | |
end | |
if health >= 8 then | |
love.graphics.draw(heart, 366+3, 640 - 46) | |
elseif health == 7 then | |
love.graphics.draw(half_heart, 366+3, 640 - 46) | |
else | |
--do bugger all | |
end | |
if health >= 10 then | |
love.graphics.draw(heart, 400+3, 640 - 46) | |
elseif health == 9 then | |
love.graphics.draw(half_heart, 400+3, 640 - 46) | |
else | |
--do bugger all | |
end | |
if health >= 12 then | |
love.graphics.draw(heart, 434+3, 640 - 46) | |
elseif health == 11 then | |
love.graphics.draw(half_heart, 434+3, 640 - 46) | |
else | |
--do bugger all | |
end | |
if health >= 14 then | |
love.graphics.draw(heart, 468+3, 640 - 46) | |
elseif health == 13 then | |
love.graphics.draw(half_heart, 468+3, 640 - 46) | |
else | |
--do bugger all | |
end | |
if health == 16 then | |
love.graphics.draw(heart, 502+3, 640 - 46) | |
elseif health == 15 then | |
love.graphics.draw(half_heart, 502+3, 640 - 46) | |
else | |
--do bugger all | |
end | |
end | |
function love.update(dt) | |
if love.keyboard.isDown("left") and inventory_open == "no" then | |
map_mov_x = map_mov_x + 2 | |
if map_mov_x % 16 == 0 then | |
play_x = play_x - 1 | |
end | |
end | |
if love.keyboard.isDown("right") and inventory_open == "no" then | |
map_mov_x = map_mov_x - 2 | |
if map_mov_x % 8 == 0 then | |
play_x = play_x + 1 | |
end | |
end | |
if love.keyboard.isDown("up") then | |
health = health + 1 | |
end | |
if love.keyboard.isDown("down") then | |
health = health - 1 | |
end | |
if love.keyboard.isDown("r") then | |
world_finished = "no" | |
end | |
if love.keyboard.isDown("i") then | |
inventory_open = "yes" | |
end | |
if love.keyboard.isDown("escape") and inventory_open == "yes" then | |
inventory_open = "no" | |
end | |
if love.keyboard.isDown("escape") and inventory_open == "no" and love.keyboard.isDown("y") then | |
love.event.quit() | |
end | |
if health > 16 then | |
health = 16 | |
end | |
end | |
inventory_open = "no" | |
chat_buffer = {} | |
health = 16 | |
function DisplayInventory() | |
inv_bg = love.graphics.newImage("inv_bg.png") | |
love.graphics.draw(inv_bg, 0,0) | |
end | |
function ChatSystem() | |
love.graphics.print("message to be printed at some point in the near future.", 0,16) | |
end | |
function love.draw() | |
set_window() | |
generate_world() | |
render_world() | |
PlayerHotBar() | |
--love.graphics.print(map_mov_x, 0,0) | |
if inventory_open == "yes" then | |
DisplayInventory() | |
else | |
DisplayHealth() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment