コード例 #1
0
ファイル: robo.c プロジェクト: carlmartus/ld30_multiverse
static void batFrame(Monster *bat, float fr) {

	if ((bat->flags & FLAG_ALIVE) == 0) {
		return;
	}

	float dist;
	esVec2f v0;

	switch (bat->state) {
		default :
		case BAT_FLY :
			bat->loc = towards(bat->loc, dudeLoc, 2.0f*fr, &dist);

			if (dist > 0.1f && dist < 5.0f) {
				bat->state = BAT_CHARGE;
				bat->counter = 0.5f;
				soundPlay(SOUND_FLAP);
			}
			break;

		case BAT_CHARGE :
			if (bat->counter < 0.0f) {
				v0.x = dudeLoc.x - bat->loc.x;
				v0.y = dudeLoc.y - bat->loc.y;
				bat->bat.charge = normalize(v0);
				bat->state = BAT_ATTACK;
				bat->counter = 0.8f;
				bat->armor = 0;
				soundPlay(SOUND_BAT1);
			}
			break;

		case BAT_ATTACK :
		case BAT_BACK :

			bat->loc.x += bat->bat.charge.x*8.5f*fr;
			bat->loc.y += bat->bat.charge.y*8.5f*fr;

			if (bat->state == BAT_ATTACK) {
				if (dudeTouching(bat->loc, 0.6f)) {
					dudeHurt(20);

					bat->bat.charge.x = -bat->bat.charge.x*0.5f;
					bat->bat.charge.y = -bat->bat.charge.y*0.5f;
					bat->state = BAT_BACK;
					bat->armor = 2;
					bat->counter = 0.4f;
				}
			}

			if (bat->counter < 0.0f) {
				bat->state = BAT_FLY;
				bat->armor = 2;
			}
			break;
	}
}
コード例 #2
0
ファイル: dude.c プロジェクト: carlmartus/ld30_multiverse
void dudeHurt(int hit) {
	if (hp > 0 && hp - hit <= 0) {
		bloodHit(HIT_SMALL, locX, locY);
		bloodHit(HIT_SMALL, locX, locY);
		soundPlay(SOUND_DUDEHURT1);
	} else if (hp > 0) {
		soundPlay(SOUND_DUDEHURT2);
	}
	hp -= hit;
	bloodHit(HIT_SMALL, locX, locY);
	stateOutput();
}
コード例 #3
0
ファイル: table.c プロジェクト: zizoumgs/Aman
static void tableTesData(GtkWidget* widget,gpointer data){
//	databaseRubahFileMusic();
//	return;
	gboolean status= FALSE;
	dataToSend_* dataTo = (dataToSend_*)data ;
	char* data_ = dataTo->file;
	gint  id    = dataTo->id;
	GValueArray* varr = 	g_value_array_new (-1);

	GValue a = {0};
	g_assert (!G_VALUE_HOLDS_STRING (&a));
	
	g_value_init (&a, G_TYPE_INT);
	g_value_set_int (&a, id);	
//	g_print("%i\n", g_value_get_int (&a) );
	
	varr 				=	g_value_array_append(varr,&a);
	GValueArray* hasil 	= databaseGetDatasFromDb("select  alarm from isi where id = ?", varr,&status);
	GValue *tmp 		= g_value_array_get_nth (hasil	,0 );

	soundPlay( g_value_get_string(tmp)  , 1);	
	//clean
	g_value_array_free (varr);
	g_value_array_free (hasil);
}
コード例 #4
0
ファイル: dude.c プロジェクト: carlmartus/ld30_multiverse
static void fireDude(float fr) {
	if (elapse > nextFire) {
		//esLog(ES_INFO, "%f %f | %f %f", locX, aimX, locY, aimY);
		roboHit(locX+aimX, locY+aimY, FIRE_DAMAGE);
		nextFire = elapse + FIRE_DELAY;
		soundPlay(SOUND_SHOT);
	}
}
コード例 #5
0
ファイル: main.c プロジェクト: ninux/mc
/**
 * main program
 * 
 * This program reads D0-D2 of the port G and write it to D0-D2 of port F.
 */  
void main(void) 
{ 
  const char * soundFiles[] = {sound1, sound2, sound3, sound4, sound5};
  uint8 count = sizeof(soundFiles) / sizeof(soundFiles[0]); 
  
  uint8 playIndex = 0;
  
  PTDDD_PTDDD2 = 1;
    
  initPorts();				// Ports konfigurieren
    
  ifrRxFrontInit();			// init IR receiver
  
  initTimer();				// Timer init
  init_timer1_ch0();		// init channel 1
  
  EnableInterrupts;			// Interrupts aktivieren
    
  for(;;) 
  {      
    switch (ifrRxFrontGetKey())
    //switch (ifrRxRearGetKey())
    {     
      case 'S' : // play/pause
        soundTooglePlayPause();
        break;
        
      case 'W' : // play next melody
        playIndex++;
        if (playIndex >= count) playIndex = 0;
        soundPlay(soundFiles[playIndex]);
        break;
      
      case 'T' : // play previous melody
        if (playIndex == 0) playIndex = count;
        playIndex--;
        soundPlay(soundFiles[playIndex]);
        break; 
      
      case '+' :  break;
      case '-' : soundStop();  break;
    }
  }
}
コード例 #6
0
ファイル: music.cpp プロジェクト: MathiasBartl/scummvm
void SciMusic::soundResume(MusicEntry *pSnd) {
	if (pSnd->pauseCounter > 0)
		pSnd->pauseCounter--;
	if (pSnd->pauseCounter != 0)
		return;
	if (pSnd->status != kSoundPaused)
		return;
	if (pSnd->pStreamAud) {
		_pMixer->pauseHandle(pSnd->hCurrentAud, false);
		pSnd->status = kSoundPlaying;
	} else {
		soundPlay(pSnd);
	}
}
コード例 #7
0
ファイル: boss.c プロジェクト: Jools64/IWBTG-C-Engine
void bossControllerUpdate(Controller* c, Entity* e, Iwbtg* iw, float dt)
{
    ControllerBoss* b = &c->boss;
            
    if(b->triggered)
    {
        if(!b->initialized)
        {
            b->initialized = true;
            
            // Take the first action in the queue
            if(!bossIsActionQueueEmpty(b))
            {
                b->actionQueue[0].initialized = false;
                bossAddActiveAction(b, &b->actionQueue[0]);
            }
        }

        for(int i = 0; i < MAX_ACTIONS_PER_BOSS; ++i)
        {
            BossAction* a = b->activeActions[i];
            if(a == 0)
                continue;
            
            a->time += dt;
            
            switch(a->type)
            {
                case BossActionType_wait:
                    if(a->time > a->wait.time)
                        bossRemoveActiveAction(b, a);
                    break;
                    
                case BossActionType_move:
                    if(!a->initialized)
                    {
                        a->move.start = e->position;
                        a->initialized = true;
                    }
                    
                    e->position = vector2fLerp(a->move.start, a->move.destination, inOutEase(clamp(a->time / a->move.time, 0, 1)));
                    
                    if(a->time >= a->move.time)
                        bossRemoveActiveAction(b, a);
                    break;
                    
                case BossActionType_projectileBurst: {
                    
                    BossActionProjectileBurst* pb = &a->projectileBurst;
                    
                    if(!a->initialized)
                        pb->shotTimer = 0;
                    
                    pb->shotTimer += dt;
                    
                    // TODO: do something a little smarter here so that
                    //       if two shots occur on the same frame, their positions
                    //       are correctly seperated from each other.
                    if(pb->shotTimer > pb->interval)
                    {
                        soundPlay(assetsGetSound(&iw->game, "bossShoot"), 0.2);
                        while(pb->shotTimer > pb->interval)
                        {
                            for(int i = 0; i < pb->count; ++i)
                            {
                                Entity* p = createEntity(iw, pb->projectileEntityType, 
                                    e->position.x + (e->sprite.size.x / 2), e->position.y + (e->sprite.size.y / 2));
                                p->position.x -= (p->sprite.size.x / 2);
                                p->position.y -= (p->sprite.size.y / 2);
                                p->velocity = speedDirectionToVector2f(pb->speed, pb->direction + ((360 / pb->count) * i));
                                
                            }
                            
                            pb->direction += pb->rotation;
                            pb->shotTimer -= pb->interval;
                        }
                    }
                    
                    if(a->time > pb->interval * pb->repeat)
                        bossRemoveActiveAction(b, a);
                } break;
                    
                case BossActionType_playMusic:
                    musicPlay(a->playMusic.music, 0.7, &iw->game);
                    bossRemoveActiveAction(b, a);
                    break;
                    
                case BossActionType_projectileRandomSpray:
                    if(a->time > a->projectileRandomSpray.time)
                        bossRemoveActiveAction(b, a);
                    
                    BossActionProjectileRandomSpray* pb = &a->projectileRandomSpray;
                    
                    Entity* p = createEntity(iw, pb->projectileEntityType, 
                                    e->position.x + (e->sprite.size.x / 2), e->position.y + (e->sprite.size.y / 2));
                    p->position.x -= (p->sprite.size.x / 2);
                    p->position.y -= (p->sprite.size.y / 2);
                    pb->previousDirection += (12 * 7);
                    //pb->previousDirection = (randomfBetween(0, 360));
                    p->velocity = speedDirectionToVector2f(pb->speed, pb->previousDirection + randomfBetween(-12, 12));
                    
                    pb->soundCounter++;
                    if(pb->soundCounter > 1)
                    {
                        pb->soundCounter = 0;
                        soundPlay(assetsGetSound(&iw->game, "bossShoot"), 0.1);
                    }
                    break;
                    
                case BossActionType_projectileAimed: {
                    BossActionProjectileAimed* pa = &a->projectileAimed;
                    Entity* p = createEntity(iw, pa->projectileEntityType, 
                                e->position.x + (e->sprite.size.x / 2), e->position.y + (e->sprite.size.y / 2));
                    p->position.x -= (p->sprite.size.x / 2);
                    p->position.y -= (p->sprite.size.y / 2);
                    
                    float direction = vector2fDirection(
                        vector2fAdd(e->position, v2f(e->sprite.size.x / 2, e->sprite.size.y / 2)),
                        vector2fAdd(iw->player.position, v2f(16, 16)))
                            * (180 / PI);
                    
                    p->velocity = speedDirectionToVector2f(pa->speed, direction);
                    
                    soundPlay(assetsGetSound(&iw->game, "bossShoot"), 0.1);
                    
                    bossRemoveActiveAction(b, a);
                } break;
                   
                default:
                    bossRemoveActiveAction(b, a);
                    printf("Warning: Tried to perform boss action that has not been implemented!\n");
                    break;
            }
            
            if(!a->initialized)
                a->initialized = true;
            
        }
        
        // TODO: Make this into a loop so multiple actions can start per frame.
        if(!bossIsActionBlocking(b) && iw->state != GameState_gameOver)
            bossNextAction(b);
        
        if(b->health <= 0)
        {
            if(iw->boss == e)
                iw->boss = 0;
            createEntity(iw, EntityType_warp, 480 - 64, 540 - 256);
            musicPlayOnce(assetsGetMusic(&iw->game, "bossDefeatedMusic"), 0.7, &iw->game);
            destroyEntity(e);
        }
    }
}
コード例 #8
0
ファイル: RAINCORE.C プロジェクト: StepanHrbek/RAIN
int RainCommand(int command,int param1,int param2,int param3,
                 char *filename,int fileofs,int filesize)
{
    int result=0;
    int i;
    if (command==CMD_PLAY)
        _bprintf(hint,hintlen,"%s,%i,%i",filename,fileofs,filesize);
    else
        _bprintf(hint,hintlen,"%i(%i,%i)",command,param1,param2);
    switch (command)
    {
        case CMD_NONE:
            RainFreeStopped();
            MIDASpoll();
            break;
        case CMD_PLAY:
            rainhandles++;
            if (sounds<SOUNDS)
            {
                sound[sounds].type=None;
                sound[sounds].rainhandle=rainhandles;
                sound[sounds].datahandle=0;
                sound[sounds].playhandle=0;
                soundPlay(&sound[sounds],filename,fileofs,filesize,param1);
                soundSetVolume(&sound[sounds],param2);
                soundSetPanning(&sound[sounds],param3);
                sounds++;
            }
            result=rainhandles;
            break;
        case CMD_VOL:
            for(i=0;i<sounds;i++)
              if(sound[i].rainhandle==param1)
              {
                  soundSetVolume(&sound[i],param2);
              }
            break;
        case CMD_PAN:
            for(i=0;i<sounds;i++)
              if(sound[i].rainhandle==param1)
              {
                  soundSetPanning(&sound[i],param2);
              }
            break;
        case CMD_STOP:
            for(i=0;i<sounds;i++)
              if(sound[i].rainhandle==param1)
              {
                  soundStop(&sound[i]);
                  sound[i--]=sound[--sounds];
              }
            break;
        case CMD_AMPLIFY:
            MIDASsetAmplification(AMPLIFY_ALL*AMPLIFY_MP3*param1);
            break;
        default:
            _bprintf(errBuf,errBufLen," Unknown command %i.",command);
            errAdd(errBuf);
    }
    MIDASreportErr();
    return result;
}
コード例 #9
0
void OptionsTabSound::previewSoundEvent(QAbstractButton* b)
{
	soundPlay(play_buttons_[b]->text());
}
コード例 #10
0
ファイル: game.c プロジェクト: mwk9/2D-game-programming
int main(int argc, char * argv[])
{
    /*variable declarations,
	remember, all v. decls. are at the beginning of each function in C*/
    int done = 0;
    const Uint8 * keys;
    
    int mx,my;
    float mf = 0;
	float guyFrame = 0;
	Sprite *thing;
	Sprite *thing2;
	Sprite *guyx;
	Sprite *galSprite;
	Sprite *mehSprite;
	int controllerConnected = 0;
	/*Sprite *myTileMap;
	const int level[] = 
	{ 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 
	  3, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 2, 
	  2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3,
	  3, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 2,
	  2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 
	  3, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 2,
	  2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 
	  3, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 2,
	  2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 3,
	  3, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 2 };*/
	FILE *tilemapFile;
	int tileClicked = 0;
	int p = 0;

    Vector4D mouseColor = {100,255,255,200};
	Vector2D flipVert = { 0, 1 };
	Vector2D scaleDown = { 0.5, 0.5 };
	Vector2D scaleUp = { 2, 2 };
	Vector2D scaleHalfUp = { 1.5, 1.5 };
	//IntNode *myLL = IntNode_init(5);
	/*Student *person;*/
	/*Entity *guy, *testDude;
	Entity *en = NULL;
	Entity *biggo = NULL;
	FILE *infile;
	Entity *fileLoadedDude = NULL;
	Entity *fileLoadedDude2 = NULL;*/
	SDL_Event e;
	SDL_Surface *icon = SDL_LoadBMP("images/sprites/guy16x.bmp");

	FILE *bandFile;
	FILE *levelFile;

	Sound *NJITtheme = NULL;
	Sound *snareDrum = NULL;
	Sound *flute = NULL;
	Sound *trumpet = NULL;
	Sound *altoSax = NULL;
	Sound *tenorSax = NULL;
	Uint32 musicPlaying = 0;
	//Sound *clap = NULL;
	Sound *cdEject = NULL;

	/*TTF_Font *PencilFont = TTF_OpenFont("fonts/Pencil.ttf", 24);
	if (!PencilFont)
	{
		slog("Error loading font");
	}
	SDL_Color colorBlack = { 255, 255, 255, 255 };
	SDL_Surface *surfaceMessage = TTF_RenderText_Solid(PencilFont, "placeholdha", colorBlack);
	SDL_Texture *message = SDL_CreateTextureFromSurface(gf2d_graphics_get_renderer, surfaceMessage);
	Sprite *textBox;*/
	TTF_Font *PencilFont;
	SDL_Color colorBlack = { 0, 0, 0, 255 };
	SDL_Surface *surfaceMessage;
	SDL_Texture *message;
	Sprite *textBox;
	TextDisplay *nameText;
	int texW = 0, texH = 0;
	SDL_Rect rect = { 65, 630, 0, 0 };

	SDL_Surface *instrumentSurface;
	SDL_Texture *instrumentTexture;
	int instX = 0, instY = 0;
	SDL_Rect instrumentRect = { 65, 660, 0, 0 };

	Uint8 playButtonPressed = 0;

	srand(time(NULL));

    /*program initializtion*/
    init_logger("dmdwa.log");
    slog("---==== BEGIN ====---");
    gf2d_graphics_initialize(
        "Drum Majors Don't Wear Aussies",
        1200,
        720,
        1200,
        720,
        vector4d(0,0,0,255),
        0,
		icon);
	//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); //This line makes images render crisp instead of blurry
    gf2d_graphics_set_frame_delay(16);
    gf2d_sprite_init(1024);
	entitySystemInit(1024);
	audioSystemInit(50, 10, 2, 0, 0, 0);
	soundSystemInit(25);
	text_system_init(50);
    SDL_ShowCursor(SDL_DISABLE);
	TTF_Init();
	//fileLoadedDude = entityNew();

	//derp
	//slog("%i", myLL->data);
    
    /*demo setup*/
    //backgroundSprite = gf2d_sprite_load_image("images/backgrounds/bg_flat.png");
	//textBox = gf2d_sprite_load_image("images/backgrounds/bg_flat.png");
    mouseSprite = gf2d_sprite_load_all("images/pointer.png",32,32,16);
	mouse = mouseSprite;
	//thing = gf2d_sprite_load_all("images/sprites/test_dude.png", 32, 32, 1);
	//thing2 = gf2d_sprite_load_all("images/sprites/test_dude3.png", 64, 64, 1);
	//guyx = gf2d_sprite_load_all("images/sprites/guy32x.png", 32, 32, 2);
	//galSprite = gf2d_sprite_load_all("images/sprites/gal32x.png", 32, 32, 2);
	//mehSprite = gf2d_sprite_load_all("images/sprites/meh32x.png", 32, 32, 2);
	//musicSheet = gf2d_sprite_load_image("images/gui/music_sheet.png");
	controllerIcon = gf2d_sprite_load_all("images/gui/controller64x.png", 64, 64, 1);
	//myTileMap = gf2d_sprite_load_all("images/field_tiles.png", 64, 64, 2);
	//person = student("Test", "Sex", thing2);
	//slog("Initializing student %s", person->name);
	/*guy = entityNew();
	strncpy(guy->name, "McBandgeek", 32);
	guy->mySprite = guyx;
	guy->scale = scaleUp;
	guy->currentFrame = 0;
	guy->minFrame = 0;
	guy->maxFrame = 2;
	guy->position = vector2d(300, 100);
	guy->update = move;
	guy->myInstrument = Instrument_Tenor_Saxophone;
	guy->instrumentSprite = gf2d_sprite_load_all("images/sprites/instrument_tenor_sax.png", 32, 32, 1);
	guy->boundingBox = rect_new(guy->position.x, guy->position.y, 64, 64);
	testDude = NULL;
	//SDL_SetTextureColorMod(thing2->texture, 100, 60, 0);
	infile = fopen("def/dude.dude", "r");
	fileLoadedDude = entityNew();
	fileLoadedDude = entityLoadFromFile(infile, fileLoadedDude);
	fclose(infile);
	//fileLoadedDude->mySprite = mehSprite;
	fileLoadedDude->instrumentSprite = gf2d_sprite_load_all(&fileLoadedDude->instrumentSpriteFilePath, 32, 32, 1);
	fileLoadedDude->position = vector2d(64, 64);
	fileLoadedDude->boundingBox = rect_new(fileLoadedDude->position.x, fileLoadedDude->position.y, 64, 64);
	fileLoadedDude->scale = vector2d(2, 2);
	fileLoadedDude->currentFrame = 0;
	fileLoadedDude->minFrame = 0;
	fileLoadedDude->maxFrame = 2;
	fileLoadedDude->currentPosition = 19;
	slog("the thing made has name: %s", &fileLoadedDude->name);

	infile = fopen("def/dude2.dude", "r");
	fileLoadedDude2 = entityNew();
	fileLoadedDude2 = entityLoadFromFile(infile, fileLoadedDude2);
	fclose(infile);
	fileLoadedDude2->instrumentSprite = gf2d_sprite_load_all(&fileLoadedDude2->instrumentSpriteFilePath, 32, 32, 1);
	fileLoadedDude2->position = vector2d(128, 64);
	fileLoadedDude2->boundingBox = rect_new(fileLoadedDude2->position.x, fileLoadedDude2->position.y, 64, 64);
	fileLoadedDude2->scale = vector2d(2, 2);
	fileLoadedDude2->currentFrame = 0;
	fileLoadedDude2->minFrame = 0;
	fileLoadedDude2->maxFrame = 2;
	fileLoadedDude2->currentPosition = 20;*/

	tile_map = tilemap_init();
	load_level("def/level/mainMenu.txt", 0);

	//textBox->texture = message;

	//Trying to load a tilemap from file
	//tilemapFile = fopen("def/level/field_0.tilemap", "r");
	//tilemap_load_from_file(tilemapFile, tile_map);
	//fclose(tilemapFile);
	//slog("tilewidth: (%i) tileheight: (%i) tperline: (%i) filepath: (...) width: (%i) height: (%i) xPos: (%i) yPos: (%i)", tile_map->tileWidth,	tile_map->tileHeight, tile_map->tilesPerLine, tile_map->width, tile_map->height, tile_map->xPos, tile_map->yPos);
	//slog("do i have a sprite? %i", tile_map->tilemapSprite != NULL);
	//tile_map->space[19] = 1;
	//tile_map->space[20] = 1;
	/*slog("tile pq start");
	while (tile_map->tiles_head != NULL)
	{
		p = pq_delete(tile_map->tiles_head, tile_map->tiles_tail);
		if (p == NULL)
		{
			break;
		}
		slog("Removing (%d) from pq", p);
	}
	slog("tile pq end");*/
	/*slog("start array");
	for (p = 0; p < tile_map->width * tile_map->height; p++)
	{
		if (p == 512)
		{
			slog("end of array");
		}
		else if (tile_map->tiles[p] == -1)
		{
			slog("found a -1");
		}
		else
		{
			slog("tiles at index (%i) is (%i)", p, tile_map->tiles[p]);
		}
	}
	slog("end array");*/

	//Trying to load all entities from a file
	//bandFile = fopen("def/_myBand.band", "r");
	//entityLoadAllFromFile(bandFile);
	//fclose(bandFile);

	//Load sounds
	//NJITtheme = soundNew("music/bg/NJIT.ogg");
	//NJITtheme = soundLoad("music/bg/NJIT.ogg", 12.0f, 3);
	//slog("do i have a sound? %i", NJITtheme->sound != NULL);
	//soundPlay(NJITtheme, 1, 0, 0, 0);
	//Mix_VolumeChunk(NJITtheme->sound, MIX_MAX_VOLUME); //Use this to change volume on the fly!
	//clap = soundLoad("music/sfx/clap.ogg", 5.0f, 1);
	cdEject = soundNew();
	cdEject = soundLoad("music/sfx/cd_play.ogg", 18.0f, 0);

	snareDrum = soundNew("music/bg/meeeeh-Snare_Drum.ogg");
	snareDrum = soundLoad("music/bg/meeeeh-Snare_Drum.ogg", 12.0f, Instrument_Snare_Drum);
	flute = soundNew("music/bg/meeeeh-Flute.ogg");
	flute = soundLoad("music/bg/meeeeh-Flute.ogg", 12.0f, Instrument_Flute);
	trumpet = soundNew("music/bg/meeeeh-Bb_Trumpet.ogg");
	trumpet = soundLoad("music/bg/meeeeh-Bb_Trumpet.ogg", 12.0f, Instrument_Trumpet);
	altoSax = soundNew("music/bg/meeeeh-Alto_Saxophone.ogg");
	altoSax = soundLoad("music/bg/meeeeh-Alto_Saxophone.ogg", 12.0f, Instrument_Alto_Saxophone);
	tenorSax = soundNew("music/bg/meeeeh-Tenor_Saxophone.ogg");
	tenorSax = soundLoad("music/bg/meeeeh-Tenor_Saxophone.ogg", 12.0f, Instrument_Tenor_Saxophone);

	//soundPlay(snareDrum, -1, 1, snareDrum->defaultChannel, 0);
	//soundPlay(flute, -1, 1, flute->defaultChannel, 0);
	//soundPlay(trumpet, -1, 1, trumpet->defaultChannel, 0);
	//soundPlay(altoSax, -1, 1, altoSax->defaultChannel, 0);
	//soundPlay(tenorSax, -1, 1, tenorSax->defaultChannel, 0);

	//text testing stuff
	PencilFont = TTF_OpenFont("fonts/Pencil.ttf", 36);
	if (!PencilFont)
	{
		slog("Error loading font");
	}
	surfaceMessage = TTF_RenderText_Solid(PencilFont, "None selected", colorBlack);
	message = SDL_CreateTextureFromSurface(gf2d_graphics_get_renderer(), surfaceMessage);
	SDL_QueryTexture(message, NULL, NULL, &texW, &texH);
	rect.w = texW;
	rect.h = texH;
	nameText = text_new(PencilFont, "placeholda", colorBlack);
	//slog("nameText inuse (%i)", nameText->inUse);

	instrumentSurface = TTF_RenderText_Solid(PencilFont, "", colorBlack);
	instrumentTexture = SDL_CreateTextureFromSurface(gf2d_graphics_get_renderer(), instrumentSurface);
	SDL_QueryTexture(instrumentTexture, NULL, NULL, &instX, &instY);
	instrumentRect.w = instX;
	instrumentRect.h = instY;

	cd = entityNew();
	cd->mySprite = gf2d_sprite_load_all("images/gui/cd.png", 128, 128, 1);
	cd->position = vector2d(0, 0);
	cd->scale = vector2d(2, 2);
	cd->boundingBox = rect_new(cd->position.x, cd->position.y, 128, 128);

	playButton = entityNew();
	playButton->mySprite = gf2d_sprite_load_image("images/gui/play.png");
	playButton->position = vector2d(64, 256);
	strncpy(playButton->name, "playButton", MAX_CHARS);
	playButton->boundingBox = rect_new(playButton->position.x, playButton->position.y, playButton->mySprite->frame_w, playButton->mySprite->frame_h);
	

    /*main game loop*/
    while(!done)
    {
        SDL_PumpEvents();   // update SDL's internal event structures
        keys = SDL_GetKeyboardState(NULL); // get the keyboard state for this frame
        /*update things here*/
        SDL_GetMouseState(&mx,&my);
		SDL_PollEvent(&e);
        mf+=0.1;
        if (mf >= 16.0)mf = 0;        
		guyFrame += 0.05;
		if (guyFrame >= 2.0)guyFrame = 0;
        
        gf2d_graphics_clear_screen();// clears drawing buffers
        // all drawing should happen betweem clear_screen and next_frame
		//backgrounds drawn first
		if (backgroundSprite)
		{
			gf2d_sprite_draw_image(backgroundSprite, vector2d(0, 0));
		}

		//Me! trying to add a sprite
		/*tilemap_draw(
			myTileMap,
			level,
			18,
			10,
			0,
			0);*/
		if (tile_map)
		{
			tilemap_draw_from_data(tile_map);
		}

		//gf2d_sprite_draw(thing, vector2d(100, 10), &scaleUp, NULL, NULL, NULL, NULL, 0);
		//gf2d_sprite_draw(thing, vector2d(100, 10), NULL, NULL, NULL, NULL, NULL, 0);
		//gf2d_sprite_draw(guy->mySprite, guy->position, &(guy->scale), NULL, NULL, NULL, NULL, 0);

		/*if (keys[SDL_SCANCODE_W])
		{
			(*guy->update)(guy, vector2d(0, -2));
		}
		if (keys[SDL_SCANCODE_A])
		{
			(*guy->update)(guy, vector2d(-2, 0));
		}
		if (keys[SDL_SCANCODE_S])
		{
			(*guy->update)(guy, vector2d(0, 2));
		}
		if (keys[SDL_SCANCODE_D])
		{
			(*guy->update)(guy, vector2d(2, 0));
		}*/
		//guy->currentFrame = guyFrame;
		//fileLoadedDude->currentFrame = guyFrame;

		/*
		//create an entity if it doesn't exist
		if (keys[SDL_SCANCODE_O] && testDude == NULL)
		{
			testDude = entityNew();
			testDude->mySprite = thing;
			testDude->position = vector2d(500, 500);
			testDude->update = move;
		}
		//if it exists, call its update function
		//slog("%i", testDude != NULL);
		if (testDude != NULL)
		{
			//(*testDude->update)(testDude, vector2d(1, 1));
			gf2d_sprite_draw(testDude->mySprite, testDude->position, NULL, NULL, NULL, NULL, NULL, 0);
		}
		//delete it from memory
		if (keys[SDL_SCANCODE_P] && testDude != NULL)
		{
			entityDelete(testDude);
		}*/
		/*if (keys[SDL_SCANCODE_L] && biggo == NULL)
		{
			biggo = entityNew();
			biggo->mySprite = guyx;
			biggo->position = vector2d(10, 10);
			biggo->scale = vector2d(25, 25);
			biggo->inUse = 1;
			biggo->currentFrame = 0;
			biggo->minFrame = 0;
			biggo->maxFrame = 2;
			biggo->update = move;
			biggo->velocity = vector2d(0.5f, 0.5f);
			biggo->acceleration = vector2d(0.5f, 0.5f);
			biggo->myInstrument = Instrument_Flute;
			biggo->instrumentSprite = gf2d_sprite_load_all("images/sprites/instrument_flute.png", 32, 32, 1);
		}
		if (biggo != NULL)
		{
			//entityDraw(biggo);
			(*biggo->update)(biggo, vector2d(0.5f, 0.5f));
			//biggo->currentFrame = guyFrame;
		}
		if (biggo != NULL && biggo->inUse == 1 && keys[SDL_SCANCODE_P])
		{
			biggo->inUse = 0;
			entityDelete(biggo);
			biggo = NULL;
		}
		if (keys[SDL_SCANCODE_O] && testDude == NULL)
		{
			//slog("Let's make a new thing!");
			testDude = entityNew();
			testDude->mySprite = mehSprite;
			testDude->position = vector2d(200, 200);
			testDude->scale = scaleUp;
			testDude->inUse = 1;
			testDude->currentFrame = 0;
			testDude->minFrame = 1;
			testDude->maxFrame = 3;
			testDude->update = move;
			testDude->instrumentSprite = gf2d_sprite_load_all("images/sprites/instrument_tuba.png", 32, 32, 1);
		}
		if (testDude != NULL)
		{
			//gf2d_sprite_draw(testDude->mySprite, testDude->position, &(testDude->scale), NULL, NULL, NULL, NULL, 0);
			//entityDraw(testDude);
			(*testDude->update)(testDude, vector2d(1, 1));
			//testDude->currentFrame = guyFrame;
		}
		if (testDude != NULL && testDude->inUse == 1 && keys[SDL_SCANCODE_P])
		{
			testDude->inUse = 0;
			entityDelete(testDude);
			testDude = NULL;
		}
		if (keys[SDL_SCANCODE_M] && en == NULL)
		{
			en = entityNew();
			en->mySprite = galSprite;
			en->position = vector2d(300, 500);
			en->scale = vector2d(1,1);
			en->inUse = 1;
			en->currentFrame = 0;
			en->minFrame = 0;
			en->maxFrame = 4;
			en->update = move;
			en->instrumentSprite = gf2d_sprite_load_all("images/sprites/instrument_clarinet.png", 32, 32, 1);
			//soundPlay(clap, 0, clap->volume, clap->defaultChannel, 0);
		}
		if (en != NULL && en->inUse == 1)
		{
			//entityDraw(en);
			(*en->update)(en, vector2d(1, -1));
			//en->currentFrame = guyFrame;
		}
		if (en != NULL && en->inUse == 1 && keys[SDL_SCANCODE_P])
		{
			en->inUse = 0;
			entityDelete(en);
			en = NULL;
		}
		if (en != NULL && en->inUse == 1 && en->position.x >= 400)
		{
			en->inUse = 0;
			entityDelete(en);
			en = NULL;
		}*/

		/*gf2d_sprite_draw(
			guyx,
			vector2d(64, 64),
			&scaleUp,
			NULL,
			NULL,
			NULL,
			NULL,
			0
		);
		gf2d_sprite_draw(
			galSprite,
			vector2d(128, 64),
			&scaleUp,
			NULL,
			NULL,
			NULL,
			NULL,
			0
		);
		gf2d_sprite_draw(
			mehSprite,
			vector2d(192, 64),
			&scaleUp,
			NULL,
			NULL,
			NULL,
			NULL,
			0
		);*/

		//entityDraw(fileLoadedDude);

		entityDrawAll();
		entityUpdateAll();
		entityIncrementCurrentFrameAll();

		if (pickedUp != NULL)
		{
			draw_line(vector2d(pickedUp->position.x + pickedUp->mySprite->frame_w, pickedUp->position.y + pickedUp->mySprite->frame_h),
						vector2d(mx, my), COLOR_RED);
		}

		switch (e.type)
		{
		case SDL_QUIT:
			done = 1;
			break;
		case SDL_MOUSEBUTTONDOWN:
			if (e.button.button == SDL_BUTTON_RIGHT)
			{
				tileClicked = tilemap_find_tile(mx, my, tile_map);
				if (tileClicked >= 0 && pickedUp != NULL)
				{
					if (tile_map->space[tileClicked] == 0)
					{
						slog("poop");
						tile_map->space[pickedUp->currentPosition] = 0;
						tile_map->space[tileClicked] = 1;
						pickedUp->currentPosition = tileClicked;
						mouse = mouseSprite;
						pickedUp->position.x = (mx - tile_map->xPos) / tile_map->tileWidth * (tile_map->tileWidth);
						pickedUp->position.y = (my - tile_map->yPos) / tile_map->tileHeight * (tile_map->tileHeight);
						pickedUp = NULL;
						surfaceMessage = TTF_RenderText_Solid(PencilFont, "None selected", colorBlack);
						message = SDL_CreateTextureFromSurface(gf2d_graphics_get_renderer(), surfaceMessage);
						SDL_QueryTexture(message, NULL, NULL, &texW, &texH);
						rect.w = texW;
						rect.h = texH;

						instrumentSurface = TTF_RenderText_Solid(PencilFont, "", colorBlack);
						instrumentTexture = SDL_CreateTextureFromSurface(gf2d_graphics_get_renderer(), instrumentSurface);
						SDL_QueryTexture(instrumentTexture, NULL, NULL, &instX, &instY);
						instrumentRect.w = instX;
						instrumentRect.h = instY;
					}
				}
			}
			else if (e.button.button == SDL_BUTTON_LEFT)
			{
				if (playButton != NULL)
				{
					if (point_in_rect(mx, my, playButton->boundingBox))
					{
						//slog("hit da BUTT");
						playButtonPressed = 1;
						soundPlay(cdEject, 0, 5.0f, -1, 0);
					}
				}
			}
			break;
		case SDL_MOUSEBUTTONUP:
			if (e.button.button == SDL_BUTTON_LEFT)
			//if (mousePress(&e.button))
			{
				/*if (point_in_rect(mx, my, guy->boundingBox))
				{
					slog("collision with guy (%s)", guy->name);
				}
				if (point_in_rect(mx, my, fileLoadedDude->boundingBox))
				{
					slog("collision with guy (%s)", &fileLoadedDude->name);
					if (pickedUp == NULL)
					{
						pickedUp = fileLoadedDude;
						mouse = fileLoadedDude->mySprite;
					}
				}
				if (point_in_rect(mx, my, fileLoadedDude2->boundingBox))
				{
					slog("collision with guy (%s)", &fileLoadedDude2->name);
					if (pickedUp == NULL)
					{
						pickedUp = fileLoadedDude2;
						mouse = fileLoadedDude2->mySprite;
					}
				}*/

				collision = entityCheckCollisionInAll(mx, my);
				if (collision != NULL && collision->myInstrument != Instrument_Unassigned)
				{
					slog("collision with guy (%s)", &collision->name);
					if (pickedUp == NULL)
					{
						pickedUp = collision;
						mouse = collision->mySprite;
						surfaceMessage = TTF_RenderText_Solid(PencilFont, &pickedUp->name, colorBlack);
						message = SDL_CreateTextureFromSurface(gf2d_graphics_get_renderer(), surfaceMessage);
						SDL_QueryTexture(message, NULL, NULL, &texW, &texH);
						rect.w = texW;
						rect.h = texH;

						instrumentSurface = TTF_RenderText_Solid(PencilFont, entityGetInstrumentName(pickedUp), colorBlack);
						instrumentTexture = SDL_CreateTextureFromSurface(gf2d_graphics_get_renderer(), instrumentSurface);
						SDL_QueryTexture(instrumentTexture, NULL, NULL, &instX, &instY);
						instrumentRect.w = instX;
						instrumentRect.h = instY;
					}
				}

				//if (point_in_rect(mx, my, tile_map->boundingBox))
				tileClicked = tilemap_find_tile(mx, my, tile_map);
				if (tileClicked >= 0)
				{
					//slog("collided with tilemap on tile (%i), occupied (%i)", tileClicked, tile_map->space[tileClicked]);
				}
			}
			break;
		case SDL_CONTROLLERDEVICEADDED:
			slog("Connected a controller");
			controllerConnected = 1;
			break;
		case SDL_CONTROLLERDEVICEREMOVED:
			slog("Removed a controller");
			controllerConnected = 0;
			break;
		}

		if (playButtonPressed && cd != NULL)
		{
			cd->position.x += 5;
		}

		if (cd != NULL)
		{
			if (point_in_rect(1000, 10, cd->boundingBox))
			{
				load_level("def/level/myLevel.txt", 1);
				if (musicPlaying > 0)
				{
					//Mix_RewindMusic();
					Mix_HaltChannel(-1);
				}
				soundPlay(snareDrum, -1, 1, snareDrum->defaultChannel, 0);
				soundPlay(flute, -1, 1, flute->defaultChannel, 0);
				soundPlay(trumpet, -1, 1, trumpet->defaultChannel, 0);
				soundPlay(altoSax, -1, 1, altoSax->defaultChannel, 0);
				soundPlay(tenorSax, -1, 1, tenorSax->defaultChannel, 0);
				musicPlaying = 1;
			}
		}
		//slog("ds %i %i %i %i", cd->boundingBox->x, cd->boundingBox->y, cd->boundingBox->w, cd->boundingBox->h);

		//UI elements last
		if (musicSheet)
			gf2d_sprite_draw(musicSheet, vector2d(0, 592), &scaleUp, NULL, NULL, NULL, NULL, 0);
		if (gui)
			gf2d_sprite_draw(gui, vector2d(0, 0), &scaleUp, NULL, NULL, NULL, NULL, 0);
		//text_draw_all();
		//text_draw(nameText);
		if (message && musicSheet)
		{
			SDL_RenderCopy(gf2d_graphics_get_renderer(), message, NULL, &rect);
			SDL_RenderCopy(gf2d_graphics_get_renderer(), instrumentTexture, NULL, &instrumentRect);
		}
		//SDL_RenderPresent(renderer);
		//gf2d_sprite_draw_image(textBox, vector2d(50, 50));
		if (controllerConnected && controllerIcon)
			gf2d_sprite_draw(controllerIcon, vector2d(700, 600), &scaleUp, NULL, NULL, NULL, NULL, 0);
		if (pickedUp == NULL)
		{
			gf2d_sprite_draw(
				mouse,				//Sprite to load
				vector2d(mx, my),	//Position to draw it at
				NULL,				//If you want to scale the sprite
				NULL,				//Scale the sprite from a certain position
				NULL,				//Rotation
				NULL,				//Flip
				&mouseColor,		//Color shift
				(int)mf);			//Which frame to draw at
		}
		else
		{
			gf2d_sprite_draw(
				mouse,				//Sprite to load
				vector2d(mx, my),	//Position to draw it at
				&scaleHalfUp,		//If you want to scale the sprite
				NULL,				//Scale the sprite from a certain position
				NULL,				//Rotation
				NULL,				//Flip
				&mouseColor,		//Color shift
				0);			//Which frame to draw at
		}
		gf2d_grahics_next_frame();// render current draw frame and skip to the next frame
        
		if (keys[SDL_SCANCODE_Q])
		{
			//close_level(tile_map);
			load_level("def/level/myLevel.txt", 1);
			if (musicPlaying > 0)
			{
				//Mix_RewindMusic();
				Mix_HaltChannel(-1);
			}
			soundPlay(snareDrum, -1, 1, snareDrum->defaultChannel, 0);
			soundPlay(flute, -1, 1, flute->defaultChannel, 0);
			soundPlay(trumpet, -1, 1, trumpet->defaultChannel, 0);
			soundPlay(altoSax, -1, 1, altoSax->defaultChannel, 0);
			soundPlay(tenorSax, -1, 1, tenorSax->defaultChannel, 0);
			musicPlaying = 1;
		}

        if (keys[SDL_SCANCODE_ESCAPE])done = 1; // exit condition
        //slog("Rendering at %f FPS",gf2d_graphics_get_frames_per_second());
    }
    slog("---==== END ====---");
	TTF_Quit();
	SDL_DestroyTexture(message);
	SDL_FreeSurface(surfaceMessage);
    return 0;
}
コード例 #11
0
void audioPlay(long leftSamples, long rightSamples, long centerSamples) {
    soundPlay(0, audioLeftBuffer, (u32) leftSamples, SAMPLE_PCM16, (u32) SAMPLE_RATE, 1, 0, false);
    soundPlay(1, audioRightBuffer, (u32) rightSamples, SAMPLE_PCM16, (u32) SAMPLE_RATE, 0, 1, false);
    soundPlay(2, audioCenterBuffer, (u32) centerSamples, SAMPLE_PCM16, (u32) SAMPLE_RATE, 1, 1, false);
    soundFlush();
}
コード例 #12
0
void Ball::doCollision()
{
    if(!stopped){

    if(birdDeadCounter>0)
    {
        --birdDeadCounter;
        if(birdDeadCounter<=0)
        {
            scene()->removeItem(removeBird);
        }
    }

    //check ob es eine Kollision gibt
    QList<QGraphicsItem*> collideList = scene()->collidingItems(this);


    //if(!(collideList.isEmpty()))
    for(int i=0; i<collideList.size(); ++i)
    {

        //finde Typ des kollidierenden Objectes heraus (BorderLine oder GroundMaterial)
        int sw = collideList.at(i)->type();

        switch(sw)
        {
            case CourtElement::borderline_type: //Kollision mit Spielfeldrand, abprallen
            {
                //Jetzt weis man, dass es eine Borderline ist, also caste QGraphicsItem* in BorderLine*
                BorderLine* borderline = static_cast<BorderLine*>(collideList.at(i));
                int angle = borderline->getAngle();

                if(canCollide<=0)
                {
                    emit soundPlay(SoundEngine::borderCollisionSound);

                    //angle ist relativ zu 3 Uhr (Uhrzeigersinn), rotation ist relativ zu 12 Uhr (Uhrzeigersinn)
                    setRotation(2*(angle+90.0-rotation()) + rotation());

                    speed = speed * borderline->getReflectionCoefficient();

                    canCollide = 3;
                }
            }
            break;

            case CourtElement::groundmaterial_type:
            {
                GroundMaterial* groundmaterial = static_cast<GroundMaterial*>(collideList.at(i));

                double maxspeed = groundmaterial->getMaxSpeed();
                double minspeed = groundmaterial->getMinSpeed();
                double friction = groundmaterial->getFrictionCoefficient();

                switch(groundmaterial->getMaterial())
                {
                    case GroundMaterial::water_material:
                    {
                        emit soundPlay(SoundEngine::waterSound);
                        speed -= friction*speed;

                        if(speed<minspeed)
                        {
                            speed = 0.0;

                            emit ballInWater();
                        }
                    }
                    break;

                    case GroundMaterial::nonNewtonian_material:

                        if(speed > minspeed)
                        {
                            speed -= speed*friction;
                        }
                        else if(speed<minspeed)
                        {
                            speed = 0.0;
                            emit soundPlay(SoundEngine::lavaSound);
                            emit ballInWater(); //Ist ja im Prinzip das gleiche wie bei Wasser
                        }
                    break;

                    case GroundMaterial::hole_material:

                        if(speed<maxspeed)
                        {
                            emit soundPlay(SoundEngine::cheeringSound);
                            speed = 0.0;
                            stopped=true;
                            emit ballInHole();
                        }

                    break;

                    case GroundMaterial::grass_material:
                    {
                       speed -= friction;

                        if(speed<minspeed)
                        {
                            speed = 0.0;
                            if(!stopped) emit ballStopped();
                            stopped = true;
                        }
                    }
                    break;

                    case GroundMaterial::sand_material:
                    {
                        emit(soundPlay(SoundEngine::sandSound));
                        speed -= 1.5*friction;

                        if(speed<minspeed)
                        {
                            speed = 0.0;
                            if(!stopped) emit ballStopped();
                            stopped = true;
                        }
                    }
                    break;

                    //unused materials:
                    /*
                    case GroundMaterial::speedUp_material:
                    case GroundMaterial::concrete_material:
                    case GroundMaterial::wood_material:
                    */

                    default: break;
                }
            }
            break;

            case 7: //Vogel abgeschossen! (7 = Pixmap)
            {
                if (isBirdDead == false)
                {
                    emit soundPlay(SoundEngine::birdHitSound);
                    emit birdHit();
                    isBirdDead = true;
                }
                removeBird = static_cast<QGraphicsPixmapItem*>(collideList.at(i));
                removeBird->setPixmap(birdDeadPicture);
                birdDeadCounter = 30;


            }
            break;

            default: break;
        }
    }
  }
}
コード例 #13
0
void Ball::playShotSound()
{
    emit soundPlay(SoundEngine::shotSound);
}