(Final)8-Bit and 16c Backgrounds - Rotation

Learn to use DS Game Maker by Example!

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Commodore » February 27th, 2012, 10:08 pm

Thanks, Foxi. I didn't know that applied to backgrounds too!
EDIT:
How do you use backgrounds for Mode7?
Last edited by Commodore on February 27th, 2012, 10:42 pm, edited 1 time in total.
"Every puzzle has an answer." - Professor Layton
_______________________________________________________________________
December 17, 2012 - MegaMan 25th Anniversary
_______________________________________________________________________
Member of Memefefe's Squad
User avatar
Commodore
 
Posts: 557
Joined: August 10th, 2011, 4:39 pm

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby YoshiInAVoid » February 27th, 2012, 10:34 pm

Foxi4 wrote:
Commodore wrote:Can't you init Mode7 in one of the other layers and have the "horizon" background behind it?

Once you could, on Layer 2, but probably due to changes in libnds this option is no longer available. It would be useless anyways - as I said before, the Mode7 background goes from point A to infinity forwards and backwards (if you set it to wrap, and you kinda have to or else it will float in black space) so it would cover the "horizon". You need to paste the horizon "over" it to create this illusion.

The results I got when I used mode7 about two years ago was this (tried to port Mario Kart SNES to DS):
Mode7MarioKart.nds
(386.06 KiB) Downloaded 44 times

MK.png
MK.png (10.47 KiB) Viewed 1998 times

Using this code:
Code: Select all
int RacingEngine(void) {

   PA_Init();
   PA_InitVBL();
   
   PA_InitText(1, 0);
   
   PA_SetVideoMode(0, 2);
   PA_SetVideoMode(1, 2);
   
   if (CurrentTrack == 0) {
      PA_LoadPAGfxRotBg(0, 3, DonutPlains, 0);
      PA_LoadPAGfxRotBg(1, 3, DonutPlains, 1);
   }
   if (CurrentTrack == 1) {
      PA_LoadPAGfxRotBg(0, 3, ChocoIsland, 0);
      PA_LoadPAGfxRotBg(1, 3, ChocoIsland, 1);
   }
         
   PA_InitMode7(3);

   PA_LoadSpritePal(0, 0, (void*)Mario_Pal);
   PA_CreateSprite(0, 0, (void*)Mario_Sprite, OBJ_SIZE_64X64, 1, 0, 128-32, 80);

   PA_LoadSpritePal(1, 0, (void*)MarioIcon_Pal);
   PA_CreateSprite(1, 0, (void*)MarioIcon_Sprite, OBJ_SIZE_32X32, 1, 0, 112, 32);

   PA_LoadSpritePal(0, 1, (void*)LapCounter_Pal);
   PA_CreateSprite(0, 1, (void*)LapCounter_Sprite, OBJ_SIZE_64X64, 1, 1, 16, 32);

   u8 Anim = 0;
   u16 Angle = 0;
   u16 Height = 8192;
   int Speed = 0<<8;
   int LapCounterX = 16<<8;
   int LapCounterY = 32<<8;
   int LapCounterAngle = 0;
   int LapCounterSin = 0;
   int LapCounterCos = 0;
   int LapCounterTimer = 0;

   bool hasFaded = false;
   int Brightness = -32;

   //Editables

   int MaxSpeed = 512;
   int Acceleration = 24;
   int DeAcceleration = 32;
   int LapCounterAcceleration = 16;

   //Start at the finish line depending on where it is on the track
   if (CurrentTrack == 0) {
      mode7cam_x = 128<<8;
      mode7cam_z = 538<<8;
   }
   if (CurrentTrack == 1) {
      mode7cam_x = 894<<8;
      mode7cam_z = 587<<8;
   }

   while (1) {

      //Lap counter circle movement
      LapCounterAngle = LapCounterAngle+6;
      if ((LapCounterTimer/60) < 2) LapCounterCos = PA_Cos(LapCounterAngle);
      LapCounterSin = PA_Sin(LapCounterAngle);
      //LapCounterX = LapCounterX+LapCounterCos;
      //LapCounterY = LapCounterY-LapCounterSin;
      PA_SetSpriteXY(0, 1, LapCounterX>>8, LapCounterY>>8);
      
      //Lap counter countdown
      if ((LapCounterTimer/60) < 2) {
         LapCounterTimer = LapCounterTimer+1;
         } else {
         LapCounterCos -= LapCounterAcceleration;
         if ((LapCounterX>>8) < -64) LapCounterCos = 0;
         
      }

      LapCounterX = LapCounterX+LapCounterCos;
      LapCounterY = LapCounterY-LapCounterSin;

      PA_SetSpriteAnim(0, 1, LapCounterTimer/60);

      if (!hasFaded) {
         Brightness = Brightness+1;
         PA_SetBrightness(0, Brightness);
         PA_SetBrightness(1, Brightness);
         if (Brightness == 0) {
            hasFaded = true;
         }
      }

      //Mario Animation
      if (Pad.Held.Left || Pad.Held.Right) {
         if (Anim == 0) {
            PA_StartSpriteAnim(0, 0, 0, 3, 12);
            Anim = 1;
         }
         if (PA_GetSpriteAnimFrame(0, 0) >= 3) {
            PA_SpriteAnimPause(0, 0, 1);
            PA_SetSpriteAnimFrame(0, 0, 3);
         }
         } else {
         if (Anim == 1) {
            PA_StartSpriteAnim(0, 0, 3, 6, 12);
            Anim = 0;
         }
         if (PA_GetSpriteAnimFrame(0, 0) >= 6) {
            PA_SpriteAnimPause(0, 0, 1);
            PA_SetSpriteAnimFrame(0, 0, 6);
         }
      }
      if (Pad.Held.Left) PA_SetSpriteHflip(0, 0, 1);
      if (Pad.Held.Right) PA_SetSpriteHflip(0, 0, 0);

      //Top Screen
      PA_SetBgRot(1, 3, (mode7cam_x>>8), (mode7cam_z>>8), 128, 96, Angle, 256);
      
      // Change the angle
      if (Pad.Held.A && Pad.Held.Right) Angle += (Speed>>8);
      if (Pad.Held.A && Pad.Held.Left) Angle += -(Speed>>8);
      if (Pad.Held.B && Pad.Held.Right) Angle += -(Speed>>8);
      if (Pad.Held.B && Pad.Held.Left) Angle += (Speed>>8);

      Angle &= 511;
      PA_Mode7Angle(Angle);
   
      // Move Forward/backward
      if (PA_GetSpriteAnimFrame(0, 1) >= 2) {
         if (Pad.Held.A) Speed=Speed+Acceleration;
         if (Pad.Held.B) Speed=Speed-Acceleration;
         if ((!Pad.Held.A) && (!Pad.Held.B) && Speed > 0) Speed=Speed-DeAcceleration;
         if ((!Pad.Held.A) && (!Pad.Held.B) && Speed < 0) Speed=Speed+DeAcceleration;
         if ((Speed) > MaxSpeed) Speed = MaxSpeed;
         if ((Speed) < -MaxSpeed) Speed = -MaxSpeed;
      }
      PA_Mode7MoveForwardBack(Speed>>8);

      PA_Mode7Height(Height);
   
      PA_WaitForVBL();
   }
   
   return 0;
}

I know, it's a complete mess, I did it I think 2 years ago and I have improved my programming a lot.

The reason that I gave up was because of these three limits:

-Can't put mode7 on the top screen,

-Couldn't figure out how to put mountains and clouds behind the track,

-The "PA_EasyBgGetPixelCol" function doesn't work with a "rot bg" (the top screen) so there is no collision detection.

Could you perhaps post some theoretical code for loading behind the track? I would really like to know how to do this so I can try and make a very simple FPS engine.
Sorry, Jack, YoshiInAVoid's back!

I'm the original; I'll take your breath away! This fall, YoshiInAVoid rules! Did you miss me, Andy? I sure missed you!

Keep an eye out for me.
YoshiInAVoid
 
Posts: 1985
Joined: December 30th, 2010, 11:53 am
Location: England

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Foxi4 » February 27th, 2012, 11:02 pm

YoshiInAVoid wrote:-Can't put mode7 on the top screen,

You can. In fact, you can have Mode7 plotted on both screens at the same time - change the Video Mode on the top screen.
-Couldn't figure out how to put mountains and clouds behind the track,

Overlay on a higher layer (1) for the sky and clouds + some alpha to make the blend look nice, wrap-around on the track so that magenta isn't visible. Mountains on layer (2), same rule applies.
-The "PA_EasyBgGetPixelCol" function doesn't work with a "rot bg" (the top screen) so there is no collision detection.
Plot bumper objects along the track or use tile-based collision. ;)

Could you perhaps post some theoretical code for loading behind the track? I would really like to know how to do this so I can try and make a very simple FPS engine.

It's impossible to load anything behind the track, issues like this have to be resolved with the relation between distance and zoom. It's a hardware limitation that you can't do anything about - Layer 3 is the bottom-most one and even if you placed your Mode7 BG on Layer 3, you still wouldn't be able to see anything behind it as it covers the whole screen. The only thing you can do is to create a slowly-blending background and placing it on-top.

By the way, that's pretty nice! Looks neato. ;)
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1119
Joined: December 31st, 2010, 3:25 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Commodore » February 27th, 2012, 11:13 pm

How do I use a different background than the one you used, Foxi? Also, how do I make the sprite not black?
"Every puzzle has an answer." - Professor Layton
_______________________________________________________________________
December 17, 2012 - MegaMan 25th Anniversary
_______________________________________________________________________
Member of Memefefe's Squad
User avatar
Commodore
 
Posts: 557
Joined: August 10th, 2011, 4:39 pm

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Foxi4 » February 28th, 2012, 8:36 pm

1. Use PAGfx (in Palib's tools section) to convert a bitmap (sizes divisible by 256). You will need a RotMap.
2. Assign a palette to the sprite - if you just spawned a DSGM sprite then it has no palette assigned (you re-setted PAlib afterall).
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1119
Joined: December 31st, 2010, 3:25 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Commodore » February 28th, 2012, 9:54 pm

How do I assign a palette?
"Every puzzle has an answer." - Professor Layton
_______________________________________________________________________
December 17, 2012 - MegaMan 25th Anniversary
_______________________________________________________________________
Member of Memefefe's Squad
User avatar
Commodore
 
Posts: 557
Joined: August 10th, 2011, 4:39 pm

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Foxi4 » February 28th, 2012, 11:27 pm

http://palib.info/Doc/PAlibDoc%20Eng/gr ... e.html#ga6

and then...

http://palib.info/Doc/PAlibDoc%20Eng/gr ... .html#ga47

I strongly suggest looking through original PAlib examples for more help when it comes to creating sprites and using palettes. ;) Alternatively, have a look at my NitroSprites.h example - it's also quite straight-forward.
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1119
Joined: December 31st, 2010, 3:25 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Commodore » February 29th, 2012, 1:21 pm

I just realizid that I don't know how to make a RotMap. How?
@Yoshi,
I would like to see the FPS engine when it's finished.
"Every puzzle has an answer." - Professor Layton
_______________________________________________________________________
December 17, 2012 - MegaMan 25th Anniversary
_______________________________________________________________________
Member of Memefefe's Squad
User avatar
Commodore
 
Posts: 557
Joined: August 10th, 2011, 4:39 pm

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Foxi4 » February 29th, 2012, 5:49 pm

PAGfx -> Backgrounds tab -> Load a BMP that has a correct size (divisible by 256) -> Select RotBG as the Type -> Convert.
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1119
Joined: December 31st, 2010, 3:25 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Buck_7 » February 29th, 2012, 5:58 pm

You made it a 8-bit map though.....?
Upcoming games I'm working on:
  • Minecraft2DS
  • Bow Man DS
  • Bird poo!
------------------------------------------------------------------------
COOL LOOK 3D portal port for DS! http://drunkencoders.com/2013/01/dstal-advance/
needMusic?needHelp?Ask.
User avatar
Buck_7
 
Posts: 1002
Joined: February 19th, 2011, 1:44 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Foxi4 » February 29th, 2012, 6:47 pm

Buck_7 wrote:You made it a 8-bit map though.....?

Only because I felt like using 8-Bit text at the same time. They're compatible but incredibly memory-monging and not recommended.

Mode7 isn't even part of this tutorial and all of a sudden it consumed most of it. :lol:

Just to repeat the purpose of this thread - it's about using 8-Bit and 16c Backgrounds and about the general idea of rotating a background, as most of the rotation rules apply to either RotBG's or Bitmaps. ;)
Last edited by Foxi4 on February 29th, 2012, 6:48 pm, edited 1 time in total.
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1119
Joined: December 31st, 2010, 3:25 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Buck_7 » February 29th, 2012, 6:48 pm

Yeah, okay

Well it's alot more impressive! Now I can make some things I once thought impossible to make!
I'm also trying,like commodore to load a sprite onto the screen without the blackness...
But , as expected, It doesn't usually work the first time I try.
Upcoming games I'm working on:
  • Minecraft2DS
  • Bow Man DS
  • Bird poo!
------------------------------------------------------------------------
COOL LOOK 3D portal port for DS! http://drunkencoders.com/2013/01/dstal-advance/
needMusic?needHelp?Ask.
User avatar
Buck_7
 
Posts: 1002
Joined: February 19th, 2011, 1:44 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Foxi4 » February 29th, 2012, 6:51 pm

Buck_7 wrote:Well it's alot more impressive! Now I can make some things I once thought impossible to make!


I personally think it's incredibly limited and it doesn't look as nice as people praise it. It's not 3D - it's just a 2D background that's been kicked on one side to appear 2D - the objects are still plotted in 2D space, plotting them is tedious and time-consuming, using the angle system to turn the camera in an a'la 3D space is complete torture and this type of backgrounds are generally not used anymore unless you're developing for, I don't know, a GBA or a SNES.

There are readily-available *full 3D* engines for the DS out there that will do all Mode7 does and more while being prettier, faster and y'know, "actually 3D". With walls 'n stuff. ;)
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1119
Joined: December 31st, 2010, 3:25 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Commodore » February 29th, 2012, 10:18 pm

What full 3D engines? This might be something to look into.
"Every puzzle has an answer." - Professor Layton
_______________________________________________________________________
December 17, 2012 - MegaMan 25th Anniversary
_______________________________________________________________________
Member of Memefefe's Squad
User avatar
Commodore
 
Posts: 557
Joined: August 10th, 2011, 4:39 pm

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby YoshiInAVoid » February 29th, 2012, 10:40 pm

This might be interesting:
http://wademcgillis.com/html5games/Wolfenstein3D/
You can right click and view page source.

The guy coded the whole thing without exta libaries, just plain javascript using a method called "raycasting".

There was a tutorial somewhere, and it showed all of the steps of how he made it, starting with just the minimap and working his way up from there but I can't find it.


Just something I thought you guys might want to see.
Sorry, Jack, YoshiInAVoid's back!

I'm the original; I'll take your breath away! This fall, YoshiInAVoid rules! Did you miss me, Andy? I sure missed you!

Keep an eye out for me.
YoshiInAVoid
 
Posts: 1985
Joined: December 30th, 2010, 11:53 am
Location: England

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Foxi4 » February 29th, 2012, 11:04 pm

Raycasting isn't 3D either.

If you want true 3D with relatively little efford, just use N3.

http://www.nightfoxandco.com/index.php/ ... 3/?lang=en
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1119
Joined: December 31st, 2010, 3:25 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Commodore » February 29th, 2012, 11:27 pm

With this "N3", can I
A)Use it for the DS?
2)Use 2D sprites in it?
D)Use It in conjunction with DSGM?
"Every puzzle has an answer." - Professor Layton
_______________________________________________________________________
December 17, 2012 - MegaMan 25th Anniversary
_______________________________________________________________________
Member of Memefefe's Squad
User avatar
Commodore
 
Posts: 557
Joined: August 10th, 2011, 4:39 pm

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Foxi4 » February 29th, 2012, 11:34 pm

Yes.
Yes.
No, at least not until it becomes too tedious to even be worth it.
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1119
Joined: December 31st, 2010, 3:25 am

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Commodore » February 29th, 2012, 11:48 pm

Also, can it make a full DS game?(not just the graphics, libraries and such)
EDIT: I just looked at it. It's an add on to the "NightFox" program, which just lets you be able to code in C.
"Every puzzle has an answer." - Professor Layton
_______________________________________________________________________
December 17, 2012 - MegaMan 25th Anniversary
_______________________________________________________________________
Member of Memefefe's Squad
User avatar
Commodore
 
Posts: 557
Joined: August 10th, 2011, 4:39 pm

Re: (Final)8-Bit and 16c Backgrounds - Rotation

Postby Foxi4 » March 1st, 2012, 12:45 am

NFlib is a complete wrapper for libnds, utilizing it is pretty much equal to utilizing PAlib in the respect of functionality, it's just maintained, less buggy and generally better. PAlib's dead, it's been dead for a while and nobody will ever revive it - it became too cluttered with deprecated code that nobody felt like cleaning up and many functions work differently then they are documented or no longer work at all.
Current Projects:

FalloutDS: Postponed until proper libraries are created, 10%
Foxi_Lib: A completely revised version of NitroSprites[FINAL], NitroBackgrounds and NitroText[FINAL], 40%
Foxi4
 
Posts: 1119
Joined: December 31st, 2010, 3:25 am

PreviousNext

Return to Tutorials & Examples

Who is online

Users browsing this forum: No registered users and 0 guests