示例#1
0
文件: project.c 项目: CTurt/dsgmLib
void player_loop(playerObjectInstance *me) {
	if(DSGM_held.Stylus) {
		(*me->angle) = DSGM_GetAngle(me->x + 16, me->y + 16, DSGM_stylus.x, DSGM_stylus.y);
	}
	if(DSGM_held.Left) {
		(*me->angle) += degreesToAngle(4);
	}
	if(DSGM_held.Right) {
		(*me->angle) -= degreesToAngle(4);
	}
	
	if(DSGM_held.Up) {
		DSGM_MoveObjectInstanceAtRotatedAngle(me);
	}
	if(DSGM_held.Down) {
		DSGM_MoveObjectInstanceAtAngle(me, (*me->angle) + degreesToAngle(180));
	}
	
	if(DSGM_newpress.A) {
		bulletObjectInstance *bulletInstance = (bulletObjectInstance *)DSGM_CreateObjectInstance(DSGM_BOTTOM, me->x + 8, me->y + 8, &DSGM_Objects[bullet]);
		*bulletInstance->angle = *me->angle;
		
		DSGM_UpdateInput();
	}
}
示例#2
0
文件: project.c 项目: CTurt/dsgmLib
void orange_loop(orangeObjectInstance *me) {	
	me->variables->vy += 16;
	
	me->bx += me->variables->vx;
	me->by += me->variables->vy;
	
	me->x = me->bx >> me->bitshift;
	me->y = me->by >> me->bitshift;
	
	if(me->y > 192) {
		DSGM_DeleteObjectInstance(me);
	}
	
	if(me->frame == 0) {
		int x = drawCoords[0].x, y = drawCoords[0].y, x2 = drawCoords[1].x, y2 = drawCoords[1].y, length = 32;
		
		int angle = DSGM_GetAngle(x, y, x2, y2) + degreesToAngle(90);
		
		x = (cosLerp(angle) * length / 2) >> 12;
		y = (-sinLerp(angle) * length / 2) >> 12;
		
		angle += degreesToAngle(180);
		
		x2 = (cosLerp(angle) * length / 2) >> 12;
		y2 = (-sinLerp(angle) * length / 2) >> 12;
		
		if(DSGM_Intersection(drawCoords[0].x, drawCoords[0].y, drawCoords[1].x, drawCoords[1].y, me->x + 16 + x, me->y + 16 + y, me->x + 16 + x2, me->y + 16 + y2)) {
			me->frame = 1;
			
			orangeObjectInstance *o = (orangeObjectInstance *)DSGM_CreateObjectInstance(DSGM_BOTTOM, me->x, me->y, me->object);
			o->variables->vx = me->variables->vx / 2;
			o->variables->vy = me->variables->vy / 2;
			o->frame = 2;
		}
	}
示例#3
0
//-------------------------------------------------------
void renderPyramid(int angle){
//-------------------------------------------------------
 
	glPushMatrix();
	glTranslatef(0, 0, -4);
	glRotatef32i(degreesToAngle(angle), inttof32(1),inttof32(1),inttof32(1)); 
	
	glBegin(GL_QUADS);
		glColor3b(255,0,0);		glVertex3f(-1.0f, -1.0f,  1.0f);					
		glColor3b(0,255,0);		glVertex3f( 1.0f, -1.0f,  1.0f);					
		glColor3b(0,0,255);		glVertex3f( 1.0f, -1.0f, -1.0f);					
		glColor3b(255,255,0);	glVertex3f(-1.0f, -1.0f, -1.0f);					
	glEnd();

	glBegin(GL_TRIANGLES);
		glColor3b(255,0,0);		glVertex3f( 0.0f,  1.0f,  0.0f);					
		glColor3b(0,255,0);		glVertex3f(-1.0f, -1.0f,  1.0f);					
		glColor3b(0,0,255);		glVertex3f( 1.0f, -1.0f,  1.0f);					

		glColor3b(255,0,0);		glVertex3f( 0.0f,  1.0f,  0.0f);					
		glColor3b(0,255,0);		glVertex3f(-1.0f, -1.0f, -1.0f);					
		glColor3b(0,0,255);		glVertex3f( 1.0f, -1.0f, -1.0f);					

		glColor3b(255,0,0);		glVertex3f( 0.0f,  1.0f,  0.0f);					
		glColor3b(0,255,0);		glVertex3f(-1.0f, -1.0f,  1.0f);					
		glColor3b(0,0,255);		glVertex3f(-1.0f, -1.0f, -1.0f);					

		glColor3b(255,0,0);		glVertex3f( 0.0f,  1.0f,  0.0f);					
		glColor3b(0,255,0);		glVertex3f( 1.0f, -1.0f,  1.0f);					
		glColor3b(0,0,255);		glVertex3f( 1.0f, -1.0f, -1.0f);					
	glEnd();
 
	glPopMatrix(1);
}
void TrashCanEntity::Update()
{
	transformContext = 0;

	u8 derp = (u8)(updateCount % 30);
	float32 periodic = 0.5*sin(3.14159*(float32)derp/30.0);
	float32 derp2 = periodic + 1.0;

	oamRotateScale(&oamSub,
		0,
		degreesToAngle(periodic*10-30),
		floatToFixed(derp2, 8),
		floatToFixed(derp2, 8)	
	);

	if (shouldBeRemoved)
		return;

	if (IsTouchedByNearbyPlayer())
	{
		LivingEntity::Damage(gpPlayerEntity->mStats->attack);
		printf("Trashcan Ouch %d!\n", mStats->health);
	}

	Sprite::Update();
}
示例#5
0
文件: project.c 项目: CTurt/dsgmLib
void ball_loop(ballObjectInstance *me) {
	if((DSGM_ObjectInstance *)me == &DSGM_GetGroup(me)->objectInstances[0]) {
		me->x = 112 + (cosLerp(angle) * 32 >> 12);
		me->y = 80 - (sinLerp(angle) * 16 >> 12);
		
		// Display on top of the other ball
		if(angle >= degreesToAngle(180)) me->priority = 0;
		
		// Display behind the other ball
		else  me->priority = 1;
		
		me->scale->x = 256 + (sinLerp(angle) >> 8);
		me->scale->y = 256 + (sinLerp(angle) >> 8);
		
		angle += degreesToAngle(6);
		angle %= degreesToAngle(360);
	}
示例#6
0
void updatePlayer(struct PLAYER * player, struct CAMERA * camera)
{
	scanKeys();
	int hold = keysHeld();

	player->yPos = -500;
	
	int vec[3];
	vec[0] = (2000 * sinLerp(camera->yRot)) / 4096;
	vec[1] = 0;
	vec[2] = (2000 * cosLerp(camera->yRot)) / 4096;

	if(!(vec[0] == 0 && vec[1] == 0 && vec[2] == 0))
		normalizef32(&vec[0]);

	//printf("%d, %d\n", xCam, zCam);
	printf("%d, %d\n", vec[0], vec[2]);

	if (hold & KEY_LEFT)
	{
		player->yRot += degreesToAngle(1);
		player->xPos += vec[0] * 15/ 4096;
		player->zPos += vec[2] * 15/ 4096;
	}
	if (hold & KEY_RIGHT)
	{
		player->yRot -= degreesToAngle(1);
		player->xPos += vec[0] * 15/ 4096;
		player->zPos += vec[2] * 15/ 4096;
	}
	if (hold & KEY_UP)
	{
			player->xPos += vec[0] * 20/ 4096;
			player->zPos += vec[2] * 20/ 4096;
			//not 100% correct, because when you press up and left together, you will not rotate!
			if(abs(player->yRot - camera->yRot) < 150) player->yRot = camera->yRot;
			else
			{
				if(camera->yRot > player->yRot) player->yRot += 150;
				if(camera->yRot < player->yRot) player->yRot -= 150;
			}
			//player->yRot = camera->yRot;
	}
	if (hold & KEY_DOWN)
	{
		player->xPos -= vec[0] * 20/ 4096;
		player->zPos -= vec[2] * 20/ 4096;
		if(abs(player->yRot - camera->yRot) < 150) player->yRot = camera->yRot;
	else
	{
		if(camera->yRot > player->yRot) player->yRot += 150;
		if(camera->yRot < player->yRot) player->yRot -= 150;
	}
		/*if(abs(player->yRot - (degreesToAngle(180) - camera->yRot)) < 300) player->yRot = (degreesToAngle(180) - camera->yRot);
	else
	{
		if(camera->yRot > (degreesToAngle(180) - camera->yRot)) player->yRot += 300;
		if(camera->yRot < (degreesToAngle(180) - camera->yRot)) player->yRot -= 300;
	}*/
	}
}
示例#7
0
文件: template.c 项目: kamocat/nds
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
    int i = 0;
    int angle = 0;

    videoSetMode(MODE_0_2D);

    vramSetBankA(VRAM_A_MAIN_SPRITE);

    oamInit(&oamMain, SpriteMapping_1D_32, false);

    u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color);

    /* This is where we load the image.
     * In this case we're doing a really simple striped pattern,
     * but we could also load a bitmap. */
    for(i = 0; i < 32 * 32 / 2; i++)
    {
        //gfx[i] = 1 | (1 << 8);
        gfx[i] = 0x201;	// alternating red and yellow
    }

    SPRITE_PALETTE[1] = RGB15(31,0,0);	// full red
    SPRITE_PALETTE[2] = RGB15(28,28,0);	// bright yellow

    while(1) {

        scanKeys();

        /* Slow down the rotate if the left trigger is pressed
         * I'd like to do a fixed-point here, but I don't know how */
        float inc = (keysHeld() & KEY_L)? 0.05 : 0.3;

        if(keysHeld() & KEY_LEFT)
            angle += degreesToAngle(inc);
        if(keysHeld() & KEY_RIGHT)
            angle -= degreesToAngle(inc);

        //-------------------------------------------------------------------------
        // Set the first rotation/scale matrix
        //
        // There are 32 rotation/scale matricies that can store sprite rotations
        // Any number of sprites can share a sprite rotation matrix or each sprite
        // (up to 32) can utilize a seperate rotation. Because this sprite is doubled
        // in size we have to adjust its position by subtracting half of its height and
        // width (20 - 16, 20 - 16, )
        //-------------------------------------------------------------------------
        oamRotateScale(&oamMain, 0, angle, intToFixed(1, 8), intToFixed(1, 8));

        oamSet(&oamMain, //main graphics engine context
               0,           //oam index (0 to 127)
               20 - 16, 20 - 16,   //x and y pixle location of the sprite
               0,                    //priority, lower renders last (on top)
               0,					  //this is the palette index if multiple palettes or the alpha value if bmp sprite
               SpriteSize_32x32,
               SpriteColorFormat_256Color,
               gfx,                  //pointer to the loaded graphics
               0,                  //sprite rotation/scale matrix index
               true,               //double the size when rotating?
               false,			//hide the sprite?
               false, false, //vflip, hflip
               false	//apply mosaic
              );

        //-------------------------------------------------------------------------
        // Because the sprite below has size double set to false it can never be larger than
        // 32x32 causing it to clip as it rotates.
        //-------------------------------------------------------------------------
        oamSet(&oamMain, //main graphics engine context
               1,           //oam index (0 to 127)
               204, 20,   //x and y pixle location of the sprite
               0,                    //priority, lower renders last (on top)
               0,					  //this is the palette index if multiple palettes or the alpha value if bmp sprite
               SpriteSize_32x32,
               SpriteColorFormat_256Color,
               gfx,                  //pointer to the loaded graphics
               0,                  //sprite rotation/scale matrix index
               false,               //double the size when rotating?
               false,			//hide the sprite?
               false, false, //vflip, hflip
               false	//apply mosaic
              );
        swiWaitForVBlank();


        oamUpdate(&oamMain);
    }

    return 0;
}