Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17

Thread: Movement Script

  
  1. #1
    Master Inuyasha is offline -Hacks Neophyte
    Join Date
    Jul 2005
    Posts
    82
    Rep Power
    15

    Default

    can someone give me a movement script for the analog stick?

    Just tell me what to replace with my pics, and what other code i may need to add, etc. Thanks in advance!!!


  2. #2
    LordCthulu is offline Senior Member -Hacks Enthusiast
    Join Date
    Mar 2005
    Posts
    578
    Rep Power
    15

    Default

    Hehe, can you give a little more detail on what your wanting? And why you want to use the analog stick? I can show you what im using right now (although it isn't too great).
    Oldest psp-hacks member ever.

  3. #3
    Master Inuyasha is offline -Hacks Neophyte
    Join Date
    Jul 2005
    Posts
    82
    Rep Power
    15

    Default

    well, i really dont want to discuss my game alot, as its still beta, but what the heck. Okay, your a ship, and you have to fire at enemies right. You get weapon upgrades, armor, missiles, etc. But right now, i want to know how i can make the picture move up and down side to side.

    Also, if u can, can u help me with like a menu?

  4. #4
    LordCthulu is offline Senior Member -Hacks Enthusiast
    Join Date
    Mar 2005
    Posts
    578
    Rep Power
    15

    Default

    Hehe I didn't needa know that muh :P No worries, you can edit your post if you want, I just needed to know why analog stick, and what directions you wanted to move. Personally, I would use the d-pad because analog stick is, idunno, i don't like it really. My game uses dpad and analog, since dpad is lighter on the thumb :)
    I can help with menu too, i've gotten compliments on my games menu's just from a low res video :lol:

    Ok anyway, heres an example movement script using analog stick (theres better ways to do this no doubt, and the area the stick has to be in to count as movement is small, so you can just change the numbers)

    Notes: -Ignore the --{ and --} i copied most of this directly from one of my scripts and i put the brackets cuz I <3 C++ so shh! :p

    -The current coordinate (x, y) of the player, lets say its...(50, 50). When you go to blit(pcXpos, pcYpos, player), it blits the image starting at the top right. It's hard to explain. Lets say my image is a square. The top right corner of the square will be right on my X/Y coordinates. Like...

    `[]

    Imagine the ` as the (x, y) coordinate, and the [] as the image.

    Code:
    -- Players current X coord
    pcXpos = 0
    -- Players current Y coord
    pcYpos = 0
    -- Show the X/Y coords to adjust the movement #'s
    screen&#58;print&#40;0, 0, tostring&#40;pcXpos&#41;, red&#41;
    screen&#58;print&#40;0, 0, tostring&#40;pcYpos&#41;, red&#41;
    
    function updateMove&#40;xPos, yPos&#41;
    --&#123;
       analogPad = Controls.read&#40;&#41;
       dx = analogPad&#58;analogX&#40;&#41;
       dy = analogPad&#58;analogY&#40;&#41;
    -- Up
       if dx > -60 and dx < 40 and dy == -128  or analogPad&#58;up&#40;&#41; then
          pcYpos = pcYpos - 2
          playerDirection = "up"
       end
    -- Left
       if dy > -25 and dy < 40 and dx == -128 or analogPad&#58;left&#40;&#41; then
          pcXpos = pcXpos - 2
          playerDirection = "left"
       end
    -- Down
       if dx > -40 and dx < 40 and dy == 127 or analogPad&#58;down&#40;&#41; then
          pcYpos = pcYpos + 2
          playerDirection = "down"
       end
    -- Right
       if dy > -35 and dy < 45 and dx == 127 or analogPad&#58;right&#40;&#41; then
          pcXpos = pcXpos + 2
          playerDirection = "right"
       end
    
       -- Check to see if player is off screen
       if pcXpos >= 440 then
          pcXpos = 430
       elseif pcXpos < 0 then
          pcXpos = 10
       end
       if pcYpos >= 160 then
          pcYpos = 150
       elseif pcYpos < 0 then
          pcYpos = 10
       end
    --&#125;
    end
    
    -- And now blit our sprite according to their current coordinates
    screen&#58;blit&#40;pcXpos, pcYpos, sprite&#41;
    Ok. That's probably really confusing. I got voted out of the game so im good for a few mins till we find another.
    Oldest psp-hacks member ever.

  5. #5
    Master Inuyasha is offline -Hacks Neophyte
    Join Date
    Jul 2005
    Posts
    82
    Rep Power
    15

    Default

    lol ok

  6. #6
    monster356 is offline -Hacks Newbie
    Join Date
    Jun 2005
    Location
    VT
    Posts
    39
    Rep Power
    15

    Default

    Hehe I didn't needa know that muh :P No worries, you can edit your post if you want, I just needed to know why analog stick, and what directions you wanted to move. Personally, I would use the d-pad because analog stick is, idunno, i don't like it really. My game uses dpad and analog, since dpad is lighter on the thumb :)
    I can help with menu too, i've gotten compliments on my games menu's just from a low res video :lol:

    Ok anyway, heres an example movement script using analog stick (theres better ways to do this no doubt, and the area the stick has to be in to count as movement is small, so you can just change the numbers)

    Notes: -Ignore the --{ and --} i copied most of this directly from one of my scripts and i put the brackets cuz I <3 C++ so shh! :p

    -The current coordinate (x, y) of the player, lets say its...(50, 50). When you go to blit(pcXpos, pcYpos, player), it blits the image starting at the top right. It's hard to explain. Lets say my image is a square. The top right corner of the square will be right on my X/Y coordinates. Like...

    `[]

    Imagine the ` as the (x, y) coordinate, and the [] as the image.

    Code:
    -- Players current X coord
    pcXpos = 0
    -- Players current Y coord
    pcYpos = 0
    -- Show the X/Y coords to adjust the movement #'s
    screen&#58;print&#40;0, 0, tostring&#40;pcXpos&#41;, red&#41;
    screen&#58;print&#40;0, 0, tostring&#40;pcYpos&#41;, red&#41;
    
    function updateMove&#40;xPos, yPos&#41;
    --&#123;
       analogPad = Controls.read&#40;&#41;
       dx = analogPad&#58;analogX&#40;&#41;
       dy = analogPad&#58;analogY&#40;&#41;
    -- Up
       if dx > -60 and dx < 40 and dy == -128  or analogPad&#58;up&#40;&#41; then
          pcYpos = pcYpos - 2
          playerDirection = "up"
       end
    -- Left
       if dy > -25 and dy < 40 and dx == -128 or analogPad&#58;left&#40;&#41; then
          pcXpos = pcXpos - 2
          playerDirection = "left"
       end
    -- Down
       if dx > -40 and dx < 40 and dy == 127 or analogPad&#58;down&#40;&#41; then
          pcYpos = pcYpos + 2
          playerDirection = "down"
       end
    -- Right
       if dy > -35 and dy < 45 and dx == 127 or analogPad&#58;right&#40;&#41; then
          pcXpos = pcXpos + 2
          playerDirection = "right"
       end
    
       -- Check to see if player is off screen
       if pcXpos >= 440 then
          pcXpos = 430
       elseif pcXpos < 0 then
          pcXpos = 10
       end
       if pcYpos >= 160 then
          pcYpos = 150
       elseif pcYpos < 0 then
          pcYpos = 10
       end
    --&#125;
    end
    
    -- And now blit our sprite according to their current coordinates
    screen&#58;blit&#40;pcXpos, pcYpos, sprite&#41;
    Ok. That's probably really confusing. I got voted out of the game so im good for a few mins till we find another.
    so i'd be able to copy and pate this into my script right?

    EDIT: where would the code for my pic go?

  7. #7
    LordCthulu is offline Senior Member -Hacks Enthusiast
    Join Date
    Mar 2005
    Posts
    578
    Rep Power
    15

    Default

    Ok assuming everything is right (I was so out of it last night LOL) you just call updateMove, and then blit the image according to pcXpos and pcYpos.

    Like this maybe:

    while true do

    screen:blit(0, 0, background)
    updateMove()
    screen:blit(pcXpos, pcYpos, sprite)

    pad = Controls.read()

    if pad:start() then break end

    end
    Oldest psp-hacks member ever.

  8. #8
    monster356 is offline -Hacks Newbie
    Join Date
    Jun 2005
    Location
    VT
    Posts
    39
    Rep Power
    15

    Default

    Ok assuming everything is right (I was so out of it last night LOL) you just call updateMove, and then blit the image according to pcXpos and pcYpos.

    Like this maybe:

    while true do

    screen:blit(0, 0, background)
    updateMove()
    screen:blit(pcXpos, pcYpos, sprite)

    pad = Controls.read()

    if pad:start() then break end

    end
    uhhhhh

    is the code for D-pad shorter/ easier

  9. #9
    LordCthulu is offline Senior Member -Hacks Enthusiast
    Join Date
    Mar 2005
    Posts
    578
    Rep Power
    15

    Default

    Well my way of doing analog stick movement is weird but works for me.
    D-Pad is definitely easier no matter how you do it though.

    if pad:up() then
    yPos = yPos -2
    end

    just that easy ;)
    Oldest psp-hacks member ever.

  10. #10
    monster356 is offline -Hacks Newbie
    Join Date
    Jun 2005
    Location
    VT
    Posts
    39
    Rep Power
    15

    Default

    Well my way of doing analog stick movement is weird but works for me.
    D-Pad is definitely easier no matter how you do it though.

    if pad:up() then
    yPos = yPos -2
    end

    just that easy ;)
    do you think you can post the script for me?

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •