Page 2 of 2 FirstFirst 1 2
Results 11 to 17 of 17

Thread: Movement Script

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

    Default

    Heres an edited version of the one I already posted.

    Code:
    -- Players current X coord
    pcXpos = 0
    -- Players current Y coord
    pcYpos = 0
    -- Show the X/Y coords to adjust the movement #'s
    screen:print(0, 0, tostring(pcXpos), red)
    screen:print(0, 0, tostring(pcYpos), red)
    
    function updateMove(xPos, yPos)
    --{
       analogPad = Controls.read()
    -- Up
       if analogPad:up() then
          pcYpos = pcYpos - 2
          playerDirection = "up"
       end
    -- Left
       if analogPad:left() then
          pcXpos = pcXpos - 2
          playerDirection = "left"
       end
    -- Down
       if analogPad:down() then
          pcYpos = pcYpos + 2
          playerDirection = "down"
       end
    -- Right
       if analogPad:right() 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;
    I just realized in the version I had posted, accepted the analog stick, AND the dpad for movement. This accepts Dpad only, and if you hit it once moves you 2 pixels in that direction, or if you hold it moves you continuosly in that direction.
    playerDirection="dir" is for me, but I left it just in case you wanted to use it.

    Oldest psp-hacks member ever.

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

    Default

    Heres an edited version of the one I already posted.

    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;
    -- Up
       if analogPad&#58;up&#40;&#41; then
          pcYpos = pcYpos - 2
          playerDirection = "up"
       end
    -- Left
       if analogPad&#58;left&#40;&#41; then
          pcXpos = pcXpos - 2
          playerDirection = "left"
       end
    -- Down
       if analogPad&#58;down&#40;&#41; then
          pcYpos = pcYpos + 2
          playerDirection = "down"
       end
    -- Right
       if 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;
    I just realized in the version I had posted, accepted the analog stick, AND the dpad for movement. This accepts Dpad only, and if you hit it once moves you 2 pixels in that direction, or if you hold it moves you continuosly in that direction.
    playerDirection="dir" is for me, but I left it just in case you wanted to use it.
    so before all that code i could put in:

    sprite = Image.load("sprite.png")

    and that pic would work for the sprite

    or would i have to add additional code to get it to work?

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

    Default

    sprite = Image.load("your_sprite.png")
    Yup, just make sure your_sprite.png is the character figure your wanting to move. The end of the script checks to see if the current coord of the player is on the edge of the screen (with an exception to the bottom and right borders, im not going to go into it probably too complicated for ya) so if you try to go offscreen it pops you back ~10 pixels from the edge.

    Just try it, if it doesn't work lemme know, I might be missing something.

    Quick edit, just realized the off-screen check checks to see around 200 pixels down on the Y axis; because thats where my on-screen HUD cuts off.
    Oldest psp-hacks member ever.

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

    Default

    sprite = Image.load("your_sprite.png")
    Yup, just make sure your_sprite.png is the character figure your wanting to move. The end of the script checks to see if the current coord of the player is on the edge of the screen (with an exception to the bottom and right borders, im not going to go into it probably too complicated for ya) so if you try to go offscreen it pops you back ~10 pixels from the edge.

    Just try it, if it doesn't work lemme know, I might be missing something.

    Quick edit, just realized the off-screen check checks to see around 200 pixels down on the Y axis; because thats where my on-screen HUD cuts off.
    i'll try it out!

    and ok

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

    Default

    it's not working for me
    i had to edit it 4 like times

    after i fixed all the errors, i booted it up andf it brought me to the error screen but nothing was there except, 'press start to restart'

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

    Default

    Do you have AIM? If so msg me CDGK69GoHaN
    Otherwise what about msn/yahoo?
    Oldest psp-hacks member ever.

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

    Default

    And then, in a booming voice, he said...

    LOCKED!!!!
    Oldest psp-hacks member ever.

Page 2 of 2 FirstFirst 1 2

Posting Permissions

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