-
-
Save anonymous/1201550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <nds.h> | |
#include <stdio.h> | |
#include <nds/input.h> | |
//-----------------sprites and bg---------------- | |
#include "Mrhop.h" | |
#include "Grass_Type.h" | |
#include "carrot.h" | |
//-------------------------------------------------- | |
int checkCollision(); | |
int Carrot_X = 45; | |
int Carrot_Y = 45; | |
int Carrot_W = 16; | |
int Carrot_H = 16; | |
int Bunny_X = 0; | |
int Bunny_Y = 0; | |
int Bunny_W = 32; | |
int Bunny_H = 32; | |
int processEvents(); | |
int HideBunny(void); | |
int keyPressed(); | |
int screenTouched(); | |
int moveBunny(touchPosition * touch); | |
int readInput(touchPosition * touch); | |
bool checkBunnyCarrotCol() | |
{ | |
bool hit = false; | |
if (Bunny_X <= Carrot_X + Carrot_W) | |
{ | |
if (Bunny_X + Bunny_W >= Carrot_X) | |
{ | |
if (Bunny_Y <= Carrot_Y + Carrot_H) | |
{ | |
if (Bunny_Y + Bunny_H >= Carrot_Y) | |
{ | |
hit = true; | |
} | |
} | |
} | |
} | |
return(hit); | |
} | |
bool checkCollision(touchPosition * touch) | |
{ | |
bool hit = false; | |
hit = checkBunnyCarrotCol(); | |
return(hit); | |
} | |
int HideBunny(void) | |
{ | |
oamClearSprite(&oamSub,0); | |
return 0; | |
} | |
int HideCarrot(void) | |
{ | |
oamClearSprite(&oamSub,1); | |
return 0; | |
} | |
int moveBunny(touchPosition * touch) | |
{ | |
//--------------------------------bunny sprite------------------------------ | |
oamSet(&oamSub, 0,Bunny_X,Bunny_Y, 0, 0, SpriteSize_32x32, SpriteColorFormat_16Color, Bunny, -1, false, false, false, false, false); | |
} | |
int moveCarrot(touchPosition * touch) | |
{ | |
//--------------------------------Carrot sprite------------------------------ | |
oamSet(&oamSub, 1,Carrot_X,Carrot_Y, 0, 0, SpriteSize_16x16, SpriteColorFormat_16Color, Carrot, 0, false, false, false, false, false); | |
} | |
int screenTouched() | |
{ | |
touchPosition touch; | |
readInput(&touch); | |
Bunny_X = touch.px; | |
Bunny_Y = touch.py; | |
if (checkCollision(&touch) == true) | |
{ | |
HideBunny(); | |
} | |
else | |
{ | |
moveBunny(&touch); | |
} | |
moveCarrot(&touch); | |
swiWaitForVBlank(); | |
oamUpdate(&oamSub); | |
return 0; | |
} | |
int keyPressed() | |
{ | |
touchPosition touch; | |
readInput(&touch); | |
if(keysHeld() & KEY_Y) | |
{ | |
HideBunny(); | |
} | |
if(keysHeld() & KEY_DOWN) | |
{ | |
Bunny_Y += 2; | |
if (checkCollision(&touch) == true) | |
{ | |
HideBunny(); | |
} | |
else | |
{ | |
moveBunny(&touch); | |
} | |
} | |
if(keysHeld() & KEY_UP) | |
{ | |
Bunny_Y -= 2; | |
if (checkCollision(&touch) == true) | |
{ | |
HideBunny(); | |
} | |
else | |
{ | |
moveBunny(&touch); | |
} | |
} | |
if(keysHeld() & KEY_LEFT) | |
{ | |
Bunny_X -= 2; | |
if (checkCollision(&touch) == true) | |
{ | |
HideBunny(); | |
} | |
else | |
{ | |
moveBunny(&touch); | |
} | |
} | |
if(keysHeld() & KEY_RIGHT) | |
{ | |
Bunny_X += 2; | |
if (checkCollision(&touch) == true) | |
{ | |
HideBunny(); | |
} | |
else | |
{ | |
moveBunny(&touch); | |
} | |
} | |
moveCarrot(&touch); | |
swiWaitForVBlank(); | |
oamUpdate(&oamSub); | |
return 0; | |
} | |
int readInput(touchPosition * touch) | |
{ | |
scanKeys(); | |
touchRead(touch); | |
} | |
int startup() | |
{ | |
videoSetModeSub(MODE_5_2D); | |
vramSetBankC(VRAM_C_SUB_BG); | |
touchPosition touch; | |
//----------------------------------set the Vram for sprites | |
vramSetBankD(VRAM_D_SUB_SPRITE); | |
//--------------------------------bunny sprite prep. | |
oamInit(&oamSub, SpriteMapping_1D_128, false); | |
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 22, 3, false, true); | |
u16* Bunny = oamAllocateGfx(&oamSub, SpriteSize_32x32, SpriteColorFormat_16Color); | |
dmaCopy(MrhopTiles, Bunny, MrhopTilesLen); | |
dmaCopy(MrhopPal, SPRITE_PALETTE_SUB, MrhopPalLen); | |
//--------------------------------carrot sprite prep. | |
oamInit(&oamSub, SpriteMapping_1D_128, false); | |
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 22, 3, false, true); | |
u16* Carrot = oamAllocateGfx(&oamSub, SpriteSize_16x16, SpriteColorFormat_16Color); | |
dmaCopy(carrotTiles, Carrot, carrotTilesLen); | |
dmaCopy(carrotPal, SPRITE_PALETTE_SUB, carrotPalLen); | |
int bg3 = bgInitSub(3, BgType_Bmp8, BgSize_B8_256x256, 4,0); | |
dmaCopy(Grass_TypeBitmap, bgGetGfxPtr(bg3), 256*256); | |
dmaCopy(Grass_TypePal, BG_PALETTE_SUB, 256*2); | |
BG_PALETTE_SUB[255]=RGB15(31,31,31); | |
processEvents(); | |
} | |
int processEvents() | |
{ | |
touchPosition touch; | |
iprintf("welcome to test1\n "); | |
iprintf("Touch the screen\n "); | |
iprintf("press Y to hide the bunny\n "); | |
while(1) | |
{ | |
readInput(&touch); | |
keyPressed(); | |
if(keysHeld() & KEY_TOUCH) | |
{ | |
screenTouched(); | |
} | |
swiWaitForVBlank(); | |
oamUpdate(&oamSub); | |
} | |
return 0; | |
} | |
int main(void) | |
{ | |
startup(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment