moar sounds

This commit is contained in:
Sebastian Krzyszkowiak 2012-02-19 20:18:28 +01:00
parent c2ef5e6d22
commit 88f627ff52
7 changed files with 49 additions and 6 deletions

View file

@ -1,5 +1,6 @@
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <stdio.h>
#include "about.h"
void About_Draw(struct Game *game) {
@ -9,6 +10,7 @@ void About_Draw(struct Game *game) {
}
void About_Load(struct Game *game) {
al_play_sample(game->about.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
ALLEGRO_EVENT ev;
for(int fadeloop=0; fadeloop<256; fadeloop+=10){
al_wait_for_event(game->event_queue, &ev);
@ -28,6 +30,12 @@ int About_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
}
void About_Preload(struct Game *game) {
game->about.image = al_load_bitmap( "data/table.png" );
game->about.sample = al_load_sample( "data/about.flac" );
if (!game->about.sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
exit(-1);
}
game->about.fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->about.fade_bitmap);
al_draw_scaled_bitmap(game->about.image,0,0,al_get_bitmap_width(game->about.image),al_get_bitmap_height(game->about.image),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
@ -49,4 +57,5 @@ void About_Unload(struct Game *game) {
}
al_destroy_bitmap(game->about.image);
al_destroy_bitmap(game->about.fade_bitmap);
al_destroy_sample(game->about.sample);
}

View file

@ -1,6 +1,7 @@
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <math.h>
#include <stdio.h>
#include "intro.h"
void Intro_Draw(struct Game *game) {
@ -30,6 +31,7 @@ void Intro_Draw(struct Game *game) {
}
void Intro_Load(struct Game *game) {
al_play_sample(game->intro.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
ALLEGRO_EVENT ev;
for(int fadeloop=0; fadeloop<256; fadeloop+=10){
al_wait_for_event(game->event_queue, &ev);
@ -57,6 +59,12 @@ void Intro_Preload(struct Game *game) {
game->intro.page = 0;
game->intro.in_animation = false;
game->intro.table_bitmap = al_load_bitmap( "data/discord.png" );
game->intro.sample = al_load_sample( "data/intro.flac" );
if (!game->intro.sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
exit(-1);
}
game->intro.table = al_create_bitmap(al_get_display_width(game->display)*4, al_get_display_height(game->display));
game->intro.font = al_load_ttf_font("data/ShadowsIntoLight.ttf",al_get_display_height(game->display)*0.045,0 );
al_set_target_bitmap(game->intro.table);
@ -98,4 +106,5 @@ void Intro_Unload(struct Game *game) {
al_destroy_bitmap(game->intro.table_bitmap);
al_destroy_bitmap(game->intro.table);
al_destroy_font(game->intro.font);
al_destroy_sample(game->intro.sample);
}

4
main.c
View file

@ -112,7 +112,7 @@ void LoadGameState(struct Game *game) {
int main(int argc, char **argv){
srand(time(NULL));
ALLEGRO_DISPLAY_MODE disp_data;
//ALLEGRO_DISPLAY_MODE disp_data;
bool redraw = true;
struct Game game;
@ -152,7 +152,7 @@ int main(int argc, char **argv){
return -1;
}
if (!al_reserve_samples(2)){
if (!al_reserve_samples(10)){
fprintf(stderr, "failed to reserve samples!\n");
return -1;
}

5
main.h
View file

@ -23,7 +23,7 @@ struct Menu {
ALLEGRO_BITMAP *mountain_bitmap, *mountain;
float cloud_position, cloud2_position;
int mountain_position;
ALLEGRO_SAMPLE *sample, *rain_sample;
ALLEGRO_SAMPLE *sample, *rain_sample, *click_sample;
ALLEGRO_FONT *font_title, *font_subtitle, *font, *font_selected;
int selected;
bool options;
@ -35,11 +35,13 @@ struct Loading {
struct About {
ALLEGRO_BITMAP *fade_bitmap, *image;
ALLEGRO_SAMPLE *sample;
};
struct Map {
ALLEGRO_BITMAP *map, *background, *map_bg, *highlight;
int selected, available;
ALLEGRO_SAMPLE *sample;
};
struct Intro {
@ -48,6 +50,7 @@ struct Intro {
bool in_animation;
ALLEGRO_BITMAP *table, *table_bitmap;
ALLEGRO_FONT *font;
ALLEGRO_SAMPLE *sample;
};
struct Game {

2
make
View file

@ -1,2 +1,2 @@
#!/bin/sh
gcc loading.c main.c menu.c about.c intro.c map.c -o superderpy -lallegro -lallegro_audio-debug -lallegro_acodec-debug -lallegro_image-debug -lallegro_font-debug -lallegro_ttf-debug -DDEBUG -std=gnu99 -g && ./superderpy
gcc loading.c main.c menu.c about.c intro.c map.c -o superderpy -lallegro -lallegro_audio-debug -lallegro_acodec-debug -lallegro_image-debug -lallegro_font-debug -lallegro_ttf-debug -DDEBUG -std=gnu99 -g -Wall && ./superderpy

9
map.c
View file

@ -8,6 +8,7 @@ void Map_Draw(struct Game *game) {
}
void Map_Load(struct Game *game) {
al_play_sample(game->map.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
ALLEGRO_EVENT ev;
for(int fadeloop=0; fadeloop<256; fadeloop+=10){
al_wait_for_event(game->event_queue, &ev);
@ -34,6 +35,13 @@ void Map_Preload(struct Game *game) {
char filename[30] = { };
sprintf(filename, "data/map/highlight%d.png", game->map.available);
game->map.highlight = al_load_bitmap( filename );
game->map.sample = al_load_sample( "data/map.flac" );
if (!game->map.sample){
fprintf(stderr, "Audio clip sample not loaded!\n" );
exit(-1);
}
al_set_target_bitmap(game->map.map);
al_draw_scaled_bitmap(game->map.background,0,0,al_get_bitmap_width(game->map.background),al_get_bitmap_height(game->map.background),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
al_draw_scaled_bitmap(game->map.map_bg,0,0,al_get_bitmap_width(game->map.map_bg),al_get_bitmap_height(game->map.map_bg),0,0,al_get_display_width(game->display), al_get_display_height(game->display),0);
@ -52,4 +60,5 @@ void Map_Unload(struct Game *game) {
al_destroy_bitmap(game->map.background);
al_destroy_bitmap(game->map.map_bg);
al_destroy_bitmap(game->map.highlight);
al_destroy_sample(game->map.sample);
}

17
menu.c
View file

@ -65,6 +65,7 @@ void Menu_Preload(struct Game *game) {
game->menu.mountain = al_load_bitmap( "data/mountain.png" );
game->menu.sample = al_load_sample( "data/menu.flac" );
game->menu.rain_sample = al_load_sample( "data/rain.flac" );
game->menu.click_sample = al_load_sample( "data/click.flac" );
game->menu.cloud = al_load_bitmap( "data/cloud.png" );
game->menu.cloud2 = al_load_bitmap( "data/cloud2.png" );
game->menu.pinkcloud = al_load_bitmap( "data/pinkcloud.png" );
@ -87,6 +88,11 @@ void Menu_Preload(struct Game *game) {
exit(-1);
}
if (!game->menu.click_sample){
fprintf(stderr, "Audio clip sample#3 not loaded!\n" );
exit(-1);
}
// Scale menu bitmap
game->menu.menu_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
al_set_target_bitmap(game->menu.menu_bitmap);
@ -156,10 +162,11 @@ void Menu_Unload(struct Game *game) {
al_destroy_font(game->menu.font_selected);
al_destroy_sample(game->menu.sample);
al_destroy_sample(game->menu.rain_sample);
al_destroy_sample(game->menu.click_sample);
}
void Menu_Load(struct Game *game) {
al_play_sample(game->menu.sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
al_play_sample(game->menu.sample, 0.8, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
al_play_sample(game->menu.rain_sample, 0.7, -0.3, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
game->menu.menu_fade_bitmap = al_create_bitmap(al_get_display_width(game->display), al_get_display_height(game->display));
@ -181,19 +188,25 @@ void Menu_Load(struct Game *game) {
int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {
if (ev->keyboard.keycode==ALLEGRO_KEY_UP) {
game->menu.selected--;
al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
} else if (ev->keyboard.keycode==ALLEGRO_KEY_DOWN) {
game->menu.selected++;
al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
} else if ((!game->menu.options) && (((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)) || (ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE))) {
al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
return 1;
} else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==0)) {
al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
UnloadGameState(game);
game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_INTRO;
} else if ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==2)) {
al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
UnloadGameState(game);
game->gamestate = GAMESTATE_LOADING;
game->loadstate = GAMESTATE_ABOUT;
} else if (((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==1)) || ((game->menu.options) && ((ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE)) || ((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3)))) {
} else if (((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (!game->menu.options) && (game->menu.selected==1)) || (((game->menu.options) && ((ev->keyboard.keycode == ALLEGRO_KEY_ESCAPE))) || (((ev->keyboard.keycode==ALLEGRO_KEY_ENTER) && (game->menu.selected==3))))) {
al_play_sample(game->menu.click_sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, NULL);
game->menu.options=!game->menu.options;
game->menu.selected=0;
PrintConsole(game, "options state changed");