DSLua Community
Welcome, Guest. Please login or register.
May 18, 2012, 08:36:52 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  |  Shooting Game « previous next »
Pages: [1]
Author Topic: Shooting Game  (Read 3407 times)
grimmyx
New Moon
*
Posts: 4


« on: April 27, 2006, 04:38:46 PM »

Hello. I'm brand new to this forum, but I would like to make a large dent in the progress of DS Homebrew. I am moderately experienced in programming in general, and I have gotten the hang of DSLua for the most part. A bit earlier I was going to post on how to move around a sprite, but I have figured it out. Currently, my game is very dull; you can only move around that ship that comes in the example scripts folder.

My goal (or atleast my first one) is to make a small shooting game in which there are monsters on the top like this:
()  ()  ()
  ()   ()
     ()
These monsters would move back and forth. After shooting all 9 of the monsters, you would get a certain score.  As the levels ascend, I would like the monsters to move quicker, and the amount of misses you can make to decrease. If anyone is willing to partake in this 'experiment' of a game, post here so we can do this together. Ill attach my current game although it isnt really much of anything. Congratulations on created DSLua by the way.

Grimmy Grin

BTW Its 'select' to exit Cheesy

Edit : I forgot to write some of the things I need help with. I need to learn the code for collision, as well as how to make the sprites move back and forth. Next, I dont know what these '.raw' files or the '.bmp.pal' files actually do, or how to create them.
For collision, I need the game to recognize that the 'laser' coming from the ship has hit the monster. After this happens, I would like to either see an explosion, or the monster dissapear; after that, a number will be distributed to the score. Thanks Again Cheesy

* scripts.rar (1.35 KB - downloaded 161 times.)
« Last Edit: April 27, 2006, 04:46:44 PM by grimmyx » Logged
grimmyx
New Moon
*
Posts: 4


« Reply #1 on: April 27, 2006, 08:08:38 PM »

Okay.. Well I improved on my code abit, cause I was trying to figure out how to make the ship shoot a bullet. Of course, I used another ship as a bullet. If anyone can help me out and show me whats wrong, that would be fantastic. One problem right now is, when I press A, I can see the sprite overlap, then the game freezes.

* scripts.rar (2.23 KB - downloaded 148 times.)
Logged
waruwaru
Administrator
Waxing Crescent
*****
Posts: 78


« Reply #2 on: April 28, 2006, 12:59:32 AM »

Looks like your code was stuck in the while loop.  I wasn't sure what you wanted, so I made some changes.  I removed the while loop so the ship can still move while the bullet is moving.  I also added the clean up code at the bottom:
Code:
-- global vars
SCREEN_BOTTOM   = 0
SCREEN_TOP      = 1
PALETTE_SHIP    = 0
PALETTE_LASER   = 1

-- preparing screen
BGTopText = Screen.LoadTextBG()
Screen.Initialize( SCREEN_TOP, BGTopText )

-- text
BGTopText:PrintXY( 0, 0, "Press select to exit the game." )
BGTopText:PrintXY( 0, 1, "Created by GrimmyX." )

-- loading sprite pallette
Sprite.LoadPalette( SCREEN_BOTTOM, PALETTE_SHIP, "vaisseau.bmp.pal" )
Sprite.LoadPalette( SCREEN_BOTTOM, PALETTE_LASER, "vaisseau1.bmp.pal" )

-- frame strip to hold sprite
ShipFrames  = FrameStrip.Create( SCREEN_BOTTOM, 32, 32, "256" )
LaserFrames = FrameStrip.Create( SCREEN_BOTTOM, 32, 32, "256" )

-- load binary data into frame strip object
ShipFrames:LoadBin( "vaisseau.raw", 1 )
LaserFrames:LoadBin( "vaisseau1.raw", 1 )

-- init variable to move sprite around
nX      = 104
nY      = 50
nvX     = 0
nvY     = 0

-- create a sprite using frame loaded
Ship  = Sprite.Create( ShipFrames, 0, PALETTE_SHIP, nX, nY )
Laser = nil

-------------------------------------------------------------------------------
function LaserCheck()
if nvY < 1 then
Laser:Free()
    Laser = nil
end
end
-------------------------------------------------------------------------------

-- updating graphics
while true do
  Ship:MoveTo( nX, nY )

  -- moving the actual ship with keys
  if Pads.Down() then
  nY = nY + 4
  end

  if Pads.Up() then
  nY = nY - 4
  end

  if Pads.Left() then
  nX = nX - 4
  end

  if Pads.Right() then
  nX = nX + 4
  end

  -- shooting
  if ( ( Laser == nil ) and ( Pads.A() ) ) then
    nvX     = nX
    nvY     = nY
  Laser   = Sprite.Create( LaserFrames, 0, PALETTE_LASER, nvX, nvY )
  end

  -- move laser
  if ( Laser ~= nil ) then
    nvY     = nvY - 1
    Laser:MoveTo( nvX, nvY )
    LaserCheck()
  end

  -- exit when user press a key
  if Pads.Select() then
    break
  end

  -- wait for VBlank so we don't cause graphics tearing
  Screen.WaitForVBL()
end

-- clean up
if ( Laser ~= nil ) then
  Laser:Free()
end
Ship:Free()

ShipFrames:FreeAll()
LaserFrames:FreeAll()
Logged
grimmyx
New Moon
*
Posts: 4


« Reply #3 on: April 28, 2006, 01:50:47 PM »

Thanks a bunch. Thats exactly what I needed to be done Cheesy. Next part i need to do is to create moving monsters on the top, and be able to detect when they are hit. After each monster is hit I want 50 points to be given. Then on the forums or on my website, there will be a high scores list that can be submitted. I will definately need to know if that is possible to do or not. Once you run out of chances or however I make it to be, I would like to choice to submit the scores to the page if the user chooses to do. I would want the connection settings to be that of the first one from the nintendo-wifi thing if possible. Thanks again..

Grim
Edit: I also need to learn how to allow the 'laser' sprite to go to the top screen if possible.
« Last Edit: April 28, 2006, 02:27:54 PM by grimmyx » Logged
angor
Waxing Crescent
**
Posts: 45


WWW
« Reply #4 on: April 28, 2006, 02:36:14 PM »

As far as i know you can not move one sprite from one screen to another.

The trick is to have 2 sprites (i.e laser/bullet) in each screen and only show one at a time. If you make one disapear when it reaches the screen border and the other appear at the same time, the illusion of being the same sprite crossing from one screeen to the other is created.

Abgor
Logged
grimmyx
New Moon
*
Posts: 4


« Reply #5 on: April 28, 2006, 03:10:37 PM »

Code:

-------------------------------------------------------------------------------
function ScoreCheck()
      xscore = xscore + total
      total = xscore + 50
     
end
-------------------------------------------------------------------------------

-- global vars
SCREEN_BOTTOM   = 0
SCREEN_TOP      = 1
PALETTE_SHIP    = 0
PALETTE_LASER   = 1
PALETTE_MONSTER = 2

-- preparing screen
BGTopText = Screen.LoadTextBG()
Screen.Initialize( SCREEN_TOP, BGTopText )

-- text
BGTopText:PrintXY( 0, 0, "Press select to exit the game." )
BGTopText:PrintXY( 0, 1, "Created by GrimmyX." )
BGTopText:PrintXY( 0, 2, "Current Score: " )

-- loading sprite pallette
Sprite.LoadPalette( SCREEN_BOTTOM, PALETTE_SHIP, "vaisseau.bmp.pal" )
Sprite.LoadPalette( SCREEN_BOTTOM, PALETTE_LASER, "vaisseau1.bmp.pal" )
Sprite.LoadPalette( SCREEN_TOP, PALETTE_MONSTER, "vaisseau1.bmp.pal" )

-- frame strip to hold sprite
ShipFrames  = FrameStrip.Create( SCREEN_BOTTOM, 32, 32, "256" )
LaserFrames = FrameStrip.Create( SCREEN_BOTTOM, 32, 32, "256" )
MonsterFrames = FrameStrip.Create( SCREEN_TOP, 32, 32, "256" )

-- load binary data into frame strip object
ShipFrames:LoadBin( "vaisseau.raw", 1 )
LaserFrames:LoadBin( "vaisseau1.raw", 1 )
MonsterFrames:LoadBin( "vaisseau1.raw", 1 )

-- init variable to move sprite around
nX      = 104
nY      = 50
nvX     = 0
nvY     = 0
nmX     = 104
nmY     = 50


-- create a sprite using frame loaded
Ship  = Sprite.Create( ShipFrames, 0, PALETTE_SHIP, nX, nY )
Monster = Sprite.Create( MonsterFrames, 0, PALETTE_MONSTER, nmX, nmY )
Laser = nil

-------------------------------------------------------------------------------
function LaserCheck()
if nvY < 1 then
Laser:Free()
    Laser = nil
end
end
-------------------------------------------------------------------------------


-- updating graphics
while true do
  Ship:MoveTo( nX, nY )
 
  -- moving the actual ship with keys
  if Pads.Down() then
  nY = nY + 4
  end

  if Pads.Up() then
  nY = nY - 4
  end

  if Pads.Left() then
  nX = nX - 4
  end

  if Pads.Right() then
  nX = nX + 4
  end

  -- shooting
  if ( ( Laser == nil ) and ( Pads.A() ) ) then
    nvX     = nX
    nvY     = nY
  Laser   = Sprite.Create( LaserFrames, 0, PALETTE_LASER, nvX, nvY )
  end

  -- move laser
  if ( Laser ~= nil ) then
    nvY     = nvY - 3
    Laser:MoveTo( nvX, nvY )
    LaserCheck()
      if ( ( nvX == nmX ) and ( nvY == nmY ) ) then
        Monster:Free()
        ScoreCheck()               
      end
  end

  -- move monster
     
  -- exit when user press a key
  if Pads.Select() then
    break
  end

  -- wait for VBlank so we don't cause graphics tearing
  Screen.WaitForVBL()
end

-- clean up
if ( Laser ~= nil ) then
  Laser:Free()
end
Ship:Free()

ShipFrames:FreeAll()
LaserFrames:FreeAll()
MonsterFrames:FreeAll()


I just updated it a bit, but i cannot figure out how to update score when the 'monster' is shot.
Logged
daltonlaffs
First Quarter
***
Posts: 189


Freaking Insane


WWW
« Reply #6 on: May 03, 2006, 06:04:04 PM »

As far as i know you can not move one sprite from one screen to another.

The trick is to have 2 sprites (i.e laser/bullet) in each screen and only show one at a time. If you make one disapear when it reaches the screen border and the other appear at the same time, the illusion of being the same sprite crossing from one screeen to the other is created.

Abgor

There is a way to do that like this. Let's call the bullet sprite 'BLT1', and pretend it was created in 100*100 on the bottom screen:

while true do
BLT.Y() = BLT.Y() - 10
if BLT.Y() == 0 then
BLT1:Free()
BLTP2 = 1
Sprite.LoadPalette( SCREEN_TOP, BLTP2, "Bullet.bmp.pal" )
FRAMESTRIP  = FrameStrip.Create( SCREEN_TOP, 16, 16, "256" )
FRAMESTRIP:LoadBin( "Bullet.raw", 1 )
BLT2 = Sprite.Create( FRAMESTRIP, 0, BLTP2, X, Y )
end

Before the sprite is created, either replace X and Y with the X and Y of where you want it to start on the top screen, or define X and Y with intervals, like this:

X = (X value here)
Y = (Y value here)

OK. EDIT: oops, forgot to close the if. *EDITS* ok. EDIT 2: oops again! I put in X in the place of Y *FIX*
« Last Edit: May 03, 2006, 06:07:26 PM by daltonlaffs » Logged

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



^^ That works, I SWEAR! ^^
Pages: [1]
« previous next »
    Jump to: