Skip to content

Commit

Permalink
Transparencies are working. Hitting b will turn them on. Need to chan…
Browse files Browse the repository at this point in the history
…ge this though

Sound works. Currently have sound when rotating and moving left and right.
Background music also works but is turned off by default
  • Loading branch information
Krishna committed Mar 20, 2010
1 parent b4706cc commit 5879522
Show file tree
Hide file tree
Showing 12 changed files with 856 additions and 46 deletions.
Binary file modified 256.bmp
Binary file not shown.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
DEPENDS = $(SOURCES:.cpp=.d)
LDFLAGS = $(shell pkg-config --libs gtkmm-2.4 gtkglextmm-1.2)
CPPFLAGS = $(shell pkg-config --cflags gtkmm-2.4 gtkglextmm-1.2)
LDFLAGS = $(shell pkg-config --libs gtkmm-2.4 gtkglextmm-1.2 sdl) -lglut -lsdl_mixer
CPPFLAGS = $(shell pkg-config --cflags gtkmm-2.4 gtkglextmm-1.2 sdl)
CXXFLAGS = $(CPPFLAGS) -W -Wall -g
CXX = g++
CXX = g++ -m32
MAIN = game488

all: $(MAIN)
Expand All @@ -16,11 +16,11 @@ clean:

$(MAIN): $(OBJECTS)
@echo Creating $@...
@$(CXX) -arch i386 -o $@ $(OBJECTS) $(LDFLAGS)
@$(CXX) -o $@ $(OBJECTS) $(LDFLAGS)

%.o: %.cpp
@echo Compiling $<...
@$(CXX) -arch i386 -o $@ -c $(CXXFLAGS) $<
@$(CXX) -o $@ -c $(CXXFLAGS) $<

%.d: %.cpp
@echo Building $@...
Expand Down
143 changes: 143 additions & 0 deletions SoundManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/* ***************************************************************
*
* File : SoundManager.cpp
*
* Author : Tiberiu Popa
* J. Alexander Clarke
* Date : June 18th, 2002
*
* Modified:
*
* Purpose: Implementation of the sound manager
*
* ****************************************************************/
#pragma implementation
#include "SoundManager.hpp"
#include <stdlib.h>


SoundManager SM;

SoundManager::SoundManager(){

nSounds = 0;
nMusics = 0;

// initialize the sound library
SDL_Init(SDL_INIT_AUDIO /*| SDL_INIT_VIDEO */);

/* sound setup */
int audio_rate = 44100;
Uint16 audio_format = AUDIO_S16;
int audio_channels = 2;
int audio_buffers = 4096;

// open the audio stream
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
printf("Unable to open audio!\n");
exit(1);
}
}

SoundManager::~SoundManager(){
}


/* *************** Manipulate Sound Chunks *******************/

int SoundManager::ResetSound(int snd){
if(snd<0 || snd>=nSounds) return -1;

Mix_HaltChannel(channel[snd]);
channel[snd] = -1;

return 0;
}

int SoundManager::LoadSound(char* file){

chunks[nSounds] = Mix_LoadWAV(file);
channel[nSounds] = -1;

nSounds+=1;
return nSounds - 1;

}

int SoundManager::PlaySound(int snd){
if(snd<0 && snd>=nSounds) return -1;
channel[snd] = Mix_PlayChannel(-1, chunks[snd], 0 /*-1*/);
return 0;
}

int SoundManager::StopSound(int snd){
if(snd<0 && snd>=nSounds) return -1;
ResetSound(snd);
return 0;
}

int SoundManager::PauseSound(int snd){
if(snd<0 && snd>=nSounds) return -1;
Mix_Pause(channel[snd]);
return 0;
}

int SoundManager::ResumeSound(int snd){
if(snd<0 && snd>=nSounds) return -1;
Mix_Resume(channel[snd]);
return 0;
}


/* *************** Manipulate Music *******************/

int SoundManager::ResetMusic(int snd){
if(snd<0 || snd>=nMusics) return -1;

Mix_HaltMusic();

return 0;
}

int SoundManager::LoadMusic(char* file){

music[nMusics] = Mix_LoadMUS(file);
if(!music[nMusics])
{
printf("Mix_LoadMUS(\"music.mp3\"): %s\n", Mix_GetError());
// this might be a critical error...
}
nMusics+=1;
return nMusics - 1;

}

int SoundManager::PlayMusic(int snd){
if(snd<0 && snd>=nMusics) return -1;
//Mix_PlayMusic(music[snd], 1 /*-1*/);

if(Mix_PlayMusic(music[snd], -1)==-1)
{
printf("Mix_PlayMusic: %s\n", Mix_GetError());
// well, there's no music, but most games don't break without music...
}
return 0;
}

int SoundManager::StopMusic(int snd){
if(snd<0 && snd>=nMusics) return -1;
ResetMusic(snd);
return 0;
}

int SoundManager::PauseMusic(int snd){
if(snd<0 && snd>=nMusics) return -1;
Mix_PauseMusic();
return 0;
}

int SoundManager::ResumeMusic(int snd){
if(snd<0 && snd>=nMusics) return -1;
Mix_ResumeMusic();
return 0;
}
76 changes: 76 additions & 0 deletions SoundManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* ***************************************************************
*
* File : SoundManager.h
*
* Author : Tiberiu Popa
* J. Alexander Clarke
* Date : June 18th, 2002
*
* Modified:
*
* Purpose: Header file for the sound manager
*
* ****************************************************************/
#ifndef _SOUND_MANAGER__H
#define _SOUND_MANAGER__H
#pragma interface

// include SDL header files
#include "SDL.h"
#include "SDL_mixer.h"

// if you want more than 100 sounds, change the MAX_SOUND
#define MAX_SOUNDS 100
#define MAX_MUSIC 100

// wrapper calss around SDL and SDL_mixer libraries
class SoundManager {
public:
SoundManager();
~SoundManager();

// manipulating sound clips
// sound clips can be played simultaneously
int LoadSound(char* file);

// snd is the sound ID returned by LoadSound
int PlaySound(int snd);
int StopSound(int snd);
int PauseSound(int snd);
int ResumeSound(int snd);

// manipulating music clips
// should have only one music clip

int LoadMusic(char* file);

int PlayMusic(int);
int StopMusic(int);
int PauseMusic(int);
int ResumeMusic(int);

private:

// internal data

// sound clips
Mix_Chunk * chunks[MAX_SOUNDS];
Mix_Music *music[MAX_MUSIC];

// sound channels for active sounds
int channel[MAX_SOUNDS];

// number of sound clips loaded
int nSounds;
int nMusics;

int ResetSound(int snd);
int ResetMusic(int snd);
};


// the global instance of the sound manager
extern SoundManager SM;


#endif // _SOUND_MANAGER__H
1 change: 1 addition & 0 deletions appwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ AppWindow::AppWindow()
m_menu_drawMode.items().push_back(MenuElem("_Wire-Frame", Gtk::AccelKey("w"), sigc::bind( draw_slot, Viewer::WIRE ) ) );
m_menu_drawMode.items().push_back(MenuElem("_Face", Gtk::AccelKey("f"), sigc::bind( draw_slot, Viewer::FACE ) ) );
m_menu_drawMode.items().push_back(MenuElem("_Texture 1", Gtk::AccelKey("t"), sigc::mem_fun(m_viewer, &Viewer::toggleTexture ) ) );
m_menu_drawMode.items().push_back(MenuElem("_Bump Mapping 1", Gtk::AccelKey("b"), sigc::mem_fun(m_viewer, &Viewer::toggleBumpMapping ) ) );

m_menu_speed.items().push_back(RadioMenuElem(m_group_speed, "_Slow", sigc::bind( speed_slot, Viewer::SLOW ) ) );
m_menu_speed.items().push_back(RadioMenuElem(m_group_speed, "_Medium", sigc::bind( speed_slot, Viewer::MEDIUM ) ) );
Expand Down
Binary file added floor.bmp
Binary file not shown.
Binary file added lumines.ogg
Binary file not shown.
Binary file added move.ogg
Binary file not shown.
Binary file added normal.bmp
Binary file not shown.
Binary file added turn.ogg
Binary file not shown.
Loading

0 comments on commit 5879522

Please sign in to comment.