forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Analog stick question Help!

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
my psprecious



Joined: 17 Feb 2006
Posts: 24

PostPosted: Sun Feb 19, 2006 6:08 pm    Post subject: Analog stick question Help! Reply with quote

I move around a png with the analog,
I use a colorpixel detection for my collision,
I'm able to get it to stop when it hit the color but then i can't move , what must I do to get the analog stick to continu moving the png without passing the red zone (like an obstacle)

Quote:
while true do

screen:clear()
analogS() --- analog function that I have ealier in my code
if bgC:pixel(x1, y1) == red then
move = false
else
move = true
end
if move == true then x1 = x0 ; y1 = y0
end


this is part of the code, where the pixel detection and stop happens


Last edited by my psprecious on Mon Feb 20, 2006 7:49 am; edited 3 times in total
Back to top
View user's profile Send private message
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Sun Feb 19, 2006 6:13 pm    Post subject: Reply with quote

You are stopping once you are ON the red pixel. What you probably want to do is stop before you get there. Try this:

Code:
while true do

screen:clear()
analogS() --- analog function that I have earlier in my code
if bgC:pixel(x0, y0) == red then
move = false
else
move = true
end
if move == true then x1 = x0 ; y1 = y0
end 
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
my psprecious



Joined: 17 Feb 2006
Posts: 24

PostPosted: Mon Feb 20, 2006 4:16 am    Post subject: Reply with quote

Thanx it's not that yet but it seems to be closer to my goal since I don't get stop, now it kind breaks and jump over but I think I might manage

except if got more great ideas like this one cause it really help the fact it doesn't stop totaly really helps me out now I feel I'm going somewhere, well the dot is hehe

big thx
Back to top
View user's profile Send private message
fattymc03



Joined: 11 Feb 2006
Posts: 18

PostPosted: Tue Feb 21, 2006 3:05 am    Post subject: Reply with quote

I'm not sure exactly where your problem is. Can we see your analogS() function. Also, this is a more efficient way to code your loop. You don't need that variable.

Code:
 
while true do

screen:clear()
analogS() --- analog function that I have earlier in my code
if bgC:pixel(x0, y0) ~= red then
x1 = x0 ; y1 = y0
end 
Back to top
View user's profile Send private message
my psprecious



Joined: 17 Feb 2006
Posts: 24

PostPosted: Tue Feb 21, 2006 6:14 am    Post subject: Reply with quote

Thanx mate here's the analog function

Quote:

function analogS()

pad = Controls.read()

dx = pad:analogX()
if math.abs(dx) > 32 then
x0 = x0 - dx / 64
end
dy = pad:analogY()
if math.abs(dy) > 32 then
y0 = y0 - dy / 64
end



What I'm trying to is to be able to go around the red pixel zone but never be able to go in or on it
Back to top
View user's profile Send private message
fattymc03



Joined: 11 Feb 2006
Posts: 18

PostPosted: Tue Feb 21, 2006 6:46 am    Post subject: Reply with quote

So, it stops you before entering the red area correct? If yes, the detection is working fine, its somewhere else in your code that is not enabling you to move. And you say you can't move at all once it reaches this red area. Like you can't move backwards. Does movement work perfect without reaching the red area? Is the x0/y0 your current position and x1/y1 the next position. It's hard to tell, at least to me, from just this code.
Back to top
View user's profile Send private message
my psprecious



Joined: 17 Feb 2006
Posts: 24

PostPosted: Wed Feb 22, 2006 8:54 am    Post subject: Reply with quote

Quote:
red = Color.new(255, 0, 0)

dot = Image.load("DATA/dot.png")
bgC = Image.load("DATA/bg col2.png")

x1 = 0 ; x0 = 0 ; y1 = 0 ; y0 = 0



------------------------------------------
---------Function Analog Stick------------
------------------------------------------

function analogS()

pad = Controls.read()

dx = pad:analogX()
if math.abs(dx) > 32 then
x0 = x0 + dx / 64

end
dy = pad:analogY()
if math.abs(dy) > 32 then
y0 = y0 + dy / 64

end
end


board = Image.createEmpty(480, 272)
while true do

screen:clear()
analogS() --- analog function
if bgC:pixel(x0, y0) == red then
move = false
--and
--analogS()
else
move = true
end
if move == true then x1 = x0 ; y1 = y0
end
board:clear()
board:blit(0, 0, bgC, 0, 0, bgC:width(), bgC:height(), false)
board:blit(x1, y1, dot, true)
screen:blit(0, 0, board)
screen.waitVblankStart()
screen.flip()

if pad:start() then break end

end


here's the entire code, now with x0, y0 in the pixel detection, it doesn't totally stop, but it's not what I'm trying to do I want it to feel the edge of the red zone, so been able to go around not teleport on the otherside like it does now

Big thanx for your help
Back to top
View user's profile Send private message
fattymc03



Joined: 11 Feb 2006
Posts: 18

PostPosted: Wed Feb 22, 2006 11:28 pm    Post subject: Reply with quote

The problem is that it keep moves even if you have hit the red spot once. Suppose you run into it by pressing left. It won't actually display the new spot of your dot but it still moves the x0 and y0, so eventually it is past the red area and thats why it "jumps" over it. If you want it to go around it, you need to kinda "stop" the updating of the x0 and y0 positions. I might suggest making boolean variables like moveLeft, moveRight, etc that will tell you if you can move in a certain direction. Then in the analog stick function, only update a certain x or y if you can move in that direction. Like:

if analog pressed left and moveLeft = true then
updateX
...
etc

in your detection code, update the boolean variables based on direction pressed and if it hit a red area, etc

Hope this helps.
Back to top
View user's profile Send private message
my psprecious



Joined: 17 Feb 2006
Posts: 24

PostPosted: Thu Feb 23, 2006 1:35 am    Post subject: Reply with quote

Ok what it was doing I pretty much understood, it's the analog part that was bugging me I think I was under the illusion that the analog couldn't do that

But now that you tell me I can control it like the d pad, this shouldn't be to hard

big thanx man someone sugested to detect pixel around I think that's when I got confuse
Back to top
View user's profile Send private message
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Thu Feb 23, 2006 2:10 am    Post subject: Reply with quote

fattymc03 wrote:
The problem is that it keep moves even if you have hit the red spot once. Suppose you run into it by pressing left. It won't actually display the new spot of your dot but it still moves the x0 and y0, so eventually it is past the red area and thats why it "jumps" over it. If you want it to go around it, you need to kinda "stop" the updating of the x0 and y0 positions.


This is kind of what I was suggesting with the fix I posted earlier. You need to get clear on what the different variables are being used for. If you decide that (x1, y1) is the current location and (x0, y0) is the location you are possibly going to move to, then you only need to fix your analogS() function to calculate the new position (x0, y0) based on the current position (x1, y1) plus the motion vector (dx/64, dy/64):

Code:
function analogS()
   pad = Controls.read()

   dx = pad:analogX()
   if math.abs(dx) > 32 then
      x0 = x1 + dx / 64
   end
   dy = pad:analogY()
   if math.abs(dy) > 32 then
      y0 = y1 + dy / 64
   end
end
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
my psprecious



Joined: 17 Feb 2006
Posts: 24

PostPosted: Thu Feb 23, 2006 1:58 pm    Post subject: Reply with quote

wow that makes so much sense

but what I get is weird, what happens is the get stock on the red pixel and to move away I need to go the opposite way, if I go up and down even if there is no red pixel it stays there. (would be great for a spider man game)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group