SORRY NOOB-A-RIFFIC - Cursor

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
glynnder
Posts: 35
Joined: Sun Sep 04, 2005 9:54 pm

SORRY NOOB-A-RIFFIC - Cursor

Post by glynnder »

Im seriously new to lua and was wondering if there was a code that made a cursor (cursor.png) move around the sreen with the analog stick and then when you hover over a button and hit x it will go to the thing that button does?

Also are menu's like in ttlde's file quite hard/easy to make?

here's my code:

Code: Select all

-- PSPOffice
--created by Glynnder
dblue = Color.new(0, 0, 255)
red = Color.new(230, 0, 0)
pink = Color.new(255, 0 , 153)
blue = Color.new(0 , 153, 255)
orange = Color.new(255, 102, 0)
gray = Color.new(153, 153, 153)
black = Color.new(0 , 0 , 0)
white = Color.new(255, 255, 255)

screen:print(194, 136, "loading: 0%", red)
screen.flip()
background = Image.load("images/home.png")

screen:clear()
screen:print(194, 136, "loading 20%", pink)
screen. flip()

pstype = Image.load("images/pstypebutton.png")

--created by glynnder
screen:clear()
screen:print(194, 136, "Loading: 40%", pink)
screen.flip()

psdraw = Image.load("images/psdrawbutton.png")
x1 = 0 ; x0 = 0 ; y1 = 0 ; y0 = 0

screen:clear()
screen:print(194, 136, "Loading: 60%", pink)
screen.flip()

pscalc = Image.load("images/pscalcbutton.png")


screen:clear()
screen:print(194, 136, "Loading: 80%", pink)
screen.flip()

links = Image.load("images/linksbutton.png")

screen:clear()
screen:print(194, 136, "Loading: 90%", pink)
screen.flip()

bg2 = Image.load("images/apps.png")
cursor = Image.load("images/cursor.png")

screen:clear()
screen:print(194, 136, "Loading: 100%", pink)
screen.flip() 

screen.waitVblankStart(60)
screen.flip()


while true do
          screen:blit(0, 0, background, false)
		  screen:blit(30, 150, pstype, true)
		  screen:blit(100, 195, pscalc, true)
		  screen:blit(285, 195, psdraw, true)
		  screen:blit(355, 150, links, true)
		  	time = os.time()
        	dateString = os.date("%c")
			screen:print(1, 1, os.date(), red)
			dateFields = os.date("*t")
			hour = dateFields.hour
			if hour < 10 then
				hour = "0" .. hour
			end
			min = dateFields.min
			if min < 10 then
			min = "0" .. min
			end
	sec = dateFields.sec
	if sec < 10 then
		sec = "0" .. sec
	end
      screen&#58;print&#40;30, 260, "Press 'Start' to quit", blue&#41;
      screen&#58;print&#40;400, 1, "Batt&#58;", red&#41;
      if  &#40;System.powerIsLowBattery&#40;&#41;&#41; == true then
	  screen&#58;print&#40;440, 1, tostring&#40;System.powerGetBatteryLifePercent&#40;&#41;&#41; .. "%", blue&#41;
	  else screen&#58;print&#40;450, 1, tostring&#40;System.powerGetBatteryLifePercent&#40;&#41;&#41; .. "%", red&#41;
	  end
	  if &#40;System.powerIsBatteryCharging&#40;&#41;&#41; == true then
	  screen&#58;print&#40;457, 1, "+", red&#41; end 
                screen&#58;print&#40;300, 260, "'Select' = Screenshot", white&#41;
          pad = Controls.read&#40;&#41; 
          screen.flip&#40;&#41;
                   
          if pad&#58;start&#40;&#41; then
                    break
          end          
          if pad&#58;select&#40;&#41; then
          screen&#58;save&#40;"screenshot.jpg"&#41;  
function analogS&#40;&#41; 
   pad = Controls.read&#40;&#41; 

   dx = pad&#58;analogX&#40;&#41; 
   if math.abs&#40;dx&#41; > 32 then 
      x0 = x1 + dx / 64 
   end 
   dy = pad&#58;analogY&#40;&#41; 
   if math.abs&#40;dy&#41; > 32 then 
      y0 = y1 + dy / 64 
   end 
end 
screen&#58;blit&#40;x0, y0, cursor, true&#41;
screen.flip&#40;&#41;
      end
	  end
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

Re: SORRY NOOB-A-RIFFIC - Cursor

Post by wekilledbambi03 »

if this is where your images are for the icons

Code: Select all

		  screen&#58;blit&#40;30, 150, pstype, true&#41;
		  screen&#58;blit&#40;100, 195, pscalc, true&#41;
		  screen&#58;blit&#40;285, 195, psdraw, true&#41;
		  screen&#58;blit&#40;355, 150, links, true&#41;
you can use these coordinates to make yourself a "box". for the purpose of making this simple ill pretend your icons are 10x10. and your cursor is at x0, y0. now well use the psptype iscon. well say

Code: Select all

if x0>30 and x0<40 and y0>150 and y0 < 160 and pad&#58;cross&#40;&#41;
then whatever
end
there may be different or better ways to do it but thats how id do it.
glynnder
Posts: 35
Joined: Sun Sep 04, 2005 9:54 pm

Post by glynnder »

OOk, the solves the clicking problem, but its still doesn't move!

Can anyone help with that?
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

Code: Select all

pad = Controls.read&#40;&#41;

                dx = pad&#58;analogX&#40;&#41;
	if math.abs&#40;dx&#41; > 32 then
		x0 = x0 + dx / 64
	end
	dy = pad&#58;analogY&#40;&#41;
	if math.abs&#40;dy&#41; > 32 then
		y0 = y0 + dy / 64
	end
That should get the cursor moving. im sure you can work it out from there
Post Reply