Skip to content
Browse files

Transitions and more.

Added SDL_Surface debug print function.
Removed unneeded gl calls.
Lists: Fixed memory-leak in removeItem. Added fast-append and fast remove functions.
Makefile.linux updated so settings is saved in ./ unless DATADIR is
specified.
Removed useless calls.
Fixed compile warning in lits.c
Added transitions between menu/game screens.
Minor optimization of particle-system removal.
  • Loading branch information...
1 parent c1101db commit e42e0786485e2683632064977dd4ace12b0a7850 @DusteDdk committed
Showing with 370 additions and 27 deletions.
  1. +4 −1 Makefile.linux
  2. +0 −1 credits.c
  3. +9 −0 game.c
  4. +2 −0 leveleditor.c
  5. +24 −1 list.c
  6. +11 −2 list.h
  7. +8 −3 main.c
  8. +54 −16 menu.c
  9. +4 −1 particle.c
  10. +66 −0 pixel.c
  11. +3 −0 pixel.h
  12. +1 −2 platform/pc.c
  13. +144 −0 transition.c
  14. +36 −0 transition.h
  15. +4 −0 wizznic.cbp
View
5 Makefile.linux
@@ -17,7 +17,9 @@ DEFS = -DDATADIR="\"$(DATADIR)\""
#Add the PER_USER_FILES define if the DATADIR is set
ifneq ($(DATADIR),)
+ ifneq ($(DATADIR),"./")
DEFS +=-DPER_USER_FILES
+ endif
endif
ifneq ($(BUILD_NUMBER),)
@@ -38,7 +40,8 @@ endif
OBJS = dumplevelimages.o board.o cursor.o draw.o input.o main.o menu.o sprite.o\
text.o ticks.o sound.o game.o player.o list.o levels.o pixel.o stars.o\
levelselector.o leveleditor.o particle.o pack.o settings.o stats.o strings.o\
-mbrowse.o teleport.o credits.o waveimg.o userfiles.o swscale.o platform/pc.o pointer.o
+mbrowse.o teleport.o credits.o waveimg.o userfiles.o swscale.o platform/pc.o\
+pointer.o transition.o
MYCC = $(CC) $(CFLAGS) $(INCS) $(DEFS)
View
1 credits.c
@@ -154,7 +154,6 @@ void clearCredits()
freeMsg(cm);
}
freeList(msgList);
- clearParticles();
}
View
9 game.c
@@ -19,6 +19,7 @@
#include "strings.h"
#include "settings.h"
#include "defs.h"
+#include "transition.h"
static playField pf;
static cursorType cur;
@@ -165,6 +166,9 @@ int runGame(SDL_Surface* screen)
//Pause ?
if( getButton( C_BTNMENU ) || isPointerEscapeClicked() )
{
+
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN,500);
+
restartConfirm=0;
resetBtn( C_BTNMENU );
if(player()->inEditor)
@@ -240,6 +244,7 @@ int runGame(SDL_Surface* screen)
timeBeforeRestart=pf.levelInfo->time;
spentTimeBeforeRestart=player()->hsEntry.time;
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_DISSOLVE, 2500);
initGame(screen);
if(!player()->inEditor)
{
@@ -424,6 +429,7 @@ int runGame(SDL_Surface* screen)
}
}
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700);
return(STATEMENU);
}
} else if(ret > 0) //Player destroyed bricks.
@@ -554,6 +560,7 @@ int runGame(SDL_Surface* screen)
player()->hsEntry.score=0;
//Goto cleanup, then menu
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700);
return(STATEMENU);
}
}
@@ -597,6 +604,7 @@ int runGame(SDL_Surface* screen)
player()->hsEntry.score=0;
//Goto cleanup, then menu
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700);
return(STATEMENU);
}
}
@@ -652,6 +660,7 @@ int runGame(SDL_Surface* screen)
resetBtn(C_BTNB);
resetMouseBtn();
cleanUpGame();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 700);
return(STATEMENU);
}
View
2 leveleditor.c
@@ -30,6 +30,7 @@
#include "strings.h"
#include "teleport.h"
+#include "transition.h"
#include "defs.h"
#define EDITOR_MAIN 0
@@ -150,6 +151,7 @@ int runEditor(SDL_Surface* screen)
{
resetMouseBtn();
editorCleanUp();
+ startTransition(screen, TRANSITION_TYPE_ROLL_IN, 500 );
return(STATEMENU);
}
}
View
25 list.c
@@ -17,6 +17,7 @@
#include "list.h"
#include <stdlib.h>
+#include <stdio.h>
void listAddData(listItem* start, void* data)
{
@@ -38,7 +39,21 @@ void listAddData(listItem* start, void* data)
}
-//Inserts into the list at pos p. 0 = first
+listItem* listAppendData(listItem* item, void* data)
+{
+ listItem *tt;
+ if(item->next)
+ {
+ printf("listAppendData ERROR: item %p is not the last item in the list.\n", item);
+ return( (listItem*)0 );
+ }
+ tt=malloc(sizeof(listItem));
+ tt->data=data;
+ tt->next=0;
+ item->next=tt;
+ return(tt);
+}
+
void listInsertData(listItem* start, void* data, int p)
{
int pos=0;
@@ -74,6 +89,7 @@ listItem* listRemoveItem(listItem* start, listItem* item)
if(l->next)
{
prev->next=l->next;
+ free(item);
} else {
prev->next=0;
}
@@ -84,6 +100,13 @@ listItem* listRemoveItem(listItem* start, listItem* item)
return(0);
}
+listItem* cutItem(listItem* previous, listItem* removeMe )
+{
+ previous->next=removeMe->next;
+ free(removeMe);
+ return(previous->next);
+}
+
listItem* initList()
{
listItem* ptr = malloc(sizeof(listItem));
View
13 list.h
@@ -26,10 +26,19 @@ struct listItemStruct
typedef struct listItemStruct listItem;
+//Add data to the end of a list
void listAddData(listItem* start, void* data);
-void listInsertData(listItem* start, void* data, int p); //Inserts into the list at pos p. 0 = first
-listItem* listRemoveItem(listItem* start, listItem* item); //Removes item from list, returns item just before removed item.
+//Fast, appends a new item containing data to a listitem.
+listItem* listAppendData(listItem* item, void* data);
+
+
+//Inserts into the list at pos p. 0 = first
+void listInsertData(listItem* start, void* data, int p);
+
+listItem* listRemoveItem(listItem* start, listItem* item); //Removes item from list, returns item just before removed item. (or 0)
+listItem* cutItem(listItem* previous, listItem* removeMe ); //Given previous item, removes item, returns next item (or 0)
+
listItem* initList();
void freeList(listItem* start);
int listSize(listItem* start);
View
11 main.c
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
@@ -42,6 +43,7 @@
#include "strings.h"
#include "swscale.h"
#include "pointer.h"
+#include "transition.h"
#ifdef PC
#include "dumplevelimages.h"
@@ -225,6 +227,8 @@ int main(int argc, char *argv[])
//Init particles
initParticles(screen);
+ srand( (int)time(NULL) );
+
#if defined(PC)
//Need to dump level-screenshots?
if(doDump)
@@ -265,6 +269,8 @@ int main(int argc, char *argv[])
//Initialize credits
initCredits(screen);
+ initTransition();
+
int lastTick;
while(state!=STATEQUIT)
{
@@ -272,7 +278,6 @@ int main(int argc, char *argv[])
frameStart();
if(runControls()) state=STATEQUIT;
-
switch(state)
{
case STATEPLAY:
@@ -292,6 +297,8 @@ int main(int argc, char *argv[])
soundRun(screen,state);
+ runTransition(screen);
+
if(setting()->showFps)
drawFPS(screen);
@@ -327,14 +334,12 @@ int main(int argc, char *argv[])
#endif
}
-
#if defined(PLATFORM_NEEDS_EXIT)
platformExit();
#endif
SDL_Quit();
- //Not even trying to clean up, OS should do that anyway..
return(0);
}
View
70 menu.c
@@ -39,6 +39,8 @@
#include "waveimg.h"
#include "stats.h"
+#include "transition.h"
+
static float rot=0;
#define MENUGFXINTRO 0
@@ -279,9 +281,11 @@ int runMenu(SDL_Surface* screen)
SDL_FreeSurface( waving.overlay );
SDL_FreeSurface( waving.mask ) ;
+ startTransition( screen, TRANSITION_TYPE_DISSOLVE, 450 );
+
menuBg[MENUGFXINTRO]=0;
menuPosY=0;
- clearParticles();
+ //clearParticles();
clearCredits();
#if defined (PLATFORM_SUPPORTS_STATSUPLOAD)
if(setting()->firstRun)
@@ -335,15 +339,6 @@ int runMenu(SDL_Surface* screen)
menuPosX = getNumLevels();
}
- if(getButton(C_BTNMENU) || isPointerEscapeClicked() )
- {
- resetBtn(C_BTNMENU);
- menuPosY=0;
- setMenu(menuStatePaused);
- break;
- }
-
-
if(menuPosX-1 < stats()->progress && menuPosX!=getNumLevels())
{
txtWrite(screen, FONTMEDIUM, ">>", HSCREENW+120,HSCREENH-12);
@@ -361,6 +356,7 @@ int runMenu(SDL_Surface* screen)
decPosX();
}
}
+
//The "Finished" image..
if(menuPosX == menuMaxX)
{
@@ -383,6 +379,16 @@ int runMenu(SDL_Surface* screen)
}
}
+ if(getButton(C_BTNMENU) || isPointerEscapeClicked() )
+ {
+ resetBtn(C_BTNMENU);
+ menuPosY=0;
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500 );
+
+ setMenu(menuStatePaused);
+ break;
+ }
+
break; // New game
case menuStateNextLevel:
@@ -407,6 +413,7 @@ int runMenu(SDL_Surface* screen)
if(getButton(C_BTNB) || isPointerClicked() )
{
resetBtn(C_BTNB);
+ resetMouseBtn();
if(initGame(screen))
{
@@ -414,6 +421,7 @@ int runMenu(SDL_Surface* screen)
{
setMenu(menuStateHowto);
} else {
+ startTransition(screen, TRANSITION_TYPE_ROLL_OUT,500);
return(STATEPLAY);
}
} else {
@@ -597,6 +605,7 @@ int runMenu(SDL_Surface* screen)
stats()->progress=-1;
}
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500 );
setMenu(menuStateNewGame);
//Clean up.
@@ -616,26 +625,35 @@ int runMenu(SDL_Surface* screen)
break;
case 1: //Resume, unset paused, return to game
if(player()->gameStarted)
+ {
+ startTransition(screen, TRANSITION_TYPE_ROLL_OUT,500);
return(STATEPLAY);
+ }
break;
case 2: //Highscores
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500 );
setMenu(menuStateHighScores);
break;
case 3: //Options
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500 );
setMenu(menuStateOptions);
break;
case 4: //UserLevels
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500 );
setMenu(menuStateUserLevels);
if(player()->gameStarted) cleanUpGame();
return(STATEMENU);
break;
case 5: //Switch to about screen
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500 );
menuState=menuStateAbout;
break;
case 6: //Switch to help screen
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500 );
setMenu(menuStateHowto);
break;
case 7: //Exit program
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500 );
if( statsIsHighScore() )
{
setMenu(menuStateEnterHighScore);
@@ -645,6 +663,7 @@ int runMenu(SDL_Surface* screen)
}
break;
case 8: //Pack selection
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500 );
setMenu(menuStatePackList);
menuPosY = packState()->selected;
break;
@@ -690,11 +709,13 @@ int runMenu(SDL_Surface* screen)
if( getButton( C_BTNB ) || isPointerClicked() )
{
resetBtn( C_BTNB );
- clearParticles();
+
if(player()->gameStarted) //Return to game if allready started
{
+ startTransition(screen, TRANSITION_TYPE_ROLL_OUT,800);
return(STATEPLAY);
} else {
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500 );
setMenu(menuStatePaused);
}
@@ -738,6 +759,7 @@ int runMenu(SDL_Surface* screen)
{
resetMouseBtn();
resetBtn( C_BTNB );
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500 );
menuState=menuStatePaused;
}
@@ -764,6 +786,7 @@ int runMenu(SDL_Surface* screen)
resetMouseBtn();
resetBtn( C_BTNB );
setMenu(menuStatePaused);
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500 );
if( statsIsHighScore() )
{
@@ -820,6 +843,7 @@ int runMenu(SDL_Surface* screen)
setMenu(menuStatePackList);
//Set to first pack in lst when we get there
menuPosY=0;
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500 );
}
@@ -844,6 +868,7 @@ int runMenu(SDL_Surface* screen)
if( getButton(C_BTNMENU) || isPointerEscapeClicked() )
{
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500);
setMenu(menuStatePaused);
}
@@ -967,14 +992,17 @@ int runMenu(SDL_Surface* screen)
sprintf(buf, "%s/level%03i.wzp", getUserLevelDir(), getNumUserLevels());
editorFileName(buf);
+ startTransition(screen, TRANSITION_TYPE_ROLL_OUT, 500 );
return(STATEEDIT);
} else if(menuPosY==1) //Exit from editor
{
player()->inEditor=0;
menuState=menuStatePaused;
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500 );
menuPosY=0;
} else if( ul==-2 || ul>0 )
{
+ startTransition(screen, TRANSITION_TYPE_ROLL_OUT, 500 );
editorLoad(userLevelFile(menuPosY-2),screen);
return(STATEEDIT);
}
@@ -996,6 +1024,8 @@ int runMenu(SDL_Surface* screen)
editorFileName(buf);
//Start editing state
+ startTransition(screen, TRANSITION_TYPE_ROLL_OUT, 500 );
+
return(STATEEDIT);
}
}
@@ -1014,6 +1044,7 @@ int runMenu(SDL_Surface* screen)
if(initGame(screen))
{
+ startTransition(screen, TRANSITION_TYPE_ROLL_OUT, 500 );
return(STATEPLAY);
} else {
printf("Editor couldn't init game for the editor.\n");
@@ -1026,6 +1057,7 @@ int runMenu(SDL_Surface* screen)
if(isPointerEscapeClicked())
{
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500 );
menuState=menuStatePaused;
resetMouseBtn();
}
@@ -1109,6 +1141,7 @@ int runMenu(SDL_Surface* screen)
saveSettings(); //Save
//--
}
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500 );
//Return to main menu
setMenu(menuStatePaused);
}
@@ -1131,6 +1164,8 @@ int runMenu(SDL_Surface* screen)
resetMouseBtn();
saveSettings();
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500 );
+
setMenu(menuStatePaused);
}
@@ -1373,7 +1408,7 @@ int runMenu(SDL_Surface* screen)
if( getButton( C_BTNB ) || isPointerClicked() )
{
resetBtn( C_BTNB );
-
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500);
setMenu(menuStatePaused);
}
@@ -1473,6 +1508,7 @@ int runMenu(SDL_Surface* screen)
strcpy(player()->campStats.name, setting()->playerName);
statsSaveHighScore();
// printf("AddingHighscore: %i\n", player()->campStats.score);
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_DOWN, 500);
menuState=menuReturnHack;
menuPosY=0;
} else if( getButton( C_BTNB ) || (hsKeyboardWasClicked && menuPosY < 5) )
@@ -1613,19 +1649,21 @@ int runMenu(SDL_Surface* screen)
//Enabled
if( menuPosX == 0 )
{
- setting()->firstRun=0;
setting()->uploadStats=1;
- saveSettings();
statsUpload(0,0,0,0,0,"check",1, &(setting()->session));
- setMenu( menuStatePaused );
}
//Disabled
if( menuPosX == 2 )
{
- setting()->firstRun=0;
setting()->uploadStats=0;
+ }
+
+ if( menuPosX == 0 || menuPosX == 2 )
+ {
+ setting()->firstRun=0;
saveSettings();
+ startTransition(screen, TRANSITION_TYPE_CURTAIN_UP, 500);
setMenu( menuStatePaused );
}
}
View
5 particle.c
@@ -162,6 +162,7 @@ void runParticlesLayer(SDL_Surface* screen, int layer)
{
if(!setting()->particles) return;
listItem* it = pSystems;
+ listItem* prev = pSystems; //For quick removal
pSystem_t* p; //psystem
int i;
@@ -190,9 +191,11 @@ void runParticlesLayer(SDL_Surface* screen, int layer)
//Remove system
clearSystem(p);
//Remove from list. (removeItem returns the item just before current, if any)
- it=listRemoveItem(pSystems, it);
+ cutItem(prev, it);
+ it=prev;
}
} //System is on correct layer
+ prev=it;
}
}
View
66 pixel.c
@@ -102,3 +102,69 @@ inline uint32_t freadPixel(SDL_Surface* img, int x, int y)
return( *(uint32_t*)( (char*)(img->pixels)+img->pitch*y+img->format->BytesPerPixel*x ) );
}
+void debugPrintSurfaceInfo(SDL_Surface* s)
+{
+ printf( "Info for surface %p\n"
+ " flags: 0x%X (%s) \n"
+ " Pixelformat %p: \n"
+ " BitsPP: %i\n"
+ " BytesPP: %i\n"
+ " RMask: 0x%X\n"
+ " GMask: 0x%X\n"
+ " BMask: 0x%X\n"
+ " Colorkey: 0x%X\n"
+ " Alpha: 0x%X\n"
+ " w: %i\n"
+ " h: %i\n"
+ " Pitch: %i\n"
+ " Pixels: %p\n"
+ " ClipRect:\n"
+ " x: %i\n"
+ " y: %i\n"
+ " w: %i\n"
+ " h: %i\n"
+ " Refcount %i\n"
+ "\n", s,
+ s->flags, debugGetFlagInfo(s->flags),
+ s->format,
+ s->format->BitsPerPixel,
+ s->format->BytesPerPixel,
+ s->format->Rmask,
+ s->format->Gmask,
+ s->format->Bmask,
+ s->format->colorkey,
+ s->format->alpha,
+ s->w,
+ s->h,
+ s->pitch,
+ s->pixels,
+ s->clip_rect.x,
+ s->clip_rect.y,
+ s->clip_rect.w,
+ s->clip_rect.h,
+ s->refcount );
+}
+
+char* debugGetFlagInfo( Uint32 flags )
+{
+ char flagsStr[4096];
+ flagsStr[0]='\0';
+
+ if(flags & SDL_ANYFORMAT) sprintf(flagsStr, "%s", "SDL_ANYFORMAT,");
+ if(flags & SDL_ASYNCBLIT) sprintf(flagsStr, "%s%s", flagsStr,"SDL_ASYNCBLIT,");
+ if(flags & SDL_DOUBLEBUF) sprintf(flagsStr, "%s%s", flagsStr,"SDL_DOUBLEBUF,");
+ if(flags & SDL_HWACCEL) sprintf(flagsStr, "%s%s", flagsStr,"SDL_HWACCEL,");
+ if(flags & SDL_HWPALETTE) sprintf(flagsStr, "%s%s", flagsStr,"SDL_HWPALETTE,");
+ if(flags & SDL_HWSURFACE) sprintf(flagsStr, "%s%s", flagsStr,"SDL_HWSURFACE,");
+ if(flags & SDL_FULLSCREEN) sprintf(flagsStr, "%s%s", flagsStr,"SDL_FULLSCREEN,");
+ if(flags & SDL_OPENGL) sprintf(flagsStr, "%s%s", flagsStr,"SDL_OPENGL,");
+ if(flags & SDL_OPENGLBLIT) sprintf(flagsStr, "%s%s", flagsStr,"SDL_OPENGLBLIT,");
+ if(flags & SDL_RESIZABLE) sprintf(flagsStr, "%s%s", flagsStr,"SDL_RESIZABLE,");
+ if(flags & SDL_RLEACCEL) sprintf(flagsStr, "%s%s", flagsStr,"SDL_RLEACCEL,");
+ if(flags & SDL_SRCALPHA) sprintf(flagsStr, "%s%s", flagsStr,"SDL_SRCALPHA,");
+ if(flags & SDL_SRCCOLORKEY) sprintf(flagsStr, "%s%s", flagsStr,"SDL_SRCCOLORKEY,");
+ if(flags & SDL_SWSURFACE) sprintf(flagsStr, "%s%s", flagsStr,"SDL_SWSURFACE,");
+ if(flags & SDL_PREALLOC) sprintf(flagsStr, "%s%s", flagsStr,"SDL_PREALLOC,");
+
+ return( (char*)&flagsStr );
+}
View
3 pixel.h
@@ -27,4 +27,7 @@ inline uint32_t freadPixel(SDL_Surface* img, int x, int y);
void setAlphaCol( int bpp );
inline int_fast8_t isAlpha(int_fast8_t r, int_fast8_t g, int_fast8_t b);
+void debugPrintSurfaceInfo( SDL_Surface* s);
+char* debugGetFlagInfo( Uint32 flags );
+
#endif // PIXEL_H_INCLUDED
View
3 platform/pc.c
@@ -63,9 +63,8 @@ SDL_Surface* platformInitAccel( int sdlVideoModeFlags )
glDisable(GL_DEPTH_TEST);
glDisable( GL_CULL_FACE );
glDisable(GL_LIGHTING);
+ glDisable(GL_BLEND);
- glEnable(GL_BLEND);
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,1,1,1);
View
144 transition.c
@@ -0,0 +1,144 @@
+#include "transition.h"
+#include "pixel.h"
+#include "ticks.h"
+#include "list.h"
+#include "particles.h"
+
+struct transition_s {
+ SDL_Surface* sur;
+ int type;
+ int time;
+ int timeLeft;
+ int reverse;
+};
+
+typedef struct transition_s transition_t;
+
+transition_t t;
+
+void initTransition()
+{
+ printf("initTransition called\n");
+ t.sur=NULL;
+ t.timeLeft=0;
+ t.time=0;
+ t.sur=NULL;
+}
+
+#define _TRANSITION_TYPE_ROLL 253
+
+void startTransition(SDL_Surface* scr, uint_fast8_t type, uint_fast16_t time)
+{
+ struct psysSet_s psys;
+
+ t.type=(type==TRANSITION_TYPE_RANDOM)?rand()%NUM_TRANSITIONS:type;
+ t.time=time;
+ t.timeLeft=time;
+ t.reverse=0;
+
+ if( t.sur != NULL )
+ {
+ SDL_FreeSurface(t.sur);
+ }
+
+
+ switch( t.type )
+ {
+ case TRANSITION_TYPE_DISSOLVE:
+ clearParticles();
+ psys.bounce=0;
+ psys.fade=0;
+ psys.gravity=0;
+ psys.layer=PSYS_LAYER_TOP;
+ psys.life=time;
+ psys.lifeVar=time;
+ psys.srcImg=scr;
+ psys.x=0; ///TODO: Needs to be positioned for non-4:3 screens
+ psys.y=0; ///TODO: Needs to be positioned for non-4:3 screens
+ psys.srcRect.x=0;
+ psys.srcRect.y=0;
+ psys.srcRect.h=scr->h;
+ psys.srcRect.w=scr->w;
+ psys.vel=0;
+ spawnParticleSystem(&psys);
+ break;
+ case TRANSITION_TYPE_ROLL_IN:
+ case TRANSITION_TYPE_CURTAIN_DOWN:
+ t.reverse=1;
+ case TRANSITION_TYPE_ROLL_OUT:
+ case TRANSITION_TYPE_CURTAIN_UP:
+ t.sur = SDL_ConvertSurface( scr, scr->format, scr->flags );
+ //Some surfaces has flags set that prevent propper blitting
+ t.sur->flags=0x00;
+ break;
+ }
+}
+
+void runTransition(SDL_Surface* scr)
+{
+ int x;
+ if( t.timeLeft == 0 )
+ return;
+
+ t.timeLeft -= getTicks();
+ if( t.timeLeft < 1 )
+ t.timeLeft=0;
+
+ SDL_Rect r,rr;
+ SDL_Surface* tmpSurf;
+
+ switch(t.type)
+ {
+ case TRANSITION_TYPE_CURTAIN_UP:
+ case TRANSITION_TYPE_CURTAIN_DOWN:
+ r.x=0;
+ r.w=scr->w;
+ rr.x=0;
+ x=((float)(t.timeLeft)/(float)(t.time))*(float)(scr->h);;
+
+ if( !t.reverse )
+ {
+ r.h=x;
+ r.y=0;
+ rr.y=0;
+ } else {
+ r.h=scr->h;
+ r.y=scr->h-x;
+ rr.y=scr->h-x;
+ }
+ SDL_BlitSurface(t.sur, &r, scr, &rr );
+ break;
+ case TRANSITION_TYPE_DISSOLVE:
+ runParticles(scr);
+ break;
+ case TRANSITION_TYPE_ROLL_IN:
+ case TRANSITION_TYPE_ROLL_OUT:
+ x=((float)(t.timeLeft)/(float)(t.time))*(float)(scr->w);
+
+ tmpSurf = SDL_ConvertSurface( scr, scr->format, scr->flags );
+ tmpSurf->flags=0x00;
+ r.y=0;
+ rr.y=0;
+
+ if( !t.reverse )
+ {
+ r.x=x-(scr->w);
+ rr.x=x;
+ } else {
+ r.x=(scr->w)-x;
+ rr.x=-x;
+ }
+
+ SDL_BlitSurface(t.sur, NULL, scr, &r );
+ SDL_BlitSurface(tmpSurf,NULL, scr, &rr );
+
+ SDL_FreeSurface(tmpSurf);
+ break;
+
+ }
+}
+
+inline int_fast8_t transitionActive()
+{
+ return(t.timeLeft<1?0:1);
+}
View
36 transition.h
@@ -0,0 +1,36 @@
+#ifndef TRANSITION_H_INCLUDED
+#define TRANSITION_H_INCLUDED
+
+/************************************************************************
+ * This file is part of Wizznic. *
+ * Copyright 2009-2012 Jimmy Christensen <dusted@dusted.dk> *
+ * Wizznic is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * Wizznic is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with Wizznic. If not, see <http://www.gnu.org/licenses/>. *
+ ************************************************************************/
+
+#include <SDL/SDL.h>
+
+#define TRANSITION_TYPE_DISSOLVE 0
+#define TRANSITION_TYPE_CURTAIN_UP 1
+#define TRANSITION_TYPE_CURTAIN_DOWN 2
+#define TRANSITION_TYPE_ROLL_OUT 3
+#define TRANSITION_TYPE_ROLL_IN 4
+#define NUM_TRANSITIONS 5
+
+#define TRANSITION_TYPE_RANDOM 255
+
+void initTransition();
+void startTransition(SDL_Surface* scr, uint_fast8_t type, uint_fast16_t time);
+void runTransition(SDL_Surface* scr);
+
+#endif
View
4 wizznic.cbp
@@ -204,6 +204,10 @@
<Option compilerVar="CC" />
</Unit>
<Unit filename="ticks.h" />
+ <Unit filename="transition.c">
+ <Option compilerVar="CC" />
+ </Unit>
+ <Unit filename="transition.h" />
<Unit filename="userfiles.c">
<Option compilerVar="CC" />
</Unit>

0 comments on commit e42e078

Please sign in to comment.
Something went wrong with that request. Please try again.