function love.load()
char = {posx = 40,posy = 160,width = 40, length = 40, health = 100}
end
function love.draw()
love.graphics.rectangle("fill",char.posx,char.posy,char.width,char.length)
end
-- Don't change this, I like it that way ~Evil_Bartek
function love.update(dt)
if love.keyboard.isDown("right") then
char.posx = char.posx + 0.4
elseif love.keyboard.isDown("left") then
char.posx = char.posx - 0.4
end
end
Just some noob code i wrote, you can see what it does...
How can i make it so when hes out of screen in a horizontal position. Like if he went out of the right or left side of the screen, how can i make him appear on the other side?
EDIT: I did make a conf.lua but thats not needed here...
Last edited by Evil_Bartek on Tue Dec 27, 2011 10:29 pm, edited 2 times in total.
Evil_Bartek wrote:
Just some noob code i wrote, you can see what it does...
How can i make it so when hes out of screen in a horizontal position. Like if he went out of the right or left side of the screen, how can i make him appear on the other side?
function love.update(dt)
if love.keyboard.isDown("right") then
char.posx = char.posx + 0.4
elseif love.keyboard.isDown("left") then
char.posx = char.posx - 0.4
end
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
if char.posx <= 0 then -- if the character "x" is equal less than "0" meaning it's outside the left side of the screen
char.posx = width - char.width -- set the character "x" to the width of the screen minus the character width, so he appears on the right side
elseif char.posx >= width - char.width then
char.posx = width - width
end
end
basically "love.graphics.getWidth, and getHeight" will grab the width and height of the screen. Using this you can just use some simple "if" statements to teleport the player if they go beyond the sides of the screen.
so this code is saying "if the characters "x" is less than the screen's x, then that means the character is going past the left side of the screen", and "if the characters "x" is MORE than the screen width then the character is going past the right side of the screen"
then you're just setting a new character.x, and character.y depending on what's happening.
Last edited by Ryne on Mon Dec 26, 2011 7:44 pm, edited 1 time in total.
It looks like its teleporting.
Can you make its so that if you go out of screen on the right it will only teleport if the left edge touches it?
Is that possible?
function love.load()
require "conf.lua"
char = {posx = 40,posy = 160,width = 40, length = 40, health = 100}
end
function love.draw()
love.graphics.rectangle("fill",char.posx,char.posy,char.width,char.length)
end
function love.update(dt)
if love.keyboard.isDown("right") then
char.posx = char.posx + 0.4
elseif love.keyboard.isDown("left") then
char.posx = char.posx - 0.4
end
local width = love.graphics.getWidth()
local lol = width + 40
local height = love.graphics.getHeight()
if char.posx <= -40 then
char.posx = width - char.width
elseif char.posx >= lol - char.width then
char.posx = width - width
end
end
Thatk you for the general template anyway, i improved your karma.
It looks like its teleporting.
Can you make its so that if you go out of screen on the right it will only teleport if the left edge touches it?
Is that possible?
By "warp" I assumed you meant teleport. Also yeah, you can just do the same thing as I did with the opposite side. Just "- character.w".
Evil_Bartek wrote:I FIXED IT SO ITS BETTER:
Thatk you for the general template anyway, i improved your karma.
function love.load()
require "conf.lua"
char = {posx = 40,posy = 160,width = 40, length = 40, health = 100}
end
function love.draw()
love.graphics.rectangle("fill",char.posx,char.posy,char.width,char.length)
end
function love.update(dt)
if love.keyboard.isDown("right") then
char.posx = char.posx + 0.4
elseif love.keyboard.isDown("left") then
char.posx = char.posx - 0.4
end
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
if char.posx <= -40 then
char.posx = (width + 35) - char.width
elseif char.posx >= (width + char.width) - char.width then
char.posx = (width - 35) - width
end
end
Its ass smooth as it could be...
Last edited by Evil_Bartek on Mon Dec 26, 2011 7:53 pm, edited 1 time in total.
function love.load()
require "conf.lua"
char = {posx = 40,posy = 160,width = 40, length = 40, health = 100}
end
function love.draw()
love.graphics.rectangle("fill",char.posx,char.posy,char.width,char.length)
end
function love.update(dt)
if love.keyboard.isDown("right") then
char.posx = char.posx + 0.4
elseif love.keyboard.isDown("left") then
char.posx = char.posx - 0.4
end
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
if char.posx <= -40 then
char.posx = (width + 35) - char.width
elseif char.posx >= (width + char.width) - char.width then
char.posx = (width - 35) - width
end
end
whats it matter in his own thread, its not like there is 15 threads in the forum covering the same topic (which is what I have always considered to be double posting), and you are just derealing the thing anyway ... 2 evils do not make bacon