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
 

Please welcome jramada, our newest member.

Who's Online: 5 Guests, 0 Users

Total Members: 555
Total Posts: 13059
Total Topics: 1480
Total Categories: 8
Total Boards: 35

Recent Posts:

Re: PGELua Help - need term for a special rotation fix (mathematical issue) by yaustar
Re: Lua Loader? by Buddy4point0
Re: Lua Loader? by osgeld
Re: Lua Loader? by acer5050
Re: Lua Loader? by bumuckl
Re: Lua Loader? by acer5050
Re: Lua Loader? by bumuckl
Lua Loader? by acer5050


Copyright © 2006-2007 www.EvilMana.com All rights reserved.
EvilMana Logo by emcp and Charlie