Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Editor works with mouse.

New fancy logo.
waveImg can have a scrolling overlay on top of images being waved.
  • Loading branch information...
commit dce9e43921f0486dd29a8165976aa92b508df086 1 parent bba53ed
@DusteDdk authored
View
6 credits.c
@@ -66,14 +66,15 @@ msg_t* initMsg(const char* strTitle, const char* strName,SDL_Surface* screen)
SDL_Surface* tempSurf;
+
+ SDL_SetColorKey( t->surfTitle, SDL_SRCCOLORKEY, SDL_MapRGB( t->surfTitle->format, 0, 0xFF, 0xFF ) );
tempSurf=SDL_DisplayFormat(t->surfTitle);
SDL_FreeSurface(t->surfTitle);
- SDL_SetColorKey( tempSurf, SDL_SRCCOLORKEY, SDL_MapRGB( tempSurf->format, 0, 0xFF, 0xFF ) );
t->surfTitle=tempSurf;
+ SDL_SetColorKey( t->nameWaving.img, SDL_SRCCOLORKEY, SDL_MapRGB( t->nameWaving.img->format, 0, 0xFF, 0xFF ) );
tempSurf=SDL_DisplayFormat(t->nameWaving.img);
SDL_FreeSurface(t->nameWaving.img);
- SDL_SetColorKey( tempSurf, SDL_SRCCOLORKEY, SDL_MapRGB( tempSurf->format, 0, 0xFF, 0xFF ) );
t->nameWaving.img=tempSurf;
return(t);
@@ -95,6 +96,7 @@ void setCurrent()
cm->nameWaving.amount=35;
cm->nameWaving.speed=50;
cm->nameWaving.privRotAmount=0;
+ cm->nameWaving.useOverlay=0;
//Setup particle system
ps.layer=PSYS_LAYER_TOP;
View
BIN  data/edit-save.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  data/menu/intro.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  data/menu/intromask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  data/menu/introoverlay.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
65 leveleditor.c
@@ -34,6 +34,7 @@
#define EDITOR_MAIN 0
#define EDITOR_BRICKS_SELECTION 1
+#define EDITOR_SAVEBTN_CLICKED 3 /*Has to be 3 */
static playField pf;
static cursorType cur;
@@ -45,7 +46,9 @@ static int teleState=0; //Teleport placement iteration
static int teleSrcPos[2];
static int editorState;
SDL_Surface* selBrickBG;
-spriteType* selBrickBgSprite;
+
+SDL_Surface* saveBtnBG;
+spriteType* saveBtnSprite;
void editorLoad(const char* fn, SDL_Surface* screen)
{
@@ -62,8 +65,12 @@ void editorLoad(const char* fn, SDL_Surface* screen)
initDraw(pf.levelInfo, screen);
SDL_FreeSurface(stealGfxPtr()->boardImg);
stealGfxPtr()->boardImg = loadImg( DATADIR"data/editbg.png" );
+
selBrickBG = loadImg( DATADIR"data/editselbrick.png" );
- selBrickBgSprite = cutSprite( selBrickBG, 0,0, selBrickBG->w, selBrickBG->h );
+
+ saveBtnBG = loadImg( DATADIR"data/edit-save.png" );
+ saveBtnSprite = cutSprite( saveBtnBG, 0,0, saveBtnBG->w, saveBtnBG->h );
+
changed=0;
selBrick=BRICKSBEGIN;
@@ -90,7 +97,9 @@ void editorCleanUp()
//Free graphics
SDL_FreeSurface(selBrickBG);
- free(selBrickBgSprite);
+
+ SDL_FreeSurface(saveBtnBG);
+ free(saveBtnSprite);
}
void editorFileName(const char* fn)
@@ -126,9 +135,25 @@ void editorRemoveBrickUnderCursor()
int runEditor(SDL_Surface* screen)
{
SDL_Rect selBrickRect;
+ getInpPointerState()->escEnable=1;
if( editorState == EDITOR_MAIN )
{
+
+ if(getButton(C_BTNMENU) || isPointerEscapeClicked() )
+ {
+ resetBtn( C_BTNMENU );
+ resetMouseBtn();
+
+ changed++; //If it was 0 then it will become 1 (saved) exit. If it was 1 it becomes 2 (not saved).
+ if( changed != 2 )
+ {
+ resetMouseBtn();
+ editorCleanUp();
+ return(STATEMENU);
+ }
+ }
+
//We detect if the "preview" brick on the left is clicked, we do this now so we can reset the click so that it does not hit the board
selBrickRect.x = HSCREENW-125;
selBrickRect.y = HSCREENH-85;
@@ -141,6 +166,17 @@ int runEditor(SDL_Surface* screen)
resetMouseBtn();
}
+ //We detect mouse-save input here so it won't hit the board.
+ selBrickRect.x = HSCREENW-145;
+ selBrickRect.y = HSCREENH+42;
+ selBrickRect.w = selBrickRect.x+59;
+ selBrickRect.h = selBrickRect.y+24;
+ if( isBoxClicked(&selBrickRect) && changed>0)
+ {
+ changed=EDITOR_SAVEBTN_CLICKED;
+ resetMouseBtn();
+ }
+
//Handle movement
if(getButton(C_UP))
{
@@ -232,6 +268,7 @@ int runEditor(SDL_Surface* screen)
pf.board[cur.x][cur.y]->pxx=cur.x*20+boardOffsetX;
pf.board[cur.x][cur.y]->pxy=cur.y*20+boardOffsetY;
} //Not a teleport
+
changed=1;
}
@@ -256,7 +293,7 @@ int runEditor(SDL_Surface* screen)
editorRemoveBrickUnderCursor();
}
- if(getButton(C_BTNSELECT))
+ if(getButton(C_BTNSELECT) || changed==EDITOR_SAVEBTN_CLICKED)
{
resetBtn(C_BTNSELECT);
FILE *f = fopen(fileName, "w");
@@ -334,18 +371,7 @@ int runEditor(SDL_Surface* screen)
}
- if(getButton(C_BTNMENU))
- {
- resetBtn( C_BTNMENU );
- changed++; //If it was 0 then it will become 1 (saved) exit. If it was 1 it becomes 2 (not saved).
- if( changed != 2 )
- {
- editorCleanUp();
- return(STATEMENU);
- }
- }
-
- } //Editor in main state, don't ignore imput
+ } //Editor in main state, don't ignore input
draw(&cur, &pf, screen);
@@ -388,11 +414,14 @@ int runEditor(SDL_Surface* screen)
}
drawAllTelePaths(screen, pf.levelInfo->teleList);
+ if( (getInpPointerState()->timeSinceMoved < POINTER_SHOW_TIMEOUT) && (changed > 0) )
+ {
+ drawSprite(screen, saveBtnSprite, HSCREENW-145, HSCREENH+42 );
+ }
+
//Draw brick-selection
if( editorState == EDITOR_BRICKS_SELECTION )
{
- //Draw box for the bricks "24 px"
-// drawSprite( screen, selBrickBgSprite, HSCREENW-78, HSCREENH-42 );
SDL_BlitSurface(selBrickBG , NULL, screen, &(setting()->bgPos) );
//Draw a 3*6 grid
View
189 menu.c
@@ -99,6 +99,11 @@ int initMenu(SDL_Surface* screen)
setWaving(&waving, screen, menuBg[MENUGFXINTRO], HSCREENW-149,HSCREENH-90,1,15,300);
waving.privRotAmount=0; //In case it was nan
+ waving.useOverlay=1;
+ waving.overlaySpeed=1;
+ waving.overlay = loadImg( DATADIR"data/menu/introoverlay.png" );
+ waving.overlayPos=waving.overlay->w+1;
+ waving.mask = loadImg( DATADIR"data/menu/intromask.png") ;
return(1);
}
@@ -271,6 +276,9 @@ int runMenu(SDL_Surface* screen)
resetBtn( C_BTNB );
menuState=menuStatePaused;
SDL_FreeSurface( menuBg[MENUGFXINTRO] );
+ SDL_FreeSurface( waving.overlay );
+ SDL_FreeSurface( waving.mask ) ;
+
menuBg[MENUGFXINTRO]=0;
menuPosY=0;
clearParticles();
@@ -540,7 +548,9 @@ int runMenu(SDL_Surface* screen)
{
txtWriteCenter(screen, FONTSMALL, STR_MENU_EDITOR_CHOICE, HSCREENW, HSCREENH+10);
if( isBoxClicked( getTxtBox() ) )
- menuPosY=1000;
+ {
+ menuPosY=4;
+ }
}
if(dir || menuPosY!= 5)
@@ -576,6 +586,8 @@ int runMenu(SDL_Surface* screen)
if( getButton( C_BTNB ) || isAnyBoxHit() )
{
resetBtn( C_BTNB );
+ resetMouseBtn();
+
switch(menuPosY)
{
case 0: //Newgame
@@ -843,10 +855,11 @@ int runMenu(SDL_Surface* screen)
}
break;
+ //The leveleditor submenu.
case menuStateUserLevels:
+ getInpPointerState()->escEnable=1;
starField(screen, 1);
fireWorks(screen);
- resetMouseBtn();
txtWave(screen, FONTMEDIUM, STR_MENU_LVLEDIT_HEADLINE, HSCREENW, HSCREENH-105, &rot);
menuMaxY=getNumUserLevels()+1;
@@ -854,14 +867,6 @@ int runMenu(SDL_Surface* screen)
//Just keep it clean.
if(player()->gameStarted) cleanUpGame();
- //Show Create and Exit menu-points.
- if(dir || menuPosY!= 0) txtWriteCenter(screen, FONTSMALL, STR_LVLEDIT_CREATE_CHOICE,HSCREENW,HSCREENH-70);
- if(dir || menuPosY!= 1) txtWriteCenter(screen, FONTSMALL, STR_LVLEDIT_EXIT_CHOICE,HSCREENW,HSCREENH-60);
-
-
- //Show usage
- txtWriteCenter(screen, FONTSMALL, STR_MENU_LVLEDIT_USAGE, HSCREENW, HSCREENH+108);
-
//List levels
ul=0; //Userlevel
scroll=0; //Generic scoll int
@@ -875,8 +880,21 @@ int runMenu(SDL_Surface* screen)
while(ul < getNumUserLevels())
{
i++;
- sprintf(buf, STR_MENU_LVLEDIT_USRLVL, ul);
+
+ if( menuPosY < 0 && -menuPosY==ul+2)
+ {
+ sprintf(buf, STR_MENU_LVLEDIT_USRLVL_SEL, ul);
+ } else {
+ sprintf(buf, STR_MENU_LVLEDIT_USRLVL, ul);
+ }
+
if(dir || menuPosY!= ul+2) txtWriteCenter(screen, FONTSMALL, buf, HSCREENW, HSCREENH-50+(10*(ul-scroll)));
+
+ if( isBoxClicked( getTxtBox() ) )
+ {
+ menuPosY=-(ul+2); //hackity hack, if menuposy is negative, we click-selected a level
+ }
+
ul++;
if( i > 12 )
{
@@ -889,72 +907,129 @@ int runMenu(SDL_Surface* screen)
txtWriteCenter(screen, FONTSMALL, STR_LVLEDIT_MORE, HSCREENW, HSCREENH-50+(10*(ul-scroll+1)));
}
-
- //Edit levels/select
- if(getButton(C_BTNB))
+ //Show keys only if cursor not active
+ if( !(getInpPointerState()->timeSinceMoved < POINTER_SHOW_TIMEOUT) )
{
- resetBtn(C_BTNB);
-
- if(menuPosY==0) //Load empty, and create new levelname
+ txtWriteCenter(screen, FONTSMALL, STR_MENU_LVLEDIT_USAGE, HSCREENW, HSCREENH+106);
+ } else {
+ //Show Play Clone Edit buttons for the mouse
+ if( menuPosY < 0)
{
- //Load empty, set name to something diffrent
- editorLoad( DATADIR"data/empty.wzp",screen);
- sprintf(buf, "%s/level%03i.wzp", getUserLevelDir(), getNumUserLevels());
- editorFileName(buf);
+ txtWriteCenter(screen, FONTSMALL, STR_MENU_LVLEDIT_PLAY, HSCREENW-60, HSCREENH+106 );
+ if( isBoxClicked( getTxtBox() ) )
+ {
+ ul=-1; //Decided that -1 means "play"
+ menuPosY=-menuPosY;
+ }
+
+ txtWriteCenter(screen, FONTSMALL, STR_MENU_LVLEDIT_EDIT, HSCREENW, HSCREENH+106 );
+ if( isBoxClicked( getTxtBox() ) )
+ {
+ ul=-2; //Decided that -2 means "edit"
+ menuPosY=-menuPosY;
+ }
+
+ txtWriteCenter(screen, FONTSMALL, STR_MENU_LVLEDIT_CLONE, HSCREENW+60, HSCREENH+106 );
+ if( isBoxClicked( getTxtBox() ) )
+ {
+ ul=-3; //Decided that -3 means "clone"
+ menuPosY=-menuPosY;
+ }
- return(STATEEDIT);
- } else if(menuPosY==1) //Exit from editor
- {
- player()->inEditor=0;
- menuState=menuStatePaused;
- menuPosY=0;
- } else {
- //Edit existing level
- editorLoad(userLevelFile(menuPosY-2),screen);
- return(STATEEDIT);
}
}
- //Clone a level
- if(getButton(C_BTNY))
+
+ //Show Create and Exit menu-points.
+ if(dir || menuPosY!= 0) txtWriteCenter(screen, FONTSMALL, STR_LVLEDIT_CREATE_CHOICE,HSCREENW,HSCREENH-70);
+ if( isBoxClicked( getTxtBox() ) )
+ menuPosY=0;
+
+ if( dir || menuPosY!= 1 ) txtWriteCenter(screen, FONTSMALL, STR_LVLEDIT_EXIT_CHOICE,HSCREENW,HSCREENH-60);
+ if( isBoxClicked( getTxtBox() ) )
+ menuPosY=1;
+
+ if( menuPosY > -1 )
{
- resetBtn(C_BTNY);
- if(menuPosY > 1)
+ //Edit levels/select
+ if(getButton(C_BTNB) || isAnyBoxHit() )
{
- //Load the selected level
- editorLoad(userLevelFile(menuPosY-2),screen);
+ resetMouseBtn();
+ resetBtn(C_BTNB);
- //Make new filename
- sprintf(buf, "%s/level%03i.wzp", getUserLevelDir(), getNumUserLevels());
- editorFileName(buf);
+ if(menuPosY==0) //Load empty, and create new levelname
+ {
+ //Load empty, set name to something diffrent
+ editorLoad( DATADIR"data/empty.wzp",screen);
+
+ sprintf(buf, "%s/level%03i.wzp", getUserLevelDir(), getNumUserLevels());
+ editorFileName(buf);
- //Start editing state
- return(STATEEDIT);
+ return(STATEEDIT);
+ } else if(menuPosY==1) //Exit from editor
+ {
+ player()->inEditor=0;
+ menuState=menuStatePaused;
+ menuPosY=0;
+ } else if( ul==-2 || ul>0 )
+ {
+ editorLoad(userLevelFile(menuPosY-2),screen);
+ return(STATEEDIT);
+ }
}
- }
- //Play levelfile
- if(getButton(C_BTNA))
- {
- resetBtn(C_BTNA);
- if(menuPosY > 1)
+ //Clone a level
+ if( getButton(C_BTNY) || ul==-3 )
{
- initPlayer(); //Reset player for editor.
- player()->levelFile = userLevelFile(menuPosY-2);
- player()->level = 0;
- player()->inEditor=1;
+ resetBtn(C_BTNY);
+ resetMouseBtn();
- if(initGame(screen))
+ if(menuPosY > 1)
{
- return(STATEPLAY);
- } else {
- printf("Editor couldn't init game for the editor.\n");
- return(STATEQUIT);
+ //Load the selected level
+ editorLoad(userLevelFile(menuPosY-2),screen);
+
+ //Make new filename
+ sprintf(buf, "%s/level%03i.wzp", getUserLevelDir(), getNumUserLevels());
+ editorFileName(buf);
+
+ //Start editing state
+ return(STATEEDIT);
+ }
+ }
+
+ //Play levelfile
+ if( getButton(C_BTNA) || ul==-1 )
+ {
+ resetBtn(C_BTNA);
+ resetMouseBtn();
+ if(menuPosY > 1)
+ {
+ initPlayer(); //Reset player for editor.
+ player()->levelFile = userLevelFile(menuPosY-2);
+ player()->level = 0;
+ player()->inEditor=1;
+
+ if(initGame(screen))
+ {
+ return(STATEPLAY);
+ } else {
+ printf("Editor couldn't init game for the editor.\n");
+ return(STATEQUIT);
+ }
}
}
+ } //Not a negative number
+
+
+ if(isPointerEscapeClicked())
+ {
+ menuState=menuStatePaused;
+ resetMouseBtn();
}
+
break; //< userlevels
case menuStatePackList:
View
6 strings.h
@@ -116,6 +116,7 @@
///General strings
+
#ifdef BUILD_NUMBER
#define VERSION_STRING "v1.0-dev (build "BUILD_NUMBER")"
#else
@@ -216,6 +217,11 @@
#define STR_LVLEDIT_CREATE_CHOICE "Create"
#define STR_LVLEDIT_EXIT_CHOICE "Exit"
#define STR_MENU_LVLEDIT_USRLVL "Level %i"
+#define STR_MENU_LVLEDIT_USRLVL_SEL "--> Level %i <--"
+
+#define STR_MENU_LVLEDIT_PLAY "Play"
+#define STR_MENU_LVLEDIT_CLONE "Clone"
+#define STR_MENU_LVLEDIT_EDIT "Edit"
#define STR_EDIT_SAVED "Saved"
#define STR_EDIT_UNSAVED "Not saved"
View
19 waveimg.c
@@ -37,22 +37,33 @@ void setWaving(wavingImage_t* wi, SDL_Surface* screen, SDL_Surface* img, int x,
void waveImg(wavingImage_t* wi)
{
- int x, y; //In the source image
+ int x, y,ox=0; //In the source image
int nx, ny; //new x/y value for px
uint32_t col; //Color of pixel
int r,g,b;
-
float pxInc = (6.28318531/wi->img->w)*wi->rotations;
float yInc;
wi->privRotAmount -=(float)getTicks()/wi->speed;
+ //If we use overlay, move it
+ if( wi->useOverlay )
+ {
+ wi->overlayPos += wi->overlaySpeed;
+ }
+
for(x=0; x < wi->img->w; x++)
{
yInc = cos(wi->privRotAmount+x*pxInc)*wi->amount;
+ if(wi->useOverlay)
+ {
+ ox=(wi->overlayPos-x)%wi->overlay->w;
+ if(ox < 0 ) { printf("Ox:%i\n",ox);}
+ }
+
for(y=0; y < wi->img->h; y++)
{
col = freadPixel(wi->img, x, y);
@@ -66,6 +77,10 @@ void waveImg(wavingImage_t* wi)
{
nx = x;
ny = y+yInc;
+
+ if( wi->useOverlay && (freadPixel(wi->mask, x, y) == 0) )
+ col = freadPixel(wi->overlay, ox, y);
+
plotPixel(wi->screen, nx+wi->x,ny+wi->y, col);
}
}
View
3  waveimg.h
@@ -24,6 +24,9 @@ struct wavingImage_s
SDL_Surface *screen, *img;
int x,y,rotations,amount,speed;
float privRotAmount; //Note: If this is not initialized properly it might be nan, in which case nothing will be shown.
+
+ int useOverlay, overlayPos, overlaySpeed;
+ SDL_Surface *overlay,*mask;
};
typedef struct wavingImage_s wavingImage_t;
//void waveImg(SDL_Surface* screen, SDL_Surface* img, int x, int y,int rots, int amount, int speed);
Please sign in to comment.
Something went wrong with that request. Please try again.