r143 - in trunk/src: . objects
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sat Sep 3 20:13:19 EDT 2005
Author: jonas
Date: 2005-09-03 20:13:18 -0400 (Sat, 03 Sep 2005)
New Revision: 143
Modified:
trunk/src/Makefile
trunk/src/animation.cpp
trunk/src/animation.h
trunk/src/characters_common.cpp
trunk/src/characters_common.h
trunk/src/common.h
trunk/src/imgcache.cpp
trunk/src/imgcache.h
trunk/src/lost_penguins.cpp
trunk/src/objects/Makefile
trunk/src/objects/baleog.cpp
trunk/src/objects/erik.cpp
trunk/src/objects/olaf.cpp
trunk/src/objects_common.cpp
trunk/src/objects_common.h
trunk/src/players_common.cpp
Log:
Numerious animation loading improvements:
o lvl2magick now creates an animation data file
o output name and id tag name changes in lvl2magick (minor)
o scale_factor in ImageCache should scale the area, not the area squared
o add directions to im_die (im_die_left, im_die_right)
o fixed a huge bug that only allowed start_pos=0 in the animation class
o removed cur_im_pos (=cur_frame_num+start_pos) in the animation class
o added animfile, datadir and lvlscale as specifiable options
(lvlscale specifies the scale factor for lvl images)
o added loadAnimation(...) to load animations from the animation data file
o used loadAnimation(...) and the new animations for Erik
Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/Makefile 2005-09-04 00:13:18 UTC (rev 143)
@@ -35,6 +35,7 @@
distclean: clean
rm -f *~
rm -f Makefile.dep
+ rm -f Makefile.dep.bak
+$(MAKE) -C objects distclean
depend:
Modified: trunk/src/animation.cpp
===================================================================
--- trunk/src/animation.cpp 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/animation.cpp 2005-09-04 00:13:18 UTC (rev 143)
@@ -34,11 +34,9 @@
if (animation_type&ATYPE_ALL_NORMAL) {
forward=true;
cur_frame_num=0;
- cur_im_pos=start_pos;
} else {
forward=false;
cur_frame_num=frames-1;
- cur_im_pos=end_pos;
}
}
bool Animation::stopAnim() {
@@ -50,10 +48,8 @@
cur_time=0;
if (animation_type&ATYPE_ALL_LSTART) {
cur_frame_num=0;
- cur_im_pos=start_pos;
} else {
cur_frame_num=frames-1;
- cur_im_pos=end_pos;
}
}
return isRunning();
@@ -128,7 +124,7 @@
}
Frame Animation::getFrame() const {
if (!isValid()) cout << "Invalid Frame of an invalid animation!" << endl;
- return Frame(base_image.surface,base_image.description[cur_frame_num]);
+ return Frame(base_image.surface,base_image.description[cur_frame_num+start_pos]);
}
Frame Animation::getBaseFrame() const {
if (!isValid()) cout << "Invalid Base Frame of an invalid animation!" << endl;
@@ -244,7 +240,6 @@
cur_time=0;
forward=true;
cur_frame_num=0;
- cur_im_pos=start_pos;
is_running=false;
is_fixed=true;
is_valid=true;
@@ -260,11 +255,9 @@
if (animation_type&ATYPE_ALL_NORMAL) {
forward=true;
cur_frame_num=0;
- cur_im_pos=start_pos;
} else {
forward=false;
cur_frame_num=frames-1;
- cur_im_pos=end_pos;
}
}
return is_valid;
Modified: trunk/src/animation.h
===================================================================
--- trunk/src/animation.h 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/animation.h 2005-09-04 00:13:18 UTC (rev 143)
@@ -17,7 +17,7 @@
/// \param ashift_x x shift value
/// \param ashift_y y shift value
///
- /// To load one still image simply use: Animation(loadImage(1,"image_name.png"))
+ /// To load one still image simply use: Animation(imgcache->loadImage(1,"image_name.png"))
Animation(const Image& abase_image,
Uint32 aduration=0,
Uint16 aframes=1,
@@ -45,7 +45,7 @@
/// Calculates and returns the current frame
Frame getFrame() const;
/// Calculates and returns the current draw position using:
- /// base_pos,bp_type,allign_type,shift,cur_im_pos
+ /// base_pos,bp_type,allign_type,shift
SDL_Rect getDrawPos() const;
/// HACK: Return the dimensions of the first frame
SDL_Rect getFrameDim() const;
@@ -129,8 +129,6 @@
bool forward;
/// Current frame number
Uint16 cur_frame_num;
- /// Current position of the base_image_desc array
- Uint16 cur_im_pos;
/// Current time
Uint32 cur_time;
};
Modified: trunk/src/characters_common.cpp
===================================================================
--- trunk/src/characters_common.cpp 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/characters_common.cpp 2005-09-04 00:13:18 UTC (rev 143)
@@ -17,7 +17,8 @@
speed(0),
gravity(900),
Dgrav(0),
- im_die(NULL),
+ im_die_left(NULL),
+ im_die_right(NULL),
dense_types(NOTHING),
enemy_types(NOTHING),
weapon(Weapon(0)) {
Modified: trunk/src/characters_common.h
===================================================================
--- trunk/src/characters_common.h 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/characters_common.h 2005-09-04 00:13:18 UTC (rev 143)
@@ -174,7 +174,8 @@
//temporary attributes
Sint16 Dgrav;
//Die animation
- Animation* im_die;
+ Animation* im_die_left;
+ Animation* im_die_right;
//Entered objects
std::set<Object *> enter;
//Touched objects
Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/common.h 2005-09-04 00:13:18 UTC (rev 143)
@@ -87,6 +87,11 @@
#define ATYPE_ALL_NORMAL 0x0000000F
#define ATYPE_ALL_REV 0x000000F0
+//Description formats
+#define DESC_NONE 0x00000000
+#define DESC_LVLANIM 0x00000001
+#define DESC_ANIM_LVLANIM 0x00000002
+
enum ConfigKey {
KEY_START,
KEY_LEFT,
@@ -152,7 +157,9 @@
int audio_channels;
string datadir;
string map;
+ string anim_file;
SDLKey keybind[30];
+ double lvlscale;
};
/**\brief Frame format
Modified: trunk/src/imgcache.cpp
===================================================================
--- trunk/src/imgcache.cpp 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/imgcache.cpp 2005-09-04 00:13:18 UTC (rev 143)
@@ -16,10 +16,10 @@
}
SDL_Rect& ImageCache::scaleRectangle(SDL_Rect& base_rect, double scale_factor) {
- base_rect.x=(Sint16)(base_rect.x*scale_factor);
- base_rect.y=(Sint16)(base_rect.y*scale_factor);
- base_rect.w=(Uint16)(base_rect.w*scale_factor);
- base_rect.h=(Uint16)(base_rect.h*scale_factor);
+ base_rect.x=(Sint16)(base_rect.x*sqrt(scale_factor));
+ base_rect.y=(Sint16)(base_rect.y*sqrt(scale_factor));
+ base_rect.w=(Uint16)(base_rect.w*sqrt(scale_factor));
+ base_rect.h=(Uint16)(base_rect.h*sqrt(scale_factor));
return base_rect;
}
@@ -31,7 +31,7 @@
}
Image& ImageCache::scaleImage(Image& original_image, double scale_factor) {
- SDL_Surface* newsurface=zoomSurface(original_image.surface, scale_factor, scale_factor, 1);
+ SDL_Surface* newsurface=zoomSurface(original_image.surface, sqrt(scale_factor), sqrt(scale_factor), 1);
SDL_FreeSurface(original_image.surface);
original_image.surface=newsurface;
scaleDescription(original_image.description, scale_factor);
@@ -143,7 +143,9 @@
std::istringstream tmpstream(tmpline);
tmpstream >> arg1 >> arg2 >> arg3 >> arg4 >> arg5 >> arg6;
- if (arg1 == "DESCRIPTION") {
+ if (arg1 == "ANIMATION") {
+ description_type=DESC_NONE;
+ } else if (arg1 == "DESCRIPTION") {
if (arg2 == "LVLANIM") {
description_type=DESC_LVLANIM;
} else if (arg2 == "FIX_RECT") {
Modified: trunk/src/imgcache.h
===================================================================
--- trunk/src/imgcache.h 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/imgcache.h 2005-09-04 00:13:18 UTC (rev 143)
@@ -1,9 +1,6 @@
#ifndef DEF_IMGCACHE_H
#define DEF_IMGCACHE_H 1
-#define DESC_NONE 0x00000000
-#define DESC_LVLANIM 0x00000001
-
/** \brief Caches images.
Caches images supported by SDL_image according to their name
Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/lost_penguins.cpp 2005-09-04 00:13:18 UTC (rev 143)
@@ -98,7 +98,9 @@
config.audio_format = MIX_DEFAULT_FORMAT;
config.audio_channels = 2;
config.datadir="data/";
+ config.anim_file="animation_data.anim";
config.map="map1.cfg";
+ config.lvlscale=4;
//key bindings
config.keybind[KEY_LEFT] = SDLK_LEFT;
@@ -133,6 +135,9 @@
if (option[0]=='#') continue;
if (option=="datadir") {
config.datadir=arg1;
+ if (config.datadir.substr(config.datadir.size() - 1, 1)!="/") config.datadir+="/";
+ } else if (option=="animfile") {
+ config.anim_file=arg1;
} else if (option=="width") {
config.width=atoi(arg1.c_str());
} else if (option=="height") {
@@ -165,6 +170,13 @@
config.map=argv[i+1];
config.map+=".cfg";
i++;
+ } else if ( strcmp(argv[i], "-datadir") == 0 ) {
+ config.datadir=argv[i+1];
+ if (config.datadir.substr(config.datadir.size() - 1, 1)!="/") config.datadir+="/";
+ i++;
+ } else if ( strcmp(argv[i], "-animfile") == 0 ) {
+ config.anim_file=argv[i+1];
+ i++;
} else if ( strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
usage();
} else usage();
@@ -173,6 +185,8 @@
void usage() {
cout << "Usage: lost_penguins [OPTIONS]\n\n";
+ cout << " -datadir Changes the data directory. Default: data/\n";
+ cout << " -animfile Changes the animation file name. Default: animation_data.anim\n";
cout << " -w, -width Changes resolution (width) of game. Default: 640\n";
cout << " -h, -height Changes resolution (height) of game. Default: 480\n";
cout << " -fs, -full Enable fullscreen. Default: disabled\n";
Modified: trunk/src/objects/Makefile
===================================================================
--- trunk/src/objects/Makefile 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/objects/Makefile 2005-09-04 00:13:18 UTC (rev 143)
@@ -30,6 +30,7 @@
distclean: clean
rm -f *~
rm -f Makefile.dep
+ rm -f Makefile.dep.bak
depend:
touch Makefile.dep
Modified: trunk/src/objects/baleog.cpp
===================================================================
--- trunk/src/objects/baleog.cpp 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/objects/baleog.cpp 2005-09-04 00:13:18 UTC (rev 143)
@@ -12,7 +12,7 @@
Player(imagename,xcord,ycord,pname) {
im_left=loadAnimation(scenario->imgcache->loadImage(1,"baleog1_left.bmp"));
im_right=loadAnimation(scenario->imgcache->loadImage(1,"baleog1_right.bmp"));
- im_run_left=loadAnimation(scenario->imgcache->loadImage(8,"baleog1-run_left.png"),1000,8);
+ im_run_left=loadAnimation(scenario->imgcache->loadImage("baleog1-run_left.png"),1000,8);
im_run_right=loadAnimation(scenario->imgcache->loadImage(8,"baleog1-run_right.png"),1000,8);
im_fall_left=im_left;
im_fall_right=im_right;
Modified: trunk/src/objects/erik.cpp
===================================================================
--- trunk/src/objects/erik.cpp 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/objects/erik.cpp 2005-09-04 00:13:18 UTC (rev 143)
@@ -15,6 +15,7 @@
jump(V_JUMP),
jump2(V_JUMP2) {
weapon=Weapon(-1,W_PRESSURE,WS_PRESSURE);
+/*
im_left=loadAnimation(scenario->imgcache->loadImage("erik1_left.bmp"));
im_right=loadAnimation(scenario->imgcache->loadImage(1,"erik1_right.bmp"));
im_run_right=im_right;
@@ -25,6 +26,19 @@
im_krit_right=im_right;
im_land_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),T_IRR,1,ATYPE_ONCE_END);
im_land_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),T_IRR,1,ATYPE_ONCE_END);
+*/
+ im_left=loadAnimation("eric_idle_left",config.lvlscale,1000);
+ im_right=loadAnimation("eric_idle_right",config.lvlscale,1000);
+ im_run_left=loadAnimation("eric_run_left",config.lvlscale,1000);
+ im_run_right=loadAnimation("eric_run_right",config.lvlscale,1000);
+ im_fall_left=loadAnimation("eric_fall_left",config.lvlscale,1000);
+ im_fall_right=loadAnimation("eric_fall_right",config.lvlscale,1000);
+ im_krit_left=loadAnimation("eric_fall_fast_left",config.lvlscale,1000);
+ im_krit_right=loadAnimation("eric_fall_fast_right",config.lvlscale,1000);
+ im_land_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),T_IRR,1,ATYPE_ONCE_END);
+ im_land_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),T_IRR,1,ATYPE_ONCE_END);
+ im_die_left=loadAnimation("eric_idle_left",config.lvlscale,1000);
+ im_die_right=loadAnimation("eric_idle_left",config.lvlscale,1000);
au_jump=scenario->sndcache->loadWAV("rboots.wav");
au_hit=scenario->sndcache->loadWAV("erikhit.wav");
au_run=NULL;
Modified: trunk/src/objects/olaf.cpp
===================================================================
--- trunk/src/objects/olaf.cpp 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/objects/olaf.cpp 2005-09-04 00:13:18 UTC (rev 143)
@@ -33,7 +33,8 @@
im_run_shield_left=im_shield_left;
im_fall_shield_left=im_shield_left;
im_fall_shield_right=im_shield_right;
- im_die=loadAnimation(scenario->imgcache->loadImage(60,"kuru.bmp"),2000,12,0,ATYPE_ONCE_END);
+ im_die_left=loadAnimation(scenario->imgcache->loadImage(60,"kuru.bmp"),2000,12,0,ATYPE_ONCE_END);
+ im_die_right=im_die_left;
au_small=scenario->sndcache->loadWAV("blob.wav");
au_big=scenario->sndcache->loadWAV("unblob.wav");
au_fart=scenario->sndcache->loadWAV("fart1.wav");
Modified: trunk/src/objects_common.cpp
===================================================================
--- trunk/src/objects_common.cpp 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/objects_common.cpp 2005-09-04 00:13:18 UTC (rev 143)
@@ -59,6 +59,66 @@
return ok;
}
+Animation* Object::loadAnimation(string anim_name,
+ double scale_factor,
+ Uint32 aduration,
+ Uint16 aanimation_type,
+ BasePointType abp_type,
+ AllignType aallign_type,
+ Sint16 ashift_x,
+ Sint16 ashift_y) {
+
+ /* Parse animation data file */
+ ifstream file;
+ string tmpline;
+ string loadfile=config.datadir+config.anim_file;
+
+ file.open(loadfile.c_str());
+ if (!file) {
+ cout << "Failed to open the animation data file: " << loadfile << " => Couldn't load " << anim_name << " animation!\n" << endl;
+ return NULL;
+ } else {
+ string arg1,arg2,arg3,arg4,arg5,arg6;
+ string tmp_anim_name="";
+ string imagename="";
+ Uint16 astart_pos=0;
+ Uint16 aframes=1;
+
+ Uint16 description_type=DESC_NONE;
+
+ while (getline(file,tmpline)) {
+ arg1=arg2=arg3=arg4=arg5=arg6="";
+ std::istringstream tmpstream(tmpline);
+ tmpstream >> arg1 >> arg2 >> arg3 >> arg4 >> arg5 >> arg6;
+
+ if (arg1 == "DESCRIPTION") {
+ description_type=DESC_NONE;
+ } else if (arg1 == "ANIMATION") {
+ if (arg2 == "LVLANIM") {
+ description_type=DESC_ANIM_LVLANIM;
+ } else {
+ description_type=DESC_NONE;
+ }
+ }
+
+ if (description_type==DESC_ANIM_LVLANIM) {
+ if (arg1.empty() || arg2.empty() || arg3.empty() || arg4.empty()) {
+ } else {
+ tmp_anim_name=arg1;
+ imagename=arg2;
+ astart_pos=(Uint16)atoi(arg3.c_str());
+ aframes=(Uint16)atoi(arg4.c_str());
+
+ if (anim_name==tmp_anim_name) {
+ return loadAnimation(imgcache->loadImage(imagename,scale_factor),aduration,aframes,aanimation_type,astart_pos,abp_type,aallign_type,ashift_x,ashift_y);
+ }
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
Animation* Object::loadAnimation(const Image& abase_image,
Uint32 aduration,
Uint16 aframes,
Modified: trunk/src/objects_common.h
===================================================================
--- trunk/src/objects_common.h 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/objects_common.h 2005-09-04 00:13:18 UTC (rev 143)
@@ -105,6 +105,15 @@
delete this;
}
//@}
+ /// Load an animation bound onto this object from an animation data file
+ Animation* loadAnimation(string anim_name,
+ double scale_factor=1,
+ Uint32 aduration=0,
+ Uint16 aanimation_type=ATYPE_LOOP,
+ BasePointType abp_type=BP_MD,
+ AllignType aallign_type=AT_MD,
+ Sint16 ashift_x=0,
+ Sint16 ashift_y=0);
/// Load an animation bound onto this object
Animation* loadAnimation(const Image& abase_image,
Uint32 aduration=0,
Modified: trunk/src/players_common.cpp
===================================================================
--- trunk/src/players_common.cpp 2005-09-03 17:18:56 UTC (rev 142)
+++ trunk/src/players_common.cpp 2005-09-04 00:13:18 UTC (rev 143)
@@ -279,18 +279,18 @@
Character* deadplr=scenario->pool->addCharacter(new DeadPlayer("dead_player.bmp",pos.x,pos.y));
switch(weap.getSubType()) {
case WS_FIRE: {
- if (deadplr) deadplr->setEvent(new CAnimEvent(deadplr,10,0,ESTATE_BUSY,au_fire,im_die));
+ if (deadplr) deadplr->setEvent(new CAnimEvent(deadplr,10,0,ESTATE_BUSY,au_fire,(state&STATE_LEFT) ? im_die_left : im_die_right));
else sfxeng->playWAV(au_fire);
break;
}
case WS_WATER: {
- if (deadplr) deadplr->setEvent(new CAnimEvent(deadplr,10,0,ESTATE_BUSY,au_drown,im_die));
+ if (deadplr) deadplr->setEvent(new CAnimEvent(deadplr,10,0,ESTATE_BUSY,au_drown,(state&STATE_LEFT) ? im_die_left : im_die_right));
else sfxeng->playWAV(au_drown);
break;
}
//WS_NORMAL, WS_ELECTRIC, WS_FIRE, WS_PRESSURE
default: {
- if (deadplr) deadplr->setEvent(new CAnimEvent(deadplr,10,0,ESTATE_BUSY,au_die,im_die));
+ if (deadplr) deadplr->setEvent(new CAnimEvent(deadplr,10,0,ESTATE_BUSY,au_die,(state&STATE_LEFT) ? im_die_left : im_die_right));
else sfxeng->playWAV(au_die);
}
}
More information about the lostpenguins-commits
mailing list