~ubuntu-branches/ubuntu/natty/smc/natty

« back to all changes in this revision

Viewing changes to src/objects/movingsprite.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Muammar El Khatib
  • Date: 2009-01-30 14:20:20 UTC
  • mfrom: (1.1.5 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090130142020-slza1cg603t34uyq
Tags: 1.7-1
* New upstream release. (Closes: #511404)
* debian/control: smc Build-Depends on libboost-filesystem1.37-dev instead of
  libboost-filesystem-dev.
* debian/control: dpatch build dependency has been added in order to make the
  update of libboost-filesystem1.37-dev.
* smc is not failing anymore with undefined symbol error in CEGUI. Problem was
  caused by a missed directory called translations under /usr/share/games/smc/
  (Closes: #508106)
* smc now suggests smc-music. Thanks to Alessio Treglia for reporting this.
  (Closes: #511660)
* Bug 'Segmentation fault on startup' is no longer present in this new 
  upstream version.  (Closes: #512841)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
/* *** *** *** *** *** *** *** cMovingSprite *** *** *** *** *** *** *** *** *** *** */
35
35
 
36
 
cMovingSprite :: cMovingSprite( GL_Surface *new_image /* = NULL */, float x /* = 0 */, float y /* = 0 */, bool del_img /* = 0 */ )
 
36
cMovingSprite :: cMovingSprite( cGL_Surface *new_image /* = NULL */, float x /* = 0 */, float y /* = 0 */, bool del_img /* = 0 */ )
37
37
: cSprite( new_image, x, y, del_img )
38
38
{
39
39
        cMovingSprite::Init();
65
65
        
66
66
        direction = DIR_UNDEFINED;
67
67
        start_direction = DIR_UNDEFINED;
 
68
        can_be_on_ground = 1;
68
69
        ground_object = NULL;
69
70
 
70
71
        ice_resistance = 0;
79
80
        moving_sprite->sprite_array = sprite_array;
80
81
        moving_sprite->Set_Massive_Type( massivetype );
81
82
        moving_sprite->can_be_ground = can_be_ground;
 
83
        moving_sprite->can_be_on_ground = can_be_on_ground;
82
84
        moving_sprite->Set_Ignore_Camera( no_camera );
83
85
        moving_sprite->Set_Shadow_Pos( shadow_pos );
84
86
        moving_sprite->Set_Shadow_Color( shadow_color );
86
88
        return moving_sprite;
87
89
}
88
90
 
89
 
void cMovingSprite :: Set_Image( GL_Surface *new_image, bool new_start_image /* = 0 */, bool del_img /* = 0 */ )
 
91
void cMovingSprite :: Set_Image( cGL_Surface *new_image, bool new_start_image /* = 0 */, bool del_img /* = 0 */ )
90
92
{
91
93
        // get a possible collision point change
92
94
        GL_point col_pos_change = GL_point();
449
451
{
450
452
        if( col_dir != DIR_UNDEFINED )
451
453
        {
452
 
                // check if the collision direction is in the front
453
 
                if( ( col_dir == DIR_RIGHT && direction != DIR_RIGHT ) || ( col_dir == DIR_LEFT && direction != DIR_LEFT ) ||
454
 
                        ( col_dir == DIR_UP && direction != DIR_UP ) || ( col_dir == DIR_DOWN && direction != DIR_DOWN ) )
 
454
                // check if the collision direction is in front
 
455
                if( ( col_dir == DIR_RIGHT && direction != col_dir ) || ( col_dir == DIR_LEFT && direction != col_dir ) ||
 
456
                        ( col_dir == DIR_UP && direction != col_dir ) || ( col_dir == DIR_DOWN && direction != col_dir ) )
455
457
                {
456
 
                        // collision direction is not in the front
 
458
                        // collision direction is not in front
457
459
                        return;
458
460
                }
459
461
        }
772
774
        return 0;
773
775
}
774
776
 
775
 
void cMovingSprite :: Set_on_Ground( cSprite *obj )
 
777
void cMovingSprite :: Set_on_Ground( cSprite *obj, bool set_on_top /* = 1 */ )
776
778
{
777
 
        // invalid
778
 
        if( !obj )
 
779
        // invalid or can't be on ground
 
780
        if( !obj || !can_be_on_ground )
779
781
        {
780
782
                return;
781
783
        }
782
784
 
783
 
        // if can't be ground object
 
785
        // if wanted object can't be ground object
784
786
        if( !obj->can_be_ground )
785
787
        {
786
788
                return;
788
790
 
789
791
        // set groundobject
790
792
        ground_object = obj;
791
 
        Set_on_Top( ground_object, 0 );
 
793
        // set on top
 
794
        if( set_on_top )
 
795
        {
 
796
                Set_on_Top( ground_object, 0 );
 
797
        }
792
798
}
793
799
 
794
800
void cMovingSprite :: Check_on_Ground( void )
795
801
{
 
802
        // can't be on ground
 
803
        if( !can_be_on_ground )
 
804
        {
 
805
                return;
 
806
        }
 
807
 
796
808
        if( type != TYPE_PLAYER && sprite_array != ARRAY_ENEMY && sprite_array != ARRAY_ACTIVE )
797
809
        {
798
810
                return;
810
822
                }
811
823
        }
812
824
 
813
 
        // don't check if flying
814
 
        if( state == STA_FLY )
 
825
        // don't check if flying or linked
 
826
        if( state == STA_FLY || state == STA_OBJ_LINKED )
815
827
        {
816
828
                return;
817
829
        }
872
884
 
873
885
                        if( collision->direction == DIR_LEFT ) 
874
886
                        {
875
 
                                Col_Move( 2, 0, 0, 1 );
 
887
                                Col_Move( 1, 0, 0, 1 );
876
888
                        }
877
889
                        else if( collision->direction == DIR_RIGHT ) 
878
890
                        {
879
 
                                Col_Move( -2, 0, 0, 1 );
 
891
                                Col_Move( -1, 0, 0, 1 );
880
892
                        }
881
893
                        else if( collision->direction == DIR_UP ) 
882
894
                        {
883
 
                                Col_Move( 0, 2, 0, 1 );
 
895
                                Col_Move( 0, 1, 0, 1 );
884
896
                        }
885
897
                        else if( collision->direction == DIR_DOWN ) 
886
898
                        {
887
 
                                Col_Move( 0, -2, 0, 1 );
 
899
                                Col_Move( 0, -1, 0, 1 );
888
900
                        }
889
901
                }
890
902
 
912
924
                {
913
925
                        if( moving_ground_object->velx != 0 || moving_ground_object->vely != 0 )
914
926
                        {
915
 
                                // check ground first because the moving object velocity
 
927
                                // check ground first because of the moving object velocity
916
928
                                Check_on_Ground();
 
929
                                // save posx for possible can not move test
 
930
                                float posy_orig = posy;
 
931
                                /* stop object from getting stopped of the moving object which did not yet move itself
 
932
                                 * for example the player always moves as last
 
933
                                */
 
934
                                bool is_massive = 0;
 
935
                                if( moving_ground_object->massivetype == MASS_MASSIVE )
 
936
                                {
 
937
                                        moving_ground_object->massivetype = MASS_PASSIVE;
 
938
                                        is_massive = 1;
 
939
                                }
917
940
                                // move
918
941
                                Col_Move( moving_ground_object->velx, moving_ground_object->vely, 0, 0, 0 );
 
942
 
 
943
                                if( is_massive )
 
944
                                {
 
945
                                        moving_ground_object->massivetype = MASS_MASSIVE;
 
946
                                }
 
947
                                // if ground object is moving up
 
948
                                if( moving_ground_object->vely < 0 )
 
949
                                {
 
950
                                        // test if we could not move upwards because something did block us in Col_Move()
 
951
                                        if( posy == posy_orig )
 
952
                                        {
 
953
                                                // massive
 
954
                                                if( moving_ground_object->massivetype == MASS_MASSIVE )
 
955
                                                {
 
956
                                                        // got crunched
 
957
                                                        DownGrade( 1 );
 
958
                                                }
 
959
                                                // halfmassive
 
960
                                                else if( moving_ground_object->massivetype == MASS_HALFMASSIVE )
 
961
                                                {
 
962
                                                        // lost ground
 
963
                                                        Move( 0, 1.9f, 1 );
 
964
                                                        Reset_on_Ground();
 
965
                                                }
 
966
                                        }
 
967
                                }
919
968
                        }
920
969
                }
921
970
        }
1007
1056
        }
1008
1057
}
1009
1058
 
 
1059
void cMovingSprite :: Handle_Move_Object_Collision( cObjectCollision *collision )
 
1060
{
 
1061
        // if not massive
 
1062
        if( massivetype != MASS_MASSIVE )
 
1063
        {
 
1064
                return;
 
1065
        }
 
1066
 
 
1067
        // get object
 
1068
        cMovingSprite *obj = NULL;
 
1069
 
 
1070
        if( collision->type == CO_ENEMY )
 
1071
        {
 
1072
                obj = static_cast<cMovingSprite *>(pActive_Sprite_Manager->Get_Pointer( collision->number ));
 
1073
 
 
1074
                // ignore these enemies
 
1075
                if( obj->type == TYPE_THROMP || obj->type == TYPE_EATO || obj->type == TYPE_JPIRANHA || obj->type == TYPE_STATIC_ENEMY )
 
1076
                {
 
1077
                        return;
 
1078
                }
 
1079
        }
 
1080
        else if( collision->type == CO_PLAYER )
 
1081
        {
 
1082
                obj = static_cast<cMovingSprite *>(pPlayer);
 
1083
        }
 
1084
        // not a valid type
 
1085
        else
 
1086
        {
 
1087
                return;
 
1088
        }
 
1089
 
 
1090
        // top collision is handled in cMovingSprite::Collide_Move()
 
1091
        if( collision->direction == DIR_BOTTOM )
 
1092
        {
 
1093
                if( obj->ground_object && obj->ground_object->massivetype == MASS_MASSIVE )
 
1094
                {
 
1095
                        // got crunched
 
1096
                        obj->DownGrade( 1 );
 
1097
                }
 
1098
                else
 
1099
                {
 
1100
                        // move
 
1101
                        obj->Col_Move( 0, vely, 0, 0, 0 );
 
1102
                }
 
1103
        }
 
1104
        else if( ( collision->direction == DIR_LEFT && velx < 0 ) || ( collision->direction == DIR_RIGHT && velx > 0 ) )
 
1105
        {
 
1106
                // save posx for possible can not move test
 
1107
                float posx_orig = obj->posx;
 
1108
                // move
 
1109
                obj->Col_Move( velx, 0, 0, 0, 0 );
 
1110
 
 
1111
                // test if we could not move it upwards because something did block it
 
1112
                if( obj->posx == posx_orig )
 
1113
                {
 
1114
                        // got crunched
 
1115
                        obj->DownGrade( 1 );
 
1116
                }
 
1117
        }
 
1118
}
 
1119
 
1010
1120
unsigned int cMovingSprite :: Validate_Collision( cSprite *obj )
1011
1121
{
1012
1122
        if( obj->massivetype == MASS_MASSIVE )
1015
1125
        }
1016
1126
        if( obj->massivetype == MASS_HALFMASSIVE )
1017
1127
        {
1018
 
                // if moving downwards and object is on top
 
1128
                // if moving downwards and the object is on bottom
1019
1129
                if( vely >= 0 && Is_on_Top( obj ) )
1020
1130
                {
1021
1131
                        return 2;
1032
1142
                cBaseBox *box = static_cast<cBaseBox *>(obj);
1033
1143
 
1034
1144
                // ghost
1035
 
                if( box->box_invisible == 2 )
 
1145
                if( box->box_invisible == BOX_GHOST )
1036
1146
                {
1037
1147
                        // maryo is not ghost
1038
1148
                        if( pPlayer->maryo_type != MARYO_GHOST )
1045
1155
        return -1;
1046
1156
}
1047
1157
 
 
1158
int cMovingSprite :: Validate_Collision_Object_On_Top( cMovingSprite *moving_sprite )
 
1159
{
 
1160
        // don't handle if not moving upwards or slower
 
1161
        if( moving_sprite->Is_on_Top( this ) && direction == DIR_UP && moving_sprite->vely > vely && moving_sprite->can_be_on_ground )
 
1162
        {
 
1163
                // halfmassive
 
1164
                if( massivetype == MASS_HALFMASSIVE )
 
1165
                {
 
1166
                        // only if no ground
 
1167
                        if( !moving_sprite->ground_object )
 
1168
                        {
 
1169
                                return 2;
 
1170
                        }
 
1171
                }
 
1172
                // massive
 
1173
                else if( massivetype == MASS_MASSIVE )
 
1174
                {
 
1175
                        // always pick up
 
1176
                        if( moving_sprite->ground_object != this )
 
1177
                        {
 
1178
                                moving_sprite->ground_object = this;
 
1179
                                return 0;
 
1180
                        }
 
1181
                }
 
1182
        }
 
1183
 
 
1184
        return -1;
 
1185
}
 
1186
 
1048
1187
void cMovingSprite :: Send_Collision( cObjectCollision *collision )
1049
1188
{
1050
1189
        // empty collision
1059
1198
                return;
1060
1199
        }
1061
1200
 
1062
 
        /* if collision is received ignore
1063
 
         * a received collision can't create a received collision
 
1201
        /* if collision is received ignore it
 
1202
         * a received collision can't create another received collision
1064
1203
         * only a self detected collision can create a received collision
1065
1204
        */
1066
1205
        if( collision->received )
1104
1243
        {
1105
1244
                ncollision->type = CO_PLAYER;
1106
1245
        }
1107
 
        
 
1246
 
1108
1247
        // add collision to the list
1109
1248
        if( collision->type == CO_PLAYER )
1110
1249
        {