DSLua Community
Welcome, Guest. Please login or register.
May 18, 2012, 09:33:57 PM
1371 Posts in 262 Topics by 33109 Members
Latest Member: Limewire Download
DSLua Community  |  DSLua - Best scripting language for Nintendo DS  |  Need Help?  |  Need help, user-controlled sprite « previous next »
Pages: [1]
Author Topic: Need help, user-controlled sprite  (Read 2137 times)
CPU_Smarts
Waxing Crescent
**
Posts: 15


« on: September 06, 2006, 06:48:53 PM »

Ok as the topic says, im having a problem making a sprite that can be controlled by the user, heres the code:

Code:
function Player1Controls()
if Pads.Up() then
Player1:MoveTo( x, y+1 )
end

if Pads.Down() then
Player1:MoveTo( x, y-1 )
end
end

all i have is up  and down for now, but i will add more later once i get these two working
Logged
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #1 on: September 06, 2006, 06:53:44 PM »

x and y are always remaining the same values in your code. You need something like this:

Code:
function Player1Controls()
if Pads.Up() then
y = y - 1
Player1:MoveTo( x, y )
end

if Pads.Down() then
y = y + 1
Player1:MoveTo( x, y )
end
end

And also notice that I made the bottom one +1 and the top one -1 because you had the two switched. (Unless you wanted inverted controls)
Logged
CPU_Smarts
Waxing Crescent
**
Posts: 15


« Reply #2 on: September 06, 2006, 10:20:33 PM »

Hm, well i put that in my script but its not working Sad ill keep messing around with it though
Logged
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #3 on: September 06, 2006, 10:35:18 PM »

Well you didn't say what the problem was. What happens when you try to run it?
Logged
CPU_Smarts
Waxing Crescent
**
Posts: 15


« Reply #4 on: September 06, 2006, 10:56:23 PM »

heheh whoops, well when i click start and go into the actual game, the sprite and background load, but i cant get the sprite to move up or down (im not too worried about getting the animation of it working right now)

um...well thats pretty much it...
Logged
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #5 on: September 06, 2006, 11:08:38 PM »

You'll have to post more code
Logged
CPU_Smarts
Waxing Crescent
**
Posts: 15


« Reply #6 on: September 06, 2006, 11:28:25 PM »

Here, i just decided to post my entire code (well the game part of it)  because im really not sure where the problem is:

Code:
------------------- MAIN GAME ------------------------------------

-- *Whew* time to start it...I'm kind of nervous ( just a reminder of what I was thinking when I started this ;))

-- More Variables
PALETTE_PLAYER1 = 0
PALETTE_BOX1 = 1
PALETTE_BOX2 = 2

-- Load Sprites...
function LoadSprites()
-- Player 1
Sprite.LoadPalette( SCREEN_BOTTOM, PALETTE_PLAYER1, "Player1.bmp.pal" )
Player1Frames = FrameStrip.Create( SCREEN_BOTTOM, 32, 32, "256" )
Player1Frames:LoadBin( "Player1.raw", 16 )
Player1 = Sprite.Create( Player1Frames, 0, PALETTE_PLAYER1, 50, 150 )
-- Box 1
Sprite.LoadPalette( SCREEN_BOTTOM, PALETTE_BOX1, "Box1.bmp.pal" )
Box1Frames = FrameStrip.Create( SCREEN_BOTTOM, 64, 64, "256" )
Box1Frames:LoadBin( "Box1.raw", 1 )
Box1 = Sprite.Create( Box1Frames, 0, PALETTE_BOX1, 90, 120 )
-- Box 2
Sprite.LoadPalette( SCREEN_BOTTOM, PALETTE_BOX2, "Box2.bmp.pal" )
Box2Frames = FrameStrip.Create( SCREEN_BOTTOM, 32, 32, "256" )
Box2Frames:LoadBin( "Box2.raw", 1 )
Box2 = Sprite.Create( Box2Frames, 0, PALETTE_BOX2, 58, 88 )
end

-- Load Map
function LoadGameMap()
BGBottomMap:LoadPalette( "Aztec.bmp.pal" )
BGBottomMap:LoadTiles( "Aztec.raw", 256 )
BGBottomMap:LoadMap( "Aztec.map", ( 256 / 8 ), ( 192 / 8 ) )
Screen.Initialize( SCREEN_BOTTOM, BGBottomMap )
end

-- Player 1 Controls *shudders*



function Player1Controls()

-- Check Keys
while true do

if Pads.Up() then
y = y - 15
Player1:MoveTo( x, y )
end

if Pads.Down() then
y = y + 15
Player1:MoveTo( x, y )
end
end

end


-- Main Game function
function MainGame()
LoadGameMap()
LoadSprites()
Player1Controls()
end

SplashScreen()
DSLua.WaitForAnyKey()
Logged
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #7 on: September 07, 2006, 12:21:00 AM »

I tried it, and it worked for me (after using my own sprites from Skydiver since I don't have yours, adding x=50 and y=150, adding BGBottomMap = Screen.LoadTileBG, adding SCREEN_TOP = 1 and SCREEN_BOTTOM = 0)

Maybe you should put all your files in a zip file and upload it here...
Logged
Pages: [1]
« previous next »
    Jump to: