void soundeffects_play(enum SoundeffectSound sound) { if (sound <= SOUND_UPROOT) d_sound_play(s->sfx.sound[sound], -1, 100, 100, 0); else d_sound_play(s->sfx.sound[sound], -1, 50, 50, 0); return; }
void game_init() { shape_init("models.stz"); model.player=shapesprite_new("player walk", 2); model.gun=shape_load("gun"); model.bullet=shape_load("bullet"); model.grenade=shape_load("grenade"); model.enemy[0]=shape_load("enemy_left"); model.enemy[1]=shape_load("enemy_gunner"); model.enemy[2]=shape_load("enemy_grenadier"); model.enemy[3]=shape_load("tank"); model.enemy_right=shape_load("enemy_right"); model.explosion=shape_load("explosion"); model.flamethrower=shape_load("flamethrower"); model.powerup[0]=shape_load("powerup_hp"); model.powerup[1]=shape_load("powerup_grenades"); sound.explosion=d_sound_streamed_load("explosion.ogg", DARNIT_AUDIO_PRELOAD, DARNIT_AUDIO_STEREO); sound.jump=d_sound_streamed_load("jump.ogg", DARNIT_AUDIO_PRELOAD, DARNIT_AUDIO_STEREO); sound.shoot=d_sound_streamed_load("shoot.ogg", DARNIT_AUDIO_PRELOAD, DARNIT_AUDIO_STEREO); sound.enemy_kill=d_sound_streamed_load("enemy_kill.ogg", DARNIT_AUDIO_PRELOAD, DARNIT_AUDIO_STEREO); sound.powerup=d_sound_streamed_load("powerup.ogg", DARNIT_AUDIO_PRELOAD, DARNIT_AUDIO_STEREO); sound.powerup_small=d_sound_streamed_load("powerup_small.ogg", DARNIT_AUDIO_PRELOAD, DARNIT_AUDIO_STEREO); sound.music=d_sound_tracked_load("music.mod", DARNIT_AUDIO_STREAM, DARNIT_AUDIO_MONO); if(sound.music) d_sound_play(sound.music, 0, 96, 96, 0); grenade_explosion=shape_copy_copy(model.explosion); flamethrower=shape_copy_copy(model.flamethrower); }
void * musikka(){ DARNIT_SOUND *music = d_sound_streamed_load("TowerTown.ogg", 1, 1); //Load an audiophile. d_sound_play(music, 1, 128, 128, 0); //Play la musica. pthread_exit(NULL); }
void map_check_powerup(int x, int y) { int i; for(i=0; i<map.powerups; i++) { if((x>map.powerup[i].x-10)&&(x<map.powerup[i].x+10)&&(y>map.powerup[i].y-10)&&(y<map.powerup[i].y+10)&&((!map.powerup[i].taken))) { map.powerup[i].taken=1; switch(map.powerup[i].type) { case POWERUP_HP: d_sound_play(sound.powerup, 0, 127, 127, 0); player->health+=50; if(player->health>100) player->health=100; break; case POWERUP_GRENADES: d_sound_play(sound.powerup_small, 0, 127, 127, 0); player->grenades=(player->grenades+2); default: break; } } } }
int main(int argc, char **argv) { int i, j, js0_x, js0_y, js1_x, js1_y; void *font, *surface, *text, *mapsheet, *sprite, *textinput, *mtsprite, *fps_text, *tilebuf, *fancy_text; void *music; char test[256], fps[16]; char *test_text; DARNIT_MOUSE mouse; DARNIT_KEYS keys; DARNIT_MAP *map; DARNIT_SPRITE *mapsprite; if (!d_init("TESTAPP - libDarnit", "testapp", NULL)) return -1; compression_test(); /* Sound/music */ music = d_sound_tracked_load("latyl-greasy_duck_v1.mod", DARNIT_AUDIO_STREAM, DARNIT_AUDIO_STEREO); d_sound_play(music, 0, 127, 127, 0); /* Text rendering */ test_text = malloc(64); font = d_font_load("dejavu_sans.ttf", 28, 512, 512); text = d_text_surface_new(font, 80, 800, 0, 460); fancy_text = d_text_surface_color_new(font, 16, 800, 0, 420); colorTest(fancy_text); fps_text = d_text_surface_new(font, 16, 200, 0, 40); /* Menutk test */ surface = d_menu_vertical_new("Hello\nGoodbye\nOther\nNothing\nLess than nothing", 50, 100, font, 200, 10, 3); sprintf(test_text, "Héllo, world. Modify m€! Test of offsets"); textinput = d_menu_textinput_new(0, 0, font, test_text, 64, 200); /* Sprites */ sprite = d_sprite_load("test.spr", 0, DARNIT_PFORMAT_RGB5A1); mapsprite = d_sprite_load("baurn.spr", 0, DARNIT_PFORMAT_RGB5A1); d_sprite_move(sprite, 50, 50); d_sprite_move(mapsprite, 0, 0); d_sprite_animate_start(sprite); d_sprite_animate_start(mapsprite); mtsprite = d_mtsprite_load("testspr.mts"); d_mtsprite_animate_start(mtsprite); /* Maps */ mapsheet = d_render_tilesheet_load("mapsheet.png", 32, 32, DARNIT_PFORMAT_RGBA8); if ((map = d_map_load("testmap_iso.ldmz")) == NULL) fprintf(stderr, "Map load failed\n"); d_tilemap_sprite_add(map->layer[0].tilemap, mapsprite); /* Tile caches */ tilebuf = d_render_tile_new(1, mapsheet); d_render_tile_move(tilebuf, 0, 64, 64); d_render_tile_tilesheet_coord_set(tilebuf, 0, 16, 16, 32, 32); /* Misc */ fprintf(stderr, "String lenght: %i\n", d_font_string_w(font, "ASDFÅÄÖ,,")); for (i = j = 0;;) { d_sprite_move(mapsprite, 64, j * 4); keys = d_keys_get(); d_text_surface_reset(text); d_text_surface_reset(fps_text); mouse = d_mouse_get(); d_joystick_get(&js0_x, &js0_y, &js1_x, &js1_y); sprintf(test, "X: %i, Y: %i, W: %i;; TX: %i, TY: %i;; nub0 (%i,%i) ;; nub1(%i,%i)", mouse.x, mouse.y, mouse.wheel, i*4, j*4, js0_x, js0_y, js1_x, js1_y); sprintf(fps, "%i", d_last_frame_time()); d_text_surface_string_append(text, test); d_text_surface_string_append(fps_text, "ASDFÅÄÖ,,"); if (keys.lmb) d_render_fade_in(1000, 1.0f, 0.0f, 0.0f); if (keys.rmb) d_render_fade_out(1000); d_render_begin(); if (keys.left == 1) i--; if (keys.right == 1) i++; if (keys.up == 1) j--; if (keys.down == 1) j++; if (keys.select) fprintf(stderr, "Blololol\n"); if (keys.r == 1) d_tilemap_camera_move(map->layer->tilemap, i*4, j*4); d_render_blend_enable(); d_tilemap_draw(map->layer->tilemap); if (keys.l == 1) if (d_menu_loop(surface) != -1) return 0; d_menu_loop(textinput); d_sprite_draw(sprite); d_text_surface_draw(text); d_text_surface_draw(fancy_text); d_text_surface_draw(fps_text); d_render_offset(-200, -200); d_mtsprite_draw(mtsprite); d_render_offset(0, 0); d_render_blend_disable(); d_render_tile_draw(tilebuf, 1); d_render_end(); d_loop(); } return 0; }
/* Bästa Snyggkoden™ i stan! */ int player_loop(DARNIT_KEYS *keys) { SHAPE_COPY *shape; DARNIT_KEYS set; static int shoot_key=0; static int grenade_key=0; int dir; if (!player) return 0; shape=shapesprite_get_current_shape(player->shape); if(keys->up) player->gun_angle=-200; else if(keys->down) player->gun_angle=200; else player->gun_angle=0; if(keys->a&&!shoot_key) { int x=player->x/1000+28, y=player->y/1000+(player->gun_angle?player->gun_angle/20:0); player->bullet=bullet_add(player->bullet, x, y, player->gun_angle, model.bullet, BULLET_OWNER_PLAYER); d_sound_play(sound.shoot, 0, 127, 127, 0); particle_emitter_new(30, 100, 8000, 10000, 255, 0, 0, PARTICLE_TYPE_PULSE, x, y, 0, player->gun_angle-100, player->gun_angle+100); particle_emitter_new(30, 100, 8000, 10000, 255, 255, 0, PARTICLE_TYPE_PULSE, x, y, 0, player->gun_angle-100, player->gun_angle+100); } if(keys->b&&(!grenade_key)&&player->grenades) grenade_time=d_time_get(); if((grenade_key&&!keys->b)||(grenade_time&&d_time_get()>=GRENADE_LIFE+grenade_time)) { int x=player->x/1000+28, y=player->y/1000+(player->gun_angle?player->gun_angle/20:0); if(player->grenades) { player->grenade=grenade_add(player->grenade, x, y, player->gun_angle, grenade_time+GRENADE_LIFE-d_time_get(), model.grenade); player->grenades--; } grenade_time=0; } shoot_key=keys->a; grenade_key=keys->b; if (keys->left) player->vel_x -= (PLAYER_ACCELERATION * d_last_frame_time()) / 1000; else if (keys->right) player->vel_x += (PLAYER_ACCELERATION * d_last_frame_time()) / 1000; else if (player->vel_x) { if (abs(player->vel_x) < (PLAYER_ACCELERATION * d_last_frame_time()) / 1000) player->vel_x = 0; else player->vel_x += ((player->vel_x < 0 ? 1 : -1) * (PLAYER_FRICTION) * d_last_frame_time()) / 1000; } if (abs(player->vel_x) > PLAYER_SPEED_X_MAX) player->vel_x = (player->vel_x < 0 ? -1 : 1) * PLAYER_SPEED_X_MAX; if (keys->l && !player->vel_y) { set = d_keys_zero(); set.l = 1; d_keys_set(set); player->vel_y -= PLAYER_JUMP_ACCELERATION; } player->vel_y += PLAYER_GRAVITY * d_last_frame_time(); if (abs(player->vel_y) > PLAYER_SPEED_Y_MAX) player->vel_y = (player->vel_y < 0 ? -1 : 1) * PLAYER_SPEED_Y_MAX; dir=map_collide_dir(shape->coord, shape->lines, player->x / 1000, player->y / 1000, player->vel_x); if(dir==MAP_SLOPE_UP) { player->x += player->vel_x * d_last_frame_time()/ 1000; player->y-=abs(player->vel_x) * d_last_frame_time() / 1000; } else if(dir==MAP_SLOPE_VERTICAL) { player->x-=player->vel_x/ 200; player->vel_x*=-1; player->y+=2000; } else if(dir!=MAP_SLOPE_VERTICAL) { if (dir != -1) player->y-=50; player->x += player->vel_x * d_last_frame_time() / 1000; } if (player->x < 32000) player->x = 32000; if (!map_collide(shape->coord, shape->lines, player->x / 1000, player->y / 1000) || player->vel_y < 0) player->y += player->vel_y * d_last_frame_time() / 1000; else { player->vel_y = 0; } if (player->y / 1000 >= PLAYER_KILLZONE||map_enemy_collide(shapesprite_get_current_shape(player->shape), player->x, player->y)) { player_kill(); return -1; } if (player->x < camera_x + 32000) player->x = camera_x + 32000; if(player->vel_x) { shapesprite_animate(player->shape); } if(boss_shooting&&((player->x-camera_x)>300000)&&((boss_shooting-d_time_get())>1000)) { player->health--; if(player->health<0) { player_kill(); return 1; } } map_check_powerup(player->x/1000/*+camera_x/1000*/, player->y/1000); score++; return 1; }