summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gun.c25
-rw-r--r--src/item.c25
-rw-r--r--src/music.c45
-rw-r--r--src/screen_setting.c38
-rw-r--r--src/screen_world.c26
-rw-r--r--src/sound.c24
-rw-r--r--src/tux.c64
-rw-r--r--src/widget_textfield.c9
8 files changed, 237 insertions, 19 deletions
diff --git a/src/gun.c b/src/gun.c
index 1cb35fe..199324f 100644
--- a/src/gun.c
+++ b/src/gun.c
@@ -10,6 +10,7 @@
#include "myTimer.h"
#include "main.h"
#include "item.h"
+#include "sound.h"
#include "screen_world.h"
#include "interface.h"
#include "gun.h"
@@ -215,17 +216,29 @@ void shotInGun(tux_t *tux)
{
switch( tux->gun )
{
- case GUN_SIMPLE : shotInGunSimpe(tux);
+ case GUN_SIMPLE :
+ playSound("gun_revolver", SOUND_GROUP_BASE);
+ shotInGunSimpe(tux);
break;
- case GUN_DUAL_SIMPLE : shotInGunDualSimpe(tux);
+ case GUN_DUAL_SIMPLE :
+ playSound("gun_revolver", SOUND_GROUP_BASE);
+ shotInGunDualSimpe(tux);
break;
- case GUN_SCATTER : shotInGunScatter(tux);
+ case GUN_SCATTER :
+ playSound("gun_scatter", SOUND_GROUP_BASE);
+ shotInGunScatter(tux);
break;
- case GUN_TOMMY : shotInGunTommy(tux);
+ case GUN_TOMMY :
+ playSound("gun_tommy", SOUND_GROUP_BASE);
+ shotInGunTommy(tux);
break;
- case GUN_LASSER : shotInGunLasser(tux);
+ case GUN_LASSER :
+ playSound("gun_lasser", SOUND_GROUP_BASE);
+ shotInGunLasser(tux);
break;
- case GUN_MINE : putInGunMine(tux);
+ case GUN_MINE :
+ playSound("put_mine", SOUND_GROUP_BASE);
+ putInGunMine(tux);
break;
}
}
diff --git a/src/item.c b/src/item.c
index 06e932b..59612ec 100644
--- a/src/item.c
+++ b/src/item.c
@@ -5,6 +5,7 @@
#include "main.h"
#include "interface.h"
#include "image.h"
+#include "sound.h"
#include "layer.h"
#include "screen_world.h"
#include "screen_setting.h"
@@ -75,11 +76,13 @@ item_t* newItem(int x, int y, int type)
break;
case ITEM_EXPLOSION :
+ playSound("explozion", SOUND_GROUP_BASE);
new->w = ITEM_EXPLOSION_WIDTH;
new->h = ITEM_EXPLOSION_HEIGHT;
break;
case ITEM_BIG_EXPLOSION :
+ playSound("explozion", SOUND_GROUP_BASE);
new->w = ITEM_BIG_EXPLOSION_WIDTH;
new->h = ITEM_BIG_EXPLOSION_HEIGHT;
break;
@@ -115,27 +118,29 @@ void addNewItem(list_t *listItem)
findFreeSpace(&new_x, &new_y, ITEM_GUN_WIDTH, ITEM_GUN_HEIGHT);
do{
- switch( random() % 10 )
+ switch( random() % 11 )
{
case 0 : type = GUN_DUAL_SIMPLE;
break;
case 1 : type = GUN_SCATTER;
break;
- case 2 : type = GUN_MINE;
+ case 2 : type = GUN_TOMMY;
break;
- case 3 : type = GUN_LASSER;
+ case 3 : type = GUN_MINE;
break;
- case 4 : type = BONUS_SPEED;
+ case 4 : type = GUN_LASSER;
break;
- case 5 : type = BONUS_SHOT;
+ case 5 : type = BONUS_SPEED;
break;
- case 6 : type = BONUS_TELEPORT;
+ case 6 : type = BONUS_SHOT;
break;
- case 7 : type = BONUS_GHOST;
+ case 7 : type = BONUS_TELEPORT;
break;
- case 8 : type = BONUS_4X;
+ case 8 : type = BONUS_GHOST;
break;
- case 9 : type = BONUS_HIDDEN;
+ case 9 : type = BONUS_4X;
+ break;
+ case 10 : type = BONUS_HIDDEN;
break;
}
}while( isSettingItem(type) == FALSE );
@@ -332,6 +337,7 @@ void eventGiveTuxItem(tux_t *tux, list_t *listItem)
case GUN_SCATTER :
case GUN_LASSER :
case GUN_MINE :
+ playSound("item_gun", SOUND_GROUP_BASE);
tux->shot[ thisItem->type ] += GUN_MAX_SHOT;
tux->gun = thisItem->type;
delListItem(listItem, i, destroyItem);
@@ -362,6 +368,7 @@ void eventGiveTuxItem(tux_t *tux, list_t *listItem)
case BONUS_GHOST :
case BONUS_4X :
case BONUS_HIDDEN :
+ playSound("item_bonus", SOUND_GROUP_BASE);
tux->bonus = thisItem->type;
tux->bonus_time = TUX_MAX_BONUS;
delListItem(listItem, i, destroyItem);
diff --git a/src/music.c b/src/music.c
index 2459787..e3a9d69 100644
--- a/src/music.c
+++ b/src/music.c
@@ -14,6 +14,7 @@
static list_t *listMusic;
static bool_t isMusicInit = FALSE;
+static bool_t isMusicActive = TRUE;
static music_t *currentMusic;
bool_t isMusicInicialized()
@@ -23,12 +24,18 @@ bool_t isMusicInicialized()
void initMusic()
{
- assert( isAudioInicialized() );
+ if( isAudioInicialized() == FALSE )
+ {
+ isMusicInit = FALSE;
+ return;
+ }
listMusic = newList();
currentMusic = NULL;
isMusicInit = TRUE;
+ isMusicActive = TRUE;
+
printf("init music..\n");
}
@@ -83,6 +90,12 @@ void addMusic(char *file, char *name, int group)
void stopMusic()
{
+ if( isMusicInit == FALSE ||
+ isMusicActive == FALSE )
+ {
+ return;
+ }
+
if( currentMusic != NULL )
{
printf("stop music %s..\n", currentMusic->name);
@@ -96,6 +109,12 @@ void playMusic(char *name, int group)
int i;
music_t *this;
+ if( isMusicInit == FALSE ||
+ isMusicActive == FALSE )
+ {
+ return;
+ }
+
if( currentMusic != NULL &&
currentMusic->group == group &&
strcmp(currentMusic->name, name) == 0 )
@@ -125,6 +144,25 @@ void playMusic(char *name, int group)
}
}
+void setMusicActive(bool_t n)
+{
+ static music_t *music = NULL;
+
+ if( n == FALSE )
+ {
+ music = currentMusic;
+ stopMusic();
+ }
+
+ if( n == TRUE )
+ {
+ currentMusic = music;
+ playMixMusic();
+ }
+
+ isMusicActive = n;
+}
+
char* getCurrentMusic()
{
return currentMusic->name;
@@ -149,6 +187,11 @@ void delAllMusicInGroup(int group)
void quitMusic()
{
+ if( isMusicInit == FALSE )
+ {
+ return;
+ }
+
stopMusic();
destroyListItem(listMusic, destroyMusic);
isMusicInit = FALSE;
diff --git a/src/screen_setting.c b/src/screen_setting.c
index ffcc8d1..26f28f7 100644
--- a/src/screen_setting.c
+++ b/src/screen_setting.c
@@ -7,6 +7,7 @@
#include "screen.h"
#include "image.h"
#include "music.h"
+#include "sound.h"
#include "screen_mainMenu.h"
#include "list.h"
#include "screen_setting.h"
@@ -25,8 +26,12 @@ static widget_button_t *button_back;
static widget_label_t *label_count_round;
static widget_label_t *label_name_player1;
static widget_label_t *label_name_player2;
+static widget_label_t *label_music;
+static widget_label_t *label_sound;
static widget_check_t *check[ITEM_COUNT];
+static widget_check_t *check_music;
+static widget_check_t *check_sound;
static widget_image_t *image_gun_dual_revolver;
static widget_image_t *image_gun_scatter;
@@ -60,6 +65,8 @@ void drawScreenSetting()
drawWidgetLabel(label_count_round);
drawWidgetLabel(label_name_player1);
drawWidgetLabel(label_name_player2);
+ drawWidgetLabel(label_music);
+ drawWidgetLabel(label_sound);
drawWidgetTextfield(textfield_count_cound);
drawWidgetTextfield(textfield_name_player1);
@@ -79,6 +86,9 @@ void drawScreenSetting()
drawWidgetImage(image_bonus_4x);
drawWidgetImage(image_bonus_hidden);
+ drawWidgetCheck(check_music);
+ drawWidgetCheck(check_sound);
+
for( i = GUN_DUAL_SIMPLE ; i <= GUN_BOMBBALL ; i++ )
{
drawWidgetCheck(check[i]);
@@ -100,6 +110,9 @@ void eventScreenSetting()
eventWidgetTextfield(textfield_name_player1);
eventWidgetTextfield(textfield_name_player2);
+ eventWidgetCheck(check_music);
+ eventWidgetCheck(check_sound);
+
for( i = GUN_DUAL_SIMPLE ; i <= GUN_BOMBBALL ; i++ )
{
eventWidgetCheck(check[i]);
@@ -120,13 +133,25 @@ void stopScreenSetting()
static void eventWidget(void *p)
{
widget_button_t *button;
+ widget_check_t *check;
button = (widget_button_t *)(p);
+ check = (widget_check_t *)(p);
if( button == button_back )
{
setScreen("mainMenu");
}
+
+ if( check == check_music )
+ {
+ setMusicActive( check_music->status );
+ }
+
+ if( check == check_sound )
+ {
+ setSoundActive( check_sound->status );
+ }
}
void initScreenSetting()
@@ -147,6 +172,14 @@ void initScreenSetting()
textfield_name_player1 = newWidgetTextfield("name1", 110+label_name_player1->w, WINDOW_SIZE_Y-160);
textfield_name_player2 = newWidgetTextfield("name2", 110+label_name_player2->w, WINDOW_SIZE_Y-120);
+ label_music = newWidgetLabel("Music :", 100, WINDOW_SIZE_Y-85, WIDGET_LABEL_LEFT);
+ check_music = newWidgetCheck(label_music->x + label_music->w + 10,
+ WINDOW_SIZE_Y-80, TRUE, eventWidget);
+ label_sound = newWidgetLabel("Sound :", check_music->x + WIDGET_CHECK_WIDTH + 10,
+ WINDOW_SIZE_Y-85, WIDGET_LABEL_LEFT);
+ check_sound = newWidgetCheck(label_sound->x + label_sound->w + 10,
+ WINDOW_SIZE_Y-80, TRUE, eventWidget);
+
for( i = GUN_DUAL_SIMPLE ; i <= GUN_BOMBBALL ; i++ )
{
int x;
@@ -257,6 +290,8 @@ void quitScreenSetting()
destroyWidgetLabel(label_count_round);
destroyWidgetLabel(label_name_player1);
destroyWidgetLabel(label_name_player2);
+ destroyWidgetLabel(label_music);
+ destroyWidgetLabel(label_sound);
destroyWidgetTextfield(textfield_count_cound);
destroyWidgetTextfield(textfield_name_player1);
@@ -276,6 +311,9 @@ void quitScreenSetting()
destroyWidgetImage(image_bonus_4x);
destroyWidgetImage(image_bonus_hidden);
+ destroyWidgetCheck(check_music);
+ destroyWidgetCheck(check_sound);
+
for( i = GUN_DUAL_SIMPLE ; i <= GUN_BOMBBALL ; i++ )
{
destroyWidgetCheck(check[i]);
diff --git a/src/screen_world.c b/src/screen_world.c
index ae278f5..a8e86b2 100644
--- a/src/screen_world.c
+++ b/src/screen_world.c
@@ -15,6 +15,7 @@
#include "layer.h"
#include "image.h"
#include "music.h"
+#include "sound.h"
#include "tux.h"
#include "wall.h"
#include "item.h"
@@ -174,6 +175,18 @@ static void control_keyboard_left(tux_t *p)
if( mapa[(SDLKey)SDLK_d] == SDL_PRESSED )moveTux(p, TUX_RIGHT);
if( mapa[(SDLKey)SDLK_a] == SDL_PRESSED )moveTux(p, TUX_LEFT);
if( mapa[(SDLKey)SDLK_s] == SDL_PRESSED )moveTux(p, TUX_DOWN);
+
+ if( mapa[(SDLKey)SDLK_q] == SDL_PRESSED )
+ {
+ proto_send_shottux(p);
+ shotTux(p);
+ }
+
+ if( mapa[(SDLKey)SDLK_TAB] == SDL_PRESSED )
+ {
+ proto_send_switchgun(p);
+ switchTuxGun(p);
+ }
}
static void eventEnd()
@@ -286,6 +299,19 @@ void initWorld()
registerScreen( newScreen("world", startWorld, eventWorld, drawWorld, stoptWorld) );
+ addSound("dead.ogg", "dead", SOUND_GROUP_BASE);
+ addSound("explozion.ogg", "explozion", SOUND_GROUP_BASE);
+ addSound("gun_lasser.ogg", "gun_lasser", SOUND_GROUP_BASE);
+ addSound("gun_revolver.ogg", "gun_revolver", SOUND_GROUP_BASE);
+ addSound("gun_scatter.ogg", "gun_scatter", SOUND_GROUP_BASE);
+ addSound("gun_tommy.ogg", "gun_tommy", SOUND_GROUP_BASE);
+ addSound("put_mine.ogg", "put_mine", SOUND_GROUP_BASE);
+ addSound("teleport.ogg", "teleport", SOUND_GROUP_BASE);
+ addSound("item_bonus.ogg", "item_bonus", SOUND_GROUP_BASE);
+ addSound("item_gun.ogg", "item_gun", SOUND_GROUP_BASE);
+ addSound("switch_gun.ogg", "switch_gun", SOUND_GROUP_BASE);
+ addSound("end.ogg", "end", SOUND_GROUP_BASE);
+
isScreenWorldInit = TRUE;
}
diff --git a/src/sound.c b/src/sound.c
index 45cb225..2e7ef4b 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -14,6 +14,7 @@
static list_t *listSound;
static bool_t isSoundInit = FALSE;
+static bool_t isSoundActive = TRUE;
bool_t isSoundInicialized()
{
@@ -22,10 +23,14 @@ bool_t isSoundInicialized()
void initSound()
{
- assert( isAudioInicialized() );
+ if( isAudioInicialized() == FALSE )
+ {
+ isSoundInit = FALSE;
+ }
listSound = newList();
isSoundInit = TRUE;
+ isSoundActive = TRUE;
printf("init sound..\n");
}
@@ -35,6 +40,7 @@ static Mix_Chunk* loadMixSound(char *file)
Mix_Chunk *new;
char str[STR_PATH_SIZE];
+ printf("load sound %s..\n", file);
sprintf(str, PATH_SOUND "%s", file);
new = Mix_LoadWAV(str);
@@ -85,6 +91,12 @@ void playSound(char *name, int group)
int i;
sound_t *this;
+ if( isSoundInit == FALSE ||
+ isSoundActive == FALSE )
+ {
+ return;
+ }
+
for( i = 0 ; i < listSound->count ; i++ )
{
this = (sound_t *)listSound->list[i];
@@ -97,8 +109,18 @@ void playSound(char *name, int group)
}
}
+void setSoundActive(bool_t n)
+{
+ isSoundActive = n;
+}
+
void quitSound()
{
+ if( isSoundInit == FALSE )
+ {
+ return;
+ }
+
destroyListItem(listSound, destroySound);
isSoundInit = FALSE;
printf("quit sound..\n");
diff --git a/src/tux.c b/src/tux.c
index 212242f..c143302 100644
--- a/src/tux.c
+++ b/src/tux.c
@@ -7,6 +7,7 @@
#include "main.h"
#include "tux.h"
#include "image.h"
+#include "sound.h"
#include "layer.h"
#include "screen_world.h"
#include "shot.h"
@@ -239,6 +240,40 @@ tux_t* isConflictWithListTux(list_t *listTux, int x, int y, int w, int h)
return NULL;
}
+int isConflictTuxWithListTux(tux_t *tux, list_t *listTux)
+{
+ tux_t *thisTux;
+ int tux_x, tux_y, tux_w, tux_h;
+ int thisTux_x, thisTux_y, thisTux_w, thisTux_h;
+ int i;
+
+ assert( tux != NULL );
+ assert( listTux != NULL );
+
+ getTuxProportion(tux, &tux_x, &tux_y, &tux_w, &tux_h);
+
+ for( i = 0 ; i < listTux->count ; i++ )
+ {
+ thisTux = (tux_t *)listTux->list[i];
+ assert( thisTux != NULL );
+
+ if( thisTux == tux )
+ {
+ continue;
+ }
+
+ getTuxProportion(thisTux, &thisTux_x, &thisTux_y, &thisTux_w, &thisTux_h);
+
+ if( conflictSpace(tux_x, tux_y, tux_w, tux_h,
+ thisTux_x, thisTux_y, thisTux_w, thisTux_h) )
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static void timer_spawnTux(void *p)
{
tux_t *tux;
@@ -313,6 +348,8 @@ void switchTuxGun(tux_t *tux)
return;
}
+ playSound("switch_gun", SOUND_GROUP_BASE);
+
for( i = tux->gun+1 ; i < GUN_COUNT ; i++ )
{
if( tux->shot[i] > 0 )
@@ -343,6 +380,7 @@ void eventTuxIsDead(tux_t *tux)
return;
}
+ playSound("dead", SOUND_GROUP_BASE);
tux->status = TUX_STATUS_DEAD;
if( getNetTypeGame() != NET_GAME_TYPE_CLIENT )
@@ -361,6 +399,8 @@ static void eventTuxIsDeadWIthShot(tux_t *tux,shot_t *shot)
void tuxTeleport(tux_t *tux)
{
+ playSound("teleport", SOUND_GROUP_BASE);
+
findFreeSpace(&tux->x, &tux->y, TUX_WIDTH, TUX_HEIGHT);
if( getNetTypeGame() == NET_GAME_TYPE_SERVER )
@@ -413,7 +453,7 @@ void eventConflictShotWithTux(list_t *listTux, list_t *listShot)
}
}
-void moveTux(tux_t *tux,int n)
+void moveTux(tux_t *tux, int n)
{
int px, py;
int zal_x, zal_y;
@@ -429,6 +469,26 @@ void moveTux(tux_t *tux,int n)
return;
}
+ if( n == TUX_LEFT && tux->x < 0 )
+ {
+ return;
+ }
+
+ if( n == TUX_RIGHT && tux->x > WINDOW_SIZE_X )
+ {
+ return;
+ }
+
+ if( n == TUX_UP && tux->y < 0 )
+ {
+ return;
+ }
+
+ if( n == TUX_DOWN && tux->y > WINDOW_SIZE_Y )
+ {
+ return;
+ }
+
arena = getWorldArena();
getCourse(tux->position, &px, &py);
@@ -447,7 +507,7 @@ void moveTux(tux_t *tux,int n)
getTuxProportion(tux, &x, &y, &w, &h);
if( tux->bonus != BONUS_GHOST && (
- isConflictWithListTux(arena->listTux, x, y, w, h) != tux ||
+ isConflictTuxWithListTux(tux, arena->listTux) ||
isConflictWithListWall(arena->listWall, x, y, w, h) ) )
{
tux->x = zal_x;
diff --git a/src/widget_textfield.c b/src/widget_textfield.c
index 67138fb..99b861c 100644
--- a/src/widget_textfield.c
+++ b/src/widget_textfield.c
@@ -109,6 +109,11 @@ static void readKey(widget_textfield_t *p)
return;
}
+ if( p->w > WIDGET_TEXTFIELD_WIDTH-40 )
+ {
+ return;
+ }
+
//klavesy abecedy
for(i=SDLK_SPACE /*SDLK_a*/;i<=SDLK_z;i++)
{
@@ -118,11 +123,13 @@ static void readKey(widget_textfield_t *p)
p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
strcat( p->text, SDL_GetKeyName(i) );
+ getTextSize(p->text, &p->w, &p->h);
if( mapa[SDLK_LSHIFT] == SDL_PRESSED ||
mapa[SDLK_RSHIFT] == SDL_PRESSED)
{
p->text[ strlen( p->text ) - 1 ] -= 32;
+ getTextSize(p->text, &p->w, &p->h);
return;
}
}
@@ -135,6 +142,7 @@ static void readKey(widget_textfield_t *p)
{
p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
strcat( p->text, SDL_GetKeyName(i) );
+ getTextSize(p->text, &p->w, &p->h);
return;
}
}
@@ -146,6 +154,7 @@ static void readKey(widget_textfield_t *p)
{
p->time = WIDGET_TEXTFIELD_TIME_READ_KEY;
strncat( p->text, SDL_GetKeyName(i)+1, 1 ); // napr. "[4]"
+ getTextSize(p->text, &p->w, &p->h);
return;
}
}