|
Submit Your Own Code
PSP
Lua CodeBase : Analog
Description
Simple code explaining how to use analog stick in LUA Code.
-- EVILMANA.COM PSP LUA CODEBASE
-- www.evilmana.com/tutorials/codebase
-- Analog
-- SUBMITTED BY: myschoo
--Analog Sample by myschoo
--colors
red = Color.new(255,0,0)
black = Color.new(0,0,0)
white = Color.new(255,255,255)
--creates player
player = Image.createEmpty(32,32)
player:clear(red)
--Players table
Player = { x = 100, y = 100, img = player }
--functiion for analog movement
function analogMove()
pad = Controls.read()
anaX = pad:analogX()
anaY = pad:analogY()
-- anaX and anaY represents number from -128 to 127
-- number "50" is analog deadzone
if anaX > 50 then
Player.x = Player.x + 5
end
if anaX < -50 then
Player.x = Player.x - 5
end
if anaY > 50 then
Player.y = Player.y + 5
end
if anaY < -50 then
Player.y = Player.y - 5
end
end
while true do
screen:clear()
screen:blit(Player.x,Player.y,Player.img)
analogMove()
-- prints X and Y analog coordinates
screen:print(5,5,"analogX: " .. anaX, white)
screen:print(5,15,"analogY: " .. anaY, white)
if pad:cross() then
break
end
screen.flip()
screen.waitVblankStart()
end
Back to CodeBase
|