summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLAMMJohnson <john_anthony@lavabit.com>2011-04-26 21:51:38 +0100
committerLAMMJohnson <john_anthony@lavabit.com>2011-04-26 21:51:38 +0100
commit66d167ccf68497e080fb920538375ea09dbd53e4 (patch)
tree3559a14b93464711b48d86ac2fcf3e3c69b9bb2f
parent2d3cbf448a2c4ef23d2dc69a07e08a4ddfb31187 (diff)
downloadnyancat-66d167ccf68497e080fb920538375ea09dbd53e4.tar.gz
nyancat-66d167ccf68497e080fb920538375ea09dbd53e4.tar.bz2
nyancat-66d167ccf68497e080fb920538375ea09dbd53e4.zip
First touches of audio
-rw-r--r--Makefile2
-rw-r--r--TODO1
-rw-r--r--nyan.c23
3 files changed, 25 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 73dd2ba..e1ee579 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
nyancat: nyan.c
- gcc -g nyan.c -o nyancat -lSDL -lSDL_image -Wall
+ gcc -g nyan.c -o nyancat -lSDL -lSDL_image -lSDL_mixer -Wall
chmod +x nyancat
install:
diff --git a/TODO b/TODO
index ecadab5..ed9dc21 100644
--- a/TODO
+++ b/TODO
@@ -4,3 +4,4 @@
-- Add command-line args
-- Add rc file
-- Make a proper install
+-- Correctly estimate screen size
diff --git a/nyan.c b/nyan.c
index 7d616bc..08e6ce5 100644
--- a/nyan.c
+++ b/nyan.c
@@ -1,5 +1,7 @@
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
+#include <SDL/SDL_mixer.h>
+#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@@ -26,6 +28,7 @@ struct sparkle_instance {
SDL_Surface* cat_img[5];
SDL_Surface* sparkle_img[5];
+Mix_Music* music;
sparkle_instance* sparkles_list = NULL;
cat_instance* cat_list = NULL;
Uint32 bgcolor;
@@ -38,8 +41,10 @@ void fillsquare(SDL_Surface* surf, int x, int y, int w, int h, Uint32 col);
void handleinput(void);
void load_images(void);
SDL_Surface* load_image(const char* path);
+void load_music(void);
void putpix(SDL_Surface* surf, int x, int y, Uint32 col);
void remove_sparkle(sparkle_instance* s);
+void start_music(void);
void update_sparkles(void);
unsigned int SCREEN_WIDTH = 1920;
@@ -201,6 +206,13 @@ load_image( const char* path ) {
}
void
+load_music(void) {
+ music = Mix_LoadMUS("res/nyan.ogg");
+ if(!music)
+ printf("Unable to load Ogg file: %s\n", Mix_GetError());
+}
+
+void
putpix(SDL_Surface* surf, int x, int y, Uint32 col) {
Uint32 *pix = (Uint32 *) surf->pixels;
pix [ ( y * surf->w ) + x ] = col;
@@ -224,6 +236,12 @@ remove_sparkle(sparkle_instance* s) {
}
void
+start_music(void) {
+ if(Mix_PlayMusic(music, 0) == -1)
+ printf("Unable to play Ogg file: %s\n", Mix_GetError());
+}
+
+void
update_sparkles(void) {
sparkle_instance* next, *s = sparkles_list;
@@ -264,6 +282,7 @@ int main( int argc, char *argv[] )
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SURF_TYPE);
load_images();
+ load_music();
bgcolor = SDL_MapRGB(screen->format, 0x00, 0x33, 0x66);
@@ -300,6 +319,10 @@ int main( int argc, char *argv[] )
SDL_Delay((1000 / FRAMERATE) - draw_time);
}
+ Mix_HaltMusic();
+ Mix_FreeMusic(music);
+ Mix_CloseAudio();
+
SDL_Quit();
return 0;
}