Exemple #1
0
int main(void) {
    memcpy(&tile_mem[4][0], blobLargeTiles, blobLargeTilesLen);
    memcpy(pal_obj_mem, blobLargePal, blobLargePalLen);
    oam_init(obj_buffer, 128);
    REG_DISPCNT = DCNT_OBJ | DCNT_OBJ_1D;

    OBJ_ATTR * blob = &obj_buffer[0];
    u32 blobTileIndex = 0;
    u32 blobPalBank = 0;

    //two different ways of setting OAM values: by hand and using TONC macros

    blob->attr0 = (blob->attr0 & ~ATTR0_SHAPE_MASK) | ATTR0_SQUARE;
    blob->attr1 = (blob->attr1 & ~ATTR1_SIZE_MASK) | ATTR1_SIZE_64;
    blob->attr2 = (blob->attr2 & ~ATTR2_ID_MASK) | (blobTileIndex << ATTR2_ID_SHIFT);
    blob->attr2 = (blob->attr2 & ~ATTR2_PALBANK_MASK) | (blobPalBank << ATTR2_PALBANK_SHIFT);

    /*
    BFN_SET2(blob->attr0, ATTR0_SQUARE, ATTR0_SHAPE);
    BFN_SET2(blob->attr1, ATTR1_SIZE_64, ATTR1_SIZE);
    BFN_SET(blob->attr2, blobTileIndex, ATTR2_ID);
    BFN_SET(blob->attr2, blobPalBank, ATTR2_PALBANK);
    */

	while (1) {
        vid_vsync();

        obj_unhide(blob, 0);

        oam_copy(oam_mem, obj_buffer, 1);
	}
}
Exemple #2
0
void link_init(TSprite *link, int x, int y, int obj_id)
{
	link->x= x;
	link->y= y;
	link->vx= link->vy= 0;

	link_set_state(link, SPR_STATE_STAND);
	link->dir= LOOK_RIGHT;
	link->objId= obj_id;

	oam_copy(&obj_buffer[obj_id], cLinkObjs, 3);
}
Exemple #3
0
void init_oam(OBJATTR *obj, u32 count)
{
    u32 nn = count;
    u32 *dst = (u32*)obj;

    // Hide each object
    while (nn--)
    {
        *dst++ = OBJ_DISABLE;
        *dst++ = 0;
    }

    oam_copy(OAM, obj, count);
}
Exemple #4
0
void init_game()
{
   //Initialization
   
   //Field_0
   memcpy(pal_bg_mem, bd_forestPal, bd_forestPalLen);
   memcpy(&tile_mem[0][0], bd_forestTiles, bd_forestTilesLen);
   memcpy(&se_mem[30][0], bd_forestMap, bd_forestMapLen);
   
   REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_4BPP | BG_REG_32x32 | BG_PRIO(1);
   
   //Bg_Forest
   memcpy(&pal_bg_bank[1], bg_forestPal, bg_forestPalLen);
   memcpy(&tile_mem[0][16], bg_forestTiles, bg_forestTilesLen);
   memcpy(&se_mem[28][0], bg_forestMap, bg_forestMapLen);
   
   REG_BG1CNT = BG_CBB(0) | BG_SBB(28) | BG_4BPP | BG_REG_64x32 | BG_PRIO(0);
   
   
   memcpy(&tile8_mem[4][0], pikmin_sheetTiles, pikmin_sheetTilesLen);
   memcpy(pal_obj_mem, pikmin_sheetPal, pikmin_sheetPalLen);
	
	
	REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_OBJ| DCNT_OBJ_1D;
	
	oam_init(obj_buffer, 128);
	
	u32 tid=0, pb=0;
	
	OBJ_ATTR *pkm = &obj_buffer[0];
	
	obj_set_attr(pkm, 
	             ATTR0_TALL, 
	             ATTR1_SIZE_16x32, 
	             ATTR2_PALBANK(pb) | tid);
	             
	pkm->attr0 |= ATTR0_8BPP;
	
	oam_copy(oam_mem, obj_buffer, 1);
}
Exemple #5
0
int main()
{
	int i;
	struct VEngine veng;
	struct World world;
	JoyState* joy;

	v_init(&veng);
	joy_init();

	/* for a random seed, wait for user input */
	i = 0;
	while (1) {
		vid_vsync();
		key_poll();
		v_putbgtile(5, 4, 37);
		v_putbgtile(6, 4, 48);
		v_putbgtile(7, 4, 51);
		v_putbgtile(8, 4, 51);
		v_putbgtile(9, 4, 51);
		if (key_hit(KEY_A) || key_hit(KEY_START)) {
			break;
		}
		i ++;
	}

	/* sqran(i); */
	sqran(4);

	init_world(&world, &veng);

	/* obj_set_pos(dude, (16 * 7), (16 * 4)); */
	
	v_draw_bg(world.map, &veng, world.map->dudex, world.map->dudey);

	while(1)
	{
		vid_vsync();
		joy = joy_poll();
		key_poll();

		if (key_hit(KEY_A)) {
			/*
			v_draw_more_bg(world.map, veng.mapofsx, veng.mapofsy - 4, 15, 4,
				world.map->dudex - 6 - veng.dudeposx,
				world.map->dudey - 4 - 4 - veng.dudeposy);
				*/
		}

		if (key_hit(KEY_START)) {
			v_init(&veng);
			init_world(&world, &veng);

			/*
			obj_set_pos(veng.obj_buffer[veng.spr_dude], (16 * 7), (16 * 4));
			*/

			v_draw_bg(world.map, &veng,
				world.map->dudex, world.map->dudey);
		}

		/*
		if (key_hit(KEY_LEFT)) {
			switch (r_move_left(&world)) {
				case 1:
					v_move_left(&veng);
					break;
				case 2:
					v_shake_dude(&veng, 1, 0);
					break;
			}
		} else if (key_hit(KEY_RIGHT)) {
			switch (r_move_right(&world)) {
				case 1:
					v_move_right(&veng);
					break;
				case 2:
					v_shake_dude(&veng, 1, 0);
					break;
			}
		} else if (key_hit(KEY_UP)) {
			switch (r_move_up(&world)) {
				case 1:
					v_move_up(&veng);
					break;
				case 2:
					v_shake_dude(&veng, 0, 1);
					break;
			}
		} else if (key_hit(KEY_DOWN)) {
			switch (r_move_down(&world)) {
				case 1:
					v_move_down(&veng);
					break;
				case 2:
					v_shake_dude(&veng, 0, 1);
					break;
			}
		}
		*/

		if (joy->moving) {
			switch (r_move(&world, joy->dx, joy->dy)) {
				case 1:
					v_move(&veng, joy->dx, joy->dy);
					break;
				case 2:
					v_shake_dude(&veng, 0, 1);
					break;
			}
			joy_handled();
		}
		v_move_co(&veng);

		v_scroll_at_edge(&veng, &world);

		v_draw_dude(&veng);

		for (i = 0; i < world.monstercount; i ++) {
			v_draw_monster(&veng, &world, i);
		}

		oam_copy(oam_mem, veng.obj_buffer, 1 + world.monstercount);
	}

	return 0;
}
Exemple #6
0
void copy_objs() {
	oam_copy(oam_mem, obj_buffer, active_objs);
}
Exemple #7
0
//---------------------------------------------------------------------------------
// Program entry point
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------


	// the vblank interrupt must be enabled for VBlankIntrWait() to work
	// since the default dispatcher handles the bios flags no vblank handler
	// is required
	irqInit();
	irqEnable(IRQ_VBLANK);

	// set mode 0, 1D mapping
	REG_DISPCNT = MODE_0 | OBJ_1D_MAP;

    init_oam(obj_buffer, 128);

	// copy sprites to appropriate memory spots
	u16 *palette_end = SPRITE_PALETTE;
	u16 *tiles_end =SPRITE_GFX;
	// blue slime
	memcpy(palette_end, blueslimePal, blueslimePalLen);
	memcpy(tiles_end, blueslimeTiles, blueslimeTilesLen);
	palette_end += blueslimePalLen/2;
	tiles_end += blueslimeTilesLen/2;
	// drakee
	memcpy(palette_end, drakeePal, drakeePalLen);
	memcpy(tiles_end, drakeeTiles, drakeeTilesLen);
	palette_end += drakeePalLen/2;
	tiles_end += drakeeTilesLen/2;
	// orange slime
	memcpy(palette_end, orangeslimePal, orangeslimePalLen);
	memcpy(tiles_end, orangeslimeTiles, orangeslimeTilesLen);
	palette_end += orangeslimePalLen/2;
	tiles_end += orangeslimeTilesLen/2;

	// enable sprites
	REG_DISPCNT |= OBJ_ON | OBJ_WIN_ENABLE;

	u16 x = 0;
	u16 y = 0;
	s8 sprite = 1;
	u16 status = ATTR0_NORMAL;


	obj_buffer[0].attr0 = (y & 0x00ff) | ATTR0_NORMAL | ATTR0_COLOR_16 | ATTR0_SQUARE;
	obj_buffer[0].attr1 = (x & 0x01ff) | ATTR1_SIZE_32;
    obj_buffer[0].attr2 = OBJ_CHAR(0);
	
	oam_copy(OAM, obj_buffer, 1);

	setRepeat(1,1);

	while (1)
	{
		// check keypad
		scanKeys();
		u16 keystate = keysDownRepeat();
		u16 keydown = keysDown();
		// directional pad
		// move sprite
		if (keystate & KEY_LEFT)
			x -= 1;
		else if (keystate & KEY_RIGHT)
			x += 1;
		if (keystate & KEY_UP)
			y -= 1;
		else if (keystate & KEY_DOWN)
			y += 1;
		// A
		// enable/disable sprite
		if (keydown & KEY_A)
		{
			if (status == ATTR0_NORMAL)
				status = ATTR0_DISABLED;
			else
				status = ATTR0_NORMAL;
		}
		// L + R
		// rotate sprites
        if (keydown & KEY_R)
		{
			sprite++;
			if (sprite > 2) sprite = 0;
		}
        else if (keydown & KEY_L)
		{
            sprite--;
			if (sprite < 0) sprite = 2;
		}
			
		// set current sprite attributes
        obj_buffer[0].attr0 = (y & 0x00ff) | status | ATTR0_COLOR_16 | ATTR0_SQUARE;
        obj_buffer[0].attr1 = (x & 0x01ff) | ATTR1_SIZE_32;
        obj_buffer[0].attr2 = OBJ_CHAR(sprite*16) | OBJ_PALETTE(sprite);

        oam_copy(OAM, obj_buffer, 1);

		VBlankIntrWait();
	}

	return 0;
}