r120 - in trunk/src: . objects
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Sat Jun 18 18:47:14 EDT 2005
Author: jonas
Date: 2005-06-18 18:47:14 -0400 (Sat, 18 Jun 2005)
New Revision: 120
Modified:
trunk/src/gfxeng.cpp
trunk/src/gfxeng.h
trunk/src/input.cpp
trunk/src/input.h
trunk/src/lost_penguins.cpp
trunk/src/menu.cpp
trunk/src/menu.h
trunk/src/objects/olaf.cpp
trunk/src/physics.cpp
trunk/src/physics.h
trunk/src/sfxeng.cpp
Log:
add a prelimenary map (game) edit mode, make shift a member variable of gfxeng, some sfxeng volume tweaks, option parsers fixes
Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/gfxeng.cpp 2005-06-18 22:47:14 UTC (rev 120)
@@ -30,6 +30,8 @@
show_fps(true),
fullscreen(config.full),
vflags(SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF) {
+ shift.x=0;
+ shift.y=0;
resize(config.width, config.height);
lifeimage=new Animation(imgcache->loadImage("life.bmp"));
}
@@ -50,14 +52,14 @@
if (game_mode&GAME_MENU) {
//Assure we have a (correct) menu background
if (!menubg) {
- if (game_mode&GAME_PLAY) {
+ if (game_mode&(GAME_PLAY|GAME_EDIT)) {
setGameMenuBG();
} else {
setMenuBG();
}
}
if (updatetype==UPDATE_ALL) {
- if (game_mode&GAME_PLAY) {
+ if (game_mode&(GAME_PLAY|GAME_EDIT)) {
setGameMenuBG();
} else {
setMenuBG();
@@ -68,11 +70,8 @@
}
//Paused game
} else if (game_mode&GAME_PAUSED) {
- if (updatetype==UPDATE_ALL) {
- drawScene();
+ if (updatetype==UPDATE_ALL || updatetype==UPDATE_BAR) {
drawPlayerBar();
- } else if (updatetype==UPDATE_BAR) {
- drawPlayerBar();
}
//Not paused running game
} else if (game_mode&GAME_PLAY) {
@@ -80,6 +79,11 @@
drawPlayerBar();
drawFPS();
updatetype=UPDATE_ALL;
+ } else if (game_mode&GAME_EDIT) {
+ if (show_fps) toggleFPS();
+ if (show_bar) togglePlayerBar();
+ drawEditScene();
+ updatetype=UPDATE_ALL;
} else return;
//This is the most time consuming operation
if (updatetype!=UPDATE_NOTHING) SDL_Flip(screen);
@@ -141,10 +145,8 @@
}
void GraphicsEngine::drawScene() {
- if (!(game_mode&GAME_PLAY)) return;
-
//We don't want to change pos!
- SDL_Rect tmprect,shift,srcpos;
+ SDL_Rect tmprect,srcpos;
if (scenario->player!=NULL) {
shift=setShift(scenario->player->getCenter());
} else {
@@ -174,6 +176,26 @@
}
}
+void GraphicsEngine::drawEditScene() {
+ //We don't want to change pos!
+ SDL_Rect tmprect,srcpos;
+
+ SDL_FillRect(screen,NULL,0);
+ tmprect=*scenario->area;
+ srcpos=scenario->background->getFrame().pos;
+ shiftMapArea(tmprect,*scenario->background->getCurPos());
+ SDL_BlitSurface(scenario->background->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
+
+ object_iterator obit=scenario->pool->objectspool.begin();
+ while (obit!=scenario->pool->objectspool.end()) {
+ tmprect=*((*obit)->getPos());
+ srcpos=(*obit)->getFrame().pos;
+ shiftMapArea(tmprect,*((*obit)->getCurPos()));
+ SDL_BlitSurface((*obit)->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
+ ++obit;
+ }
+}
+
//TODO don't draw the whole screen, just till bar, just upgrade certain regions of the bar
void GraphicsEngine::drawPlayerBar() {
if (!show_bar) return;
@@ -334,8 +356,10 @@
//this could probably be done much easier ;)
inline void GraphicsEngine::setGameMenuBG() {
if (menubg) SDL_FreeSurface(menubg);
- drawScene();
- drawPlayerBar();
+ if (game_mode&GAME_PLAY) {
+ drawScene();
+ drawPlayerBar();
+ } else if (game_mode&GAME_EDIT) drawEditScene();
SDL_Flip(screen);
SDL_Surface* tmp = SDL_CreateRGBSurface (
@@ -386,3 +410,15 @@
menubg=NULL;
}
}
+
+const SDL_Rect& GraphicsEngine::addShift(Sint16 shiftx, Sint16 shifty) {
+ shift.x+=shiftx;
+ shift.y+=shifty;
+ return shift;
+}
+
+const SDL_Rect& GraphicsEngine::setShift(Sint16 shiftx, Sint16 shifty) {
+ shift.x=shiftx;
+ shift.y=shifty;
+ return shift;
+}
Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/gfxeng.h 2005-06-18 22:47:14 UTC (rev 120)
@@ -30,6 +30,8 @@
void toggleFPS();
void toggleFullScreen();
void setMenuBG(SDL_Surface* menu_background=NULL);
+ const SDL_Rect& addShift(Sint16,Sint16);
+ const SDL_Rect& setShift(Sint16,Sint16);
protected:
const Uint32 rmask;
const Uint32 gmask;
@@ -53,10 +55,15 @@
Uint8 updatetype;
//video flags
Uint32 vflags;
+ // current shift
+ SDL_Rect shift;
protected:
/// Draw the background and all objects in the pool. This is a very time
/// consuming function...
inline void drawScene();
+ /// Draw the background and all objects in the pool in map editor mode.
+ /// This is a very time consuming function...
+ inline void drawEditScene();
/// Draw player bar
inline void drawPlayerBar();
/// Draw the frames per second
Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/input.cpp 2005-06-18 22:47:14 UTC (rev 120)
@@ -34,6 +34,8 @@
pollPausedEvents();
} else if (game_mode&GAME_PLAY) {
pollGameEvents();
+ } else if (game_mode&GAME_EDIT) {
+ pollEditEvents();
} else {
}
}
@@ -174,3 +176,49 @@
}
keystate = SDL_GetKeyState(NULL);
}
+
+inline void InputHandler::pollEditEvents() {
+ for (Uint16 i=0; i<SDLK_LAST; i++) {
+ keypressed[i]=false;
+ }
+ while(SDL_PollEvent(&event)) {
+ switch(event.type) {
+ // special events
+ case SDL_VIDEORESIZE: {
+ gfxeng->resize(event.resize.w, event.resize.h);
+ break;
+ }
+ // keyboard events
+ case SDL_QUIT: {
+ quitGame(0);
+ }
+ case SDL_KEYDOWN: {
+ SDLKey key=event.key.keysym.sym;
+ keypressed[key]=true;
+ if (key==config.keybind[KEY_FULL]) {
+ gfxeng->toggleFullScreen();
+ } else if (key==config.keybind[KEY_MENU]) {
+ sfxeng->pauseMusic();
+ setMenu(new EditMenu());
+ gfxeng->update(UPDATE_ALL);
+ } else if (key==config.keybind[KEY_QUIT]) {
+ quitGame(0);
+ }
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ }
+ keystate = SDL_GetKeyState(NULL);
+ if (keyState(KEY_LEFT)) {
+ gfxeng->addShift(-1,0);
+ } else if (keyState(KEY_RIGHT)) {
+ gfxeng->addShift(1,0);
+ } else if (keyState(KEY_UP)) {
+ gfxeng->addShift(0,-1);
+ } else if (keyState(KEY_DOWN)) {
+ gfxeng->addShift(0,1);
+ }
+}
Modified: trunk/src/input.h
===================================================================
--- trunk/src/input.h 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/input.h 2005-06-18 22:47:14 UTC (rev 120)
@@ -28,6 +28,8 @@
inline void pollPausedEvents();
/// Check for keyboard events in menu
inline void pollMenuEvents();
+ /// Check for keyboard events in editing mode
+ inline void pollEditEvents();
};
#endif
Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/lost_penguins.cpp 2005-06-18 22:47:14 UTC (rev 120)
@@ -55,7 +55,7 @@
while (true) {
input->update();
- if (game_mode&GAME_PLAY) scenario->physic->update();
+ scenario->physic->update();
gfxeng->draw();
}
@@ -135,8 +135,9 @@
config.height=atoi(arg1.c_str());
} else if (option=="bpp") {
config.bpp=atoi(arg1.c_str());
- } else if (option=="full" && arg1=="1") {
- config.full=true;
+ } else if (option=="full") {
+ if (arg1=="1") config.full=true;
+ else config.full=false;
} else if (option=="map") {
config.map=arg1;
//TODO: add keybindings
Modified: trunk/src/menu.cpp
===================================================================
--- trunk/src/menu.cpp 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/menu.cpp 2005-06-18 22:47:14 UTC (rev 120)
@@ -56,7 +56,7 @@
StartMenu::StartMenu(): Menu() {
title="-== MAIN MENU ==-";
- entries.resize(4);
+ entries.resize(5);
update();
}
void StartMenu::act() {
@@ -72,14 +72,25 @@
break;
}
case 1: {
+ //Add a proper Map creation menu, etc..., FIXME
+ if ((config.map!="") && (scenario->loadMap(config.map)==0)) {
+ closeMenu();
+ game_mode|=GAME_EDIT;
+ cout << "Starting game...\n" << endl;
+ } else {
+ cout << "Select a valid map first...\n" << endl;
+ }
+ break;
+ }
+ case 2: {
setMenu(new MapMenu());
break;
}
- case 2: {
+ case 3: {
setMenu(new ConfigMenu());
break;
}
- case 3: {
+ case 4: {
quitGame(0);
break;
}
@@ -90,9 +101,10 @@
}
void StartMenu::update() {
entries[0]="Start Game";
- entries[1]="Map selection";
- entries[2]="Configuration";
- entries[3]="Quit";
+ entries[1]="Edit Map";
+ entries[2]="Map selection";
+ entries[3]="Configuration";
+ entries[4]="Quit";
}
@@ -130,6 +142,40 @@
}
+EditMenu::EditMenu(): Menu() {
+ title="-== EDIT MENU ==-";
+ entries.resize(3);
+ update();
+}
+void EditMenu::act() {
+ switch (currententry) {
+ case 0: {
+ if (!closeMenu()) {
+ gfxeng->update(UPDATE_ALL);
+ sfxeng->resumeMusic();
+ }
+ break;
+ }
+ case 1: {
+ setMenu(new ConfigMenu());
+ break;
+ }
+ case 2: {
+ quitGame(0);
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+}
+void EditMenu::update() {
+ entries[0]="Resume";
+ entries[1]="Configuration";
+ entries[2]="Quit";
+}
+
+
MapMenu::MapMenu(): Menu() {
title="-== MAP SELECTION ==-";
//TODO: add common entries, check directory for map files, entries.push_back(name);
Modified: trunk/src/menu.h
===================================================================
--- trunk/src/menu.h 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/menu.h 2005-06-18 22:47:14 UTC (rev 120)
@@ -60,6 +60,15 @@
void update();
};
+class EditMenu : public Menu {
+ public:
+ EditMenu();
+ virtual void act();
+ private:
+ /// Helper function
+ void update();
+};
+
class MapMenu : public Menu {
public:
MapMenu();
Modified: trunk/src/objects/olaf.cpp
===================================================================
--- trunk/src/objects/olaf.cpp 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/objects/olaf.cpp 2005-06-18 22:47:14 UTC (rev 120)
@@ -161,7 +161,6 @@
else if (!(state&STATE_FALL)) {
setState(STATE_ACT_2);
}
-
//Can't fart anymore
if (state&STATE_ACT_1) {
//Fart
Modified: trunk/src/physics.cpp
===================================================================
--- trunk/src/physics.cpp 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/physics.cpp 2005-06-18 22:47:14 UTC (rev 120)
@@ -38,6 +38,15 @@
reset_time=false;
tcurrent=SDL_GetTicks();
updateGame();
+ } else if (game_mode&GAME_EDIT) {
+ if (reset_time) {
+ dt=0;
+ } else {
+ dt=(SDL_GetTicks()-tcurrent);
+ }
+ reset_time=false;
+ tcurrent=SDL_GetTicks();
+ updateEdit();
} else {
}
}
@@ -108,6 +117,38 @@
}
}
+inline void PhysicHandler::updateEdit() {
+ object_iterator obit=scenario->pool->objectspool.begin();
+ while (obit!=scenario->pool->objectspool.end()) {
+ //remove marked objects
+ if ((*obit)->isDeleted()) {
+ obit=scenario->pool->removeObject(*obit);
+ } else ++obit;
+ }
+ obit=scenario->pool->objectspool.begin();
+ while (obit!=scenario->pool->objectspool.end()) {
+ (*obit)->idle(dt);
+ (*obit)->updateEvents(dt);
+ ++obit;
+ }
+ //run end scenario->player effects
+ character_iterator cit=scenario->pool->characterspool.begin();
+ while (cit!=scenario->pool->characterspool.end()) {
+ (*cit)->fall(dt);
+ (*cit)->updateAnimState(!((*cit)->getState(ESTATE_ANIM)));
+ ++cit;
+ }
+ //update the animations of all objects
+ obit=scenario->pool->objectspool.begin();
+ while (obit!=scenario->pool->objectspool.end()) {
+ if ((*obit)->getState(ESTATE_ANIM)) {
+ bool runs=(*obit)->updateAnim(dt);
+ if (!runs) (*obit)->stopEvent();
+ } else if ((*obit)->isRunning()) (*obit)->updateAnim(dt);
+ ++obit;
+ }
+}
+
inline void PhysicHandler::updatePaused() {
if (input->keyPressed(KEY_RIGHT)) {
scenario->player->switchItem(true);
Modified: trunk/src/physics.h
===================================================================
--- trunk/src/physics.h 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/physics.h 2005-06-18 22:47:14 UTC (rev 120)
@@ -22,6 +22,7 @@
Uint16 Dfps,Dframes,currentfps,minfps;
private:
inline void updateGame();
+ inline void updateEdit();
inline void updatePaused();
inline void updateFPS();
};
Modified: trunk/src/sfxeng.cpp
===================================================================
--- trunk/src/sfxeng.cpp 2005-06-18 15:49:04 UTC (rev 119)
+++ trunk/src/sfxeng.cpp 2005-06-18 22:47:14 UTC (rev 120)
@@ -5,7 +5,7 @@
SoundsEngine::SoundsEngine() {
#ifdef SDL_MIXER
/* Open the audio device */
- if (Mix_OpenAudio(config.audio_rate, config.audio_format, config.audio_channels, 512) < 0) {
+ if (Mix_OpenAudio(config.audio_rate, config.audio_format, config.audio_channels, 256) < 0) {
cout << "Couldn't open audio: " << SDL_GetError() << endl;
cout << "Audio disabled!\n";
disabled=true;
@@ -32,7 +32,7 @@
if (theme) Mix_FreeMusic(theme);
theme = Mix_LoadMUS(name.c_str());
Mix_FadeInMusic(theme, -1, 5000);
- Mix_VolumeMusic(MIX_MAX_VOLUME/4);
+ Mix_VolumeMusic(MIX_MAX_VOLUME/2);
}
#endif
}
More information about the lostpenguins-commits
mailing list