I'm trying to make this RPG and everything's going quite well so far, but I'm a bit new when it comes to grid creation and scrolling through a level that has been created with tiles. Like I had mentioned before I'm trying to create a typical Japanese Roleplaying Game like Golden Sun or Final Fantasy; The effect I want to create is what can be seen in this playthrough of Golden Sun: http://www.youtube.com/watch?v=471MozBfrrE ( at 3.05 ). The problem I'm having is that the formula I'm using right now just works on one map and changing the resolution of my screen jumbles it up as well. I also don't really know how I can get my grid to stop moving once it reaches the -end- of the map. I hope this makes some sense at least. Anyway.. the code I have so far is this;
Code: Select all
function load_level(level)
love.filesystem.load(level)()
end
--new_map gets called in level
function new_map(mapwidth, mapheight, tile_w, tile_h, tilemap)
map_w = mapwidth
map_h = mapheight
tilewidth = tile_w
tileheight = tile_h
map = tilemap
tile = {}
Tileset = love.graphics.newImage("images/tilesheet.png")
local tilesetW, tilesetH = Tileset:getWidth(), Tileset:getHeight()
--temp quads, will probably use some sort of for loop for this later
firstQuad = love.graphics.newQuad(0,0,tile_w,tile_h,tilesetW,tilesetH)
secondQuad = love.graphics.newQuad(40,0,tile_w,tile_h,tilesetW,tilesetH)
thirdQuad = love.graphics.newQuad(80,0,tile_w,tile_h,tilesetW,tilesetH)
-- temp tiles, will probably use some sort of for loop for this later
tile[0] = firstQuad
tile[1] = secondQuad
tile[2] = firstQuad
end
function playerinit()
Player = love.graphics.newImage("images/player.png")
Playermovement = 0
Player_x = love.graphics.getWidth() / 2;
Player_y = love.graphics.getHeight() / 2;
end
-- temp variables
Grid_x = 0
Grid_y = 0
function draw_map()
local map_x = 0
local map_y = 0
for y=1, map_h do
for x=1, map_w do
love.graphics.drawq(Tileset, tile[map[y+map_y][x+map_x]], Grid_x + (x*tilewidth-tilewidth), Grid_y + (y*tileheight-tileheight))
end
end
end
function love.load()
load_level("levels/level1.lua")
playerinit()
end
function love.draw()
draw_map()
love.graphics.draw(Player, Player_x,Player_y)
end
function love.update(dt)
print(Grid_x)
if love.keyboard.isDown("lalt") and love.keyboard.isDown("f4") then
love.event.quit()
end
if love.keyboard.isDown( "right" ) then
Grid_x = Grid_x - 500 * dt
end
if love.keyboard.isDown( "left" ) then
Grid_x = Grid_x + 500 * dt
end
if love.keyboard.isDown( "up" ) then
Grid_y = Grid_y + 500 * dt
end
if love.keyboard.isDown( "down" ) then
Grid_y = Grid_y - 500 * dt
end
-- bounding box for the edges of the map, here's one of the main problems I'm having as it doesn't seem to work with other tilemaps and screen resolutions
if Grid_x >= (table.getn(map[1]) * tilewidth / 2) then
Grid_x = (table.getn(map[1]) * tilewidth / 2)
end
if Grid_x <= -(table.getn(map[1]) * tilewidth / 2) then
Grid_x = -(table.getn(map[1]) * tilewidth / 2)
end
if Grid_y >= (table.getn(map) * tileheight / 2) then
Grid_y = (table.getn(map) * tileheight / 2)
end
if Grid_y <= -(table.getn(map) * tileheight / 2) then
Grid_y = -(table.getn(map) * tileheight / 2)
end
end
Code: Select all
local map=
{
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,1,0,1,2,2,0,1,0,0,1,1},
{0,0,1,0,2,0,1,0,1,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
{0,0,1,0,2,0,1,0,2,1,0,0,1,0,2,0,1,0,2,1,1},
}
new_map(21, 16, 40, 40, map)
Thanks in advance