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.
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;
}YoshiInAVoid wrote:-Can't put mode7 on the top screen,
-Couldn't figure out how to put mountains and clouds behind the track,
Plot bumper objects along the track or use tile-based collision.-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.
Buck_7 wrote:You made it a 8-bit map though.....?
Buck_7 wrote:Well it's alot more impressive! Now I can make some things I once thought impossible to make!
Return to Tutorials & Examples
Users browsing this forum: No registered users and 0 guests