/*---------------------------------------------------------------------------* Project: Dolphin/Revolution gx demo File: G2D-testEditor.c (Test of 2D API by Paul Donnelly, Nov. 1999) Copyright 1998-2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #include "G2D-test.h" #ifdef _EDITOR #include #include #include /*---------------------------------------------------------------------------* Defines *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------* Global Variables *---------------------------------------------------------------------------*/ s32 nMapX, nMapY; s32 nStampLeft, nStampWidth = 1; s32 nStampTop, nStampHeight = 1; s32 nStampStartX, nStampStartY; s32 nStampOffsetX, nStampOffsetY; u8 aEditStamp[8192]; u8 aEditBack[8192]; /*---------------------------------------------------------------------------* Local Function Declarations *---------------------------------------------------------------------------*/ static void DrawCursor ( void ); #endif // ifdef _EDITOR /*---------------------------------------------------------------------------* Name: MapEditor Description: Logic for map editor mode (uses ship position variables for cursor position) Arguments: none Returns: none *---------------------------------------------------------------------------*/ void MapEditor( G2DLayer *layer ) { #ifdef _EDITOR s8 nDX, nDY; static s8 nOldDX = 0; static s8 nOldDY = 0; s32 nMapIdx, nIdx; u8 *buf = aEditStamp; s32 nX, nY, nZ; s32 nOldMapX, nOldMapY; nOldMapX= nMapX; nOldMapY= nMapY; nDX = 0; if (DEMOPadGetDirsNew(0) & DEMO_STICK_RIGHT) { nDX = 1; } else if (DEMOPadGetDirsNew(0) & DEMO_STICK_LEFT) { nDX = -1; } nDY = 0; if (DEMOPadGetDirsNew(0) & DEMO_STICK_DOWN) { nDY = 1; } else if (DEMOPadGetDirsNew(0) & DEMO_STICK_UP) { nDY = -1; } if (nButtons & PAD_BUTTON_B) { poShip.rPosX += (f32)(nDX * layer->nTileWidth); poShip.rPosY += (f32)(nDY * layer->nTileHeight); } else { if ((nDX) && (nOldDX == 0)) { poShip.rPosX += (f32)(nDX * layer->nTileWidth); } if ((nDY) && (nOldDY == 0)) { poShip.rPosY += (f32)(nDY * layer->nTileHeight); } } nOldDX = nDX; nOldDY = nDY; if (poShip.rPosX >= rWorldWidth) { poShip.rPosX -= rWorldWidth; } else if (poShip.rPosX < 0) { poShip.rPosX += rWorldWidth; } if (poShip.rPosY >= rWorldHeight) { poShip.rPosY -= rWorldHeight; } else if (poShip.rPosY < 0) { poShip.rPosY += rWorldHeight; } nMapX = (s32)(poShip.rPosX / layer->nTileWidth); nMapY = (s32)(poShip.rPosY / layer->nTileHeight); nMapIdx = (nMapY<nHS) + nMapX; if (nButtons & PAD_BUTTON_X) { if ((~nOldButtons) & PAD_BUTTON_X) { nStampStartX = nMapX; nStampStartY = nMapY; nStampOffsetX = 0; nStampOffsetY = 0; } else { /* If there was a change in map coordinates, we should add * that change to the stamp offset */ if (nMapX != nOldMapX) { nStampOffsetX += nDX; } if (nMapY != nOldMapY) { nStampOffsetY += nDY; } } if (nStampOffsetX < 0) { nStampLeft = nStampStartX + nStampOffsetX; nStampWidth = 1 - nStampOffsetX; } else { nStampLeft = nStampStartX; nStampWidth = 1 + nStampOffsetX; } if (nStampOffsetY < 0) { nStampTop = nStampStartY + nStampOffsetY; nStampHeight = 1 - nStampOffsetY; } else { nStampTop = nStampStartY; nStampHeight = 1 + nStampOffsetY; } if (nStampWidth > nMapWidth) { nStampWidth = nMapWidth; } if (nStampHeight > nMapHeight) { nStampHeight = nMapHeight; } /* Copy block of tiles for use as a stamp */ buf = aEditStamp; for(nY = 0; nYnHS) + nMapX; map[nMapIdx] = (u8)('*'-' '); // "*' indicates the start position of the ship for (nJ=0; nJnHS)+nI] + ' '); } fprintf(fpMap, "\"\n"); } map[nMapIdx] = '.'-' '; fclose(fpMap); #else #pragma unused (layer) #endif // ifdef _EDITOR } /*---------------------------------------------------------------------------* Name: DrawCursor Description: Draw the map-editor cursor Arguments: none Returns: none *---------------------------------------------------------------------------*/ static void DrawCursor( void ) { #ifdef _EDITOR s32 nX, nY, nW, nH; nX = lyrBack.nTileWidth * (nStampLeft + nMapX - nStampStartX - nStampOffsetX); nY = lyrBack.nTileHeight * (nStampTop + nMapY - nStampStartY - nStampOffsetY); nW = lyrBack.nTileWidth * nStampWidth; nH = lyrBack.nTileHeight * nStampHeight; /* Draw a white box around the position of the cursor */ // Set Position Params GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0); //PositionShift); GXSetVtxDesc(GX_VA_POS, GX_DIRECT); // Set Color for Vertex Format 0 GXSetNumTexGens(0); GXSetNumChans(1); GXSetVtxDesc(GX_VA_TEX0, GX_NONE); GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR); GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGB8, 0); GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT); GXBegin(GX_LINESTRIP, GX_VTXFMT0, 3); GXPosition2f32( (f32)(nX + 4), (f32)nY ); GXColor3u8( 255, 255, 255 ); GXPosition2f32( (f32)nX, (f32)nY ); GXColor3u8( 255, 255, 255 ); GXPosition2f32( (f32)nX, (f32)(nY + 4) ); GXColor3u8( 255, 255, 255 ); GXEnd(); GXBegin(GX_LINESTRIP, GX_VTXFMT0, 3); GXPosition2f32( (f32)(nX + nW - 4), (f32)nY ); GXColor3u8( 255, 255, 255 ); GXPosition2f32( (f32)(nX + nW), (f32)nY ); GXColor3u8( 255, 255, 255 ); GXPosition2f32( (f32)(nX + nW), (f32)(nY + 4) ); GXColor3u8( 255, 255, 255 ); GXEnd(); GXBegin(GX_LINESTRIP, GX_VTXFMT0, 3); GXPosition2f32( (f32)(nX + 4), (f32)(nY + nH) ); GXColor3u8( 255, 255, 255 ); GXPosition2f32( (f32)nX, (f32)(nY + nH) ); GXColor3u8( 255, 255, 255 ); GXPosition2f32( (f32)nX, (f32)(nY + nH - 4) ); GXColor3u8( 255, 255, 255 ); GXEnd(); GXBegin(GX_LINESTRIP, GX_VTXFMT0, 3); GXPosition2f32( (f32)(nX + nW - 4), (f32)(nY + nH) ); GXColor3u8( 255, 255, 255 ); GXPosition2f32( (f32)(nX + nW), (f32)(nY + nH) ); GXColor3u8( 255, 255, 255 ); GXPosition2f32( (f32)(nX + nW), (f32)(nY + nH - 4) ); GXColor3u8( 255, 255, 255 ); GXEnd(); #endif // ifdef _EDITOR } /*---------------------------------------------------------------------------* Name: RenderEditorMode Description: Renders the Arguments: none Returns: none *---------------------------------------------------------------------------*/ void RenderEditorMode( s8 *aSortBuffer ) { #ifdef _EDITOR s32 nStaticX = nStampLeft + nMapX - nStampStartX - nStampOffsetX; s32 nStaticY = nStampTop + nMapY - nStampStartY - nStampOffsetY; s32 nMapWidth = 1<