DSLua Community
Welcome, Guest. Please login or register.
May 18, 2012, 09:25:22 PM
1371 Posts in 262 Topics by 33109 Members
Latest Member: Limewire Download
DSLua Community  |  DSLua - Best scripting language for Nintendo DS  |  Home-brew/Hacks/Games/Projects  |  Skydiver « previous next »
Pages: [1] 2
Author Topic: Skydiver  (Read 8539 times)
Jeremysr
First Quarter
***
Posts: 215



WWW
« on: July 24, 2006, 05:03:48 PM »

Skydiver is a "text-based" game, because I have no idea how to use graphics/sprites etc. Anyway, this is how the game works. A plane scrolls across the top screen at the very top, and you press the A button (or tap the touchscreen maybe) to drop the skydiver. Your goal is to drop him into the target, which is supposed to be a pool of water. When the difficulty increases, the plane will go faster, the target will get smaller, and more.

This is the code for the entire first level.

Code:
-- Set up screens
SCREEN_TOP = 1
SCREEN_BOTTOM = 0
BGTopText = Screen.LoadTextBG()
BGBotText = Screen.LoadTextBG()
Screen.Initialize( SCREEN_TOP, BGTopText )
Screen.Initialize( SCREEN_BOTTOM, BGBotText )

-- Level1
-- Set level variables. (to easiest possible variables)
level = 1
planeDirection = "RIGHT"
planeX = 2
planeY = 1
planeSpeed = "SLOW"
targetX = 6
targetY = 24
targetWidth = 10
-- Draw the target (a pool of water)
for targetDraw=targetX,targetX+targetWidth do
BGBotText:printXY( targetDraw, targetY, "X" )
end
-- Start the game loop
win = 0    -- win = 1 when player wins the level
lose = 0   -- lose = 1 when player loees the level
while win = 0 and lose = 0 do
BGTopText:printXY( planeX, planeY, " " ) -- Erases the current plane before drawing it again
if planeDirection == "RIGHT" and planeX < 23 then planeX = planeX + 1 -- If the plane is not at the end of the screen, move it to the right
if planeDirection == "LEFT" and planeX > 1 then planeX = planeX - 1
if planeDirection == "RIGHT" and planeX == 23 then planeX = 1            -- If it's at the end of the screen, start again from the other side of the screen
if planeDirection == "LEFT" and planeX == 1 then planeX = 23

-- Draw the plane with the new coordinates
if planeDirection == "RIGHT" then BGTopText:printXY( planeX, planeY, ">" )
if planeDirection == "LEFT" then BGTopText:printXY( planeX, planeY, "<" )

-- Delay loop: The more delay there is, the slower the plane will travel.
if planeSpeed == "SLOW" then delay = 2000
if planeSpeed == "NORMAL" then delay = 1500
if planeSpeed == "FAST" then delay = 1000
if planeSpeed == "VERYFAST" then delay = 500
for delayloop=1,delay do
end

-- Did they top the screen or press the A button?
if Stylus.Down() or Pads.A() then
diverX = planeX
diverY = planeY  -- The diver starts diving wherever the plane is, of course.
-- Start a loop that makes the diver go down 1 each increment
while diverY < 24
BGTopText:printXY( diverX,diverY," " )
diverY = diverY + 1
BGTopText:printXY( diverX,diverY,"*" )
-- Delay loop
for delayloop=1,delay do
end
end
-- That got the diver to the bottom of the top screen, now he will go to the bottom screen to continue falling.
-- First we erase him from the top screen
BGTopText:printXY( diverX,diverY," " )
diverY = 1
-- Now go into a loop until he falls either to the ground or the target.
while diverY < targetY + 1
BGBotText:printXY( diverX,diverY," " )
diverY = diverY + 1
BGBotText:printXY( diverX,diverY,"*" )
-- Delay loop
for delayloop=1,delay do
end
end
-- Now we determine whether he hit the target or hit the ground (won or lost)
for checkwin=targetX,targetX+targetWidth do
if diverX = checkwin then win = 1
end
if win = 0 then lose = 1
-- Remember, the whole loop will discontinue once either "win" or "lose" equal "1"
end
end

-- Now clear the screen. This code will be executed after they've either won or lost the dive.
BGBotText:Clear()
BGTopText:Clear()

-- Now display the win/lose message
if win = 1 then BGBotText:print( "You won!" )
if lose = 1 then BGBotText:print( "You died! You have lost!" )
BGBotText:printXY( 1,5,"Press any key to quit." )

-- Wait for them to press a key, then exit.
DSLua.WaitForAnyKey()

Edit: Fixed the for..do..loop to for..do..end. I am too used to BASIC...
« Last Edit: July 24, 2006, 05:41:42 PM by Jeremysr » Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #1 on: July 27, 2006, 07:04:15 AM »

Hm... I copied all that text and saved it to a script, but when I run it, i get an error. Fix!!!

EDIT: Just so you know, you have broken a rule of DSLua scripting. This may have lead to some of the errors. You see where you used if then thingys to compare values? YALL MESSED UP BAD!

Example:

You did:

Code:
if win = 1 then BGBotText:print( "You won!" )
if lose = 1 then BGBotText:print( "You died! You have lost!" )

I FIX TO:

Code:
if win == 1 then BGBotText:print( "You won!" )
if lose == 1 then BGBotText:print( "You died! You have lost!" )

Don't you get it now? It's like this. I'll explain. When you are assigning variables values, like let's say you wanted A to equal 1, you'd type A = 1. But if you are COMPARING VALUES, you must use ==! Like if A == 1 then break.

You made the comparing mistake everywhere. FIX IT!!!!!!!!!!!!
« Last Edit: July 27, 2006, 07:09:59 AM by daltonlaffs » Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #2 on: July 27, 2006, 07:40:07 PM »

Yeah, I know the comparison/assignation operators from PHP and C++. I fixed all of them, and some other errors (I finally found out how to see which line the error was on). But I think I'm doing something wrong with my for loops. Can someone show me how for loops work in DSLua? Nevermind, it seems to be a problem with
Code:
BGBotText:printXY( targetX, targetY, "X" )
« Last Edit: July 27, 2006, 10:21:28 PM by Jeremysr » Logged
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #3 on: July 27, 2006, 08:19:08 PM »

Ok, it's all fixed! (printXY had to be changed to PrintXY). I've attached Skydiver 1.0 to this post. It has 10 levels. Tap the touch screen to drop the diver. You only have 1 life..

I found a nice little .mod file to play as background music. Unfortunately it keeps slowing down and speeding up depending on how much code is being executed while the music is playing. Sad  I'm hoping that this won't happen once I run this on my actual DS.

* skydiver.zip (40.93 KB - downloaded 165 times.)
« Last Edit: July 28, 2006, 02:22:19 AM by Jeremysr » Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #4 on: July 28, 2006, 08:42:32 AM »

WOW. It's even hard! I couldn't get to level 10. NICE JOB for a first script! You have a bright future!

When you learn how to use sprites, I hope to see a full version!
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #5 on: July 28, 2006, 04:27:50 PM »

Thanks Smiley

I don't know how to use gfx2gba Huh
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #6 on: July 29, 2006, 07:19:41 AM »

I don't know how to use gfx2gba Huh

Lol... ok. I'm here to help. First of all, you have to use a 256 color bitmap. If you use Paint, you can change format to 256 color. When you get the bitmap to a 256 color bitmap, you're almost ready. Now make sure your image is 16*16, 32*32, 64*64, or any combination of the three. In pixels, that is.

Now take your finished bitmap and copy it to bin. Then go to Start-->Accessories-->Command Prompt. Now type this:

cd (yourpathhere)

Where (yourpathhere) is where you put your path to the bin folder. Then press Enter and type:

gfx2gba -p(Palettenamehere) -t8 (bitmapnamehere)

Where (Palettenamehere) is what you wanna call the palette file (i reccommend putting .pal at the end to get the right format) and (bitmapnamehere) is the name of the bitmap you are converting.

Doing that will generate a .pal file and a .raw file. You named the .pal file, but the .raw file automatically names itself after the bitmap it was generated by, without the .bmp extension. It uses a .raw extension.

Now you can use the .pal and .raw files in your code! Enjoy!  Grin
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #7 on: July 29, 2006, 06:05:06 PM »

Yay, thanks!!! Grin I should have the full version done in a few days!

By the way, if I want a big 256x192 background for both screens, how do I do that? Combination of 64x64 bmp's? And how do I make the sprite transparent over the background?
« Last Edit: July 29, 2006, 06:44:06 PM by Jeremysr » Logged
Zhen
Waxing Crescent
**
Posts: 45


WWW
« Reply #8 on: July 30, 2006, 06:16:48 AM »

By the way, if I want a big 256x192 background for both screens, how do I do that? Combination of 64x64 bmp's?

It's easy. You have a bmp with 256 colours and 256x192 pixels. With this command you get the data for lua:

Code:
gfx2gba -m -ppalette.pal -t8 background.bmp

The -m parameter is to get map data.

Move the palette.pal, background.map and background.raw to the script folder. Now the code to load the bitmap in the background in both screens.

Code:
SCREEN_BOTTOM   = 0
SCREEN_TOP      = 1

BGBotMap = nil

BGBotMap = Screen.LoadTileBG()

BGBotMap:LoadPalette( "palette.pal" )
BGBotMap:LoadTiles( "background.raw", 256 )
BGBotMap:LoadMap( "background.map", (256 / 8 ), ( 192 / 8 ) )

Screen.Initialize( SCREEN_BOTTOM, BGBotMap )

BGTopMap = nil

BGTopMap = Screen.LoadTileBG()

BGTopMap:LoadPalette( "palette.pal" )
BGTopMap:LoadTiles( "background.raw", 256 )
BGTopMap:LoadMap( "background.map", (256 / 8 ), ( 192 / 8 ) )

Screen.Initialize( SCREEN_TOP, BGTopMap )

And how do I make the sprite transparent over the background?

The first colour in the sprite palette is the transparent one.

Zhen
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #9 on: July 30, 2006, 08:43:16 AM »

The first colour in the sprite palette is the transparent one.

And if you use Paint like I do, the first palette color is black. Just so ya know  Grin
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #10 on: August 08, 2006, 02:54:56 AM »

Hmm, I just tried it on my other computer and it went REALLY fast...I guess I should use the DS clock for delay. (It counts to 1500 or something every iteration). But then it won't work in Dualis because its clock doesn't work, I think.

Somehow I lost my newer version of skydiver (full version) and so it'll be a while before it will be ready. Lips sealed
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #11 on: August 17, 2006, 10:08:32 AM »

Well, jeremysr, I tried your Skydiver on regular hardware now. It moves at a fine speed. No need to use DS clock. Yeah. I have EZFlash III now, along with my old WifiMe card. IT WORKZ! Finally, I can hardware test stuff!

And the DS clock doesn't work in Dualis. Sorry to disappoint you  Undecided
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #12 on: August 17, 2006, 07:18:29 PM »

Yeah, I knew it doesn't work. But it's weird how the little DS goes the same speed as my fast computer. Anyway, I somehow lost all the code for Skydiver 2 or whatever it could be called, the one with sprites...

And I should get my passcard3 in a couple weeks.
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #13 on: August 18, 2006, 08:43:29 AM »

The reason a little DS can go as fast as your computer is that the DS has NO background processes running. It only runs the game it is supposed to be running. If you are using Windows XP, press Ctrl+Alt+Delete and go to the Processes tab. THAT is how many other processes Windows XP uses. Lol...

And I just remembered to tell you, the music is PERFECT in hardware. No speed-ups or slowdowns. Same with my RPG Maker DS... hmm...  Cheesy
Logged

Code:
-- Bored? Read code line below.
-- Bored? Read code line above.



^^ That works, I SWEAR! ^^
Jeremysr
First Quarter
***
Posts: 215



WWW
« Reply #14 on: August 25, 2006, 08:07:29 PM »

Ok...here's skydiver 2! With sprites! After you dive you have to press any key to continue. Either to the next level (if you won) or to the main menu (if you lost, or won level 10 (beat the whole game)). I wish it was possible to output text (BGBotText) while in "sprite mode" or whatever...or is it possible? When I tried, all that showed up was a bunch of black rectangles where the text should've been.

http://www.bio-gaming.com/jeremy/skydiver2.zip

The only improvements are the graphics and the titlescreen.
Logged
Pages: [1] 2
« previous next »
    Jump to: