DizzyAGE General Coding Queries
Started by delta on 9 February 2008 • 258,915 views
[quote data-userid="642" data-postid="82987"]
Hi Andy, when you say 2 layers, you mean just Dizzy’s layer and a sky background? You can find that in Pirate’s Life Dizzy and it’s very easy to do.
If you want to add more layers without the smooth scrolling, I can tell you how to do that – it’s not that hard if the scrolling is only horizontal.
[/quote]
Back to this! I'm trying to create a scrolling game with only one background, which moves left and right according to the player's X. At the moment, my background is static a la Pirate's Life Dizzy. I think a very simple way to implement it would be to just check if the player is walking left, and increment the X of the background, and vice versa. But how can I check? I can only see PlayterGe(P_STATUS)==STATUS_WALK, which doesn't define left or right. Thanks for any advice :smile:
If I remember right, the way I did this was as follows:
Define a new game variable, then put this line in the BeginNewGame function, and at the top of the PlayerUpdate Handler:
GameSet(G_PARALLAX,PlayerGet(P_ X) );
Then, put this bit in the GameAfterUpdate Handler:
step = ( PlayerGet(P_ X) - GameGet(G_PARALLA X) ) / 2;
if(step!=0)
{
back = ObjFind(100);
ObjSet(back,O_X,ObjGet(back,O_ X) + step);
ObjPresent(back);
}
That should move your background left and right at half the speed Dizzy walks. You can change the fraction to 1/4 or 3/4 by editing the "/2" in the code above.
BTW, this might not work if you're using the smooth scrolling code I posted before. In fact I'm pretty sure it won't.
OK I have another problem re: the scrolling. I always try to resolve this stuff myself but this one has been doing my nut for about a week now. Basically, my game starts indoors (interiors are on the top row of screens) and when you leave the house (4th row) it's stormy. After the first part of the game, the weather changes and that's when my parallax scrolling comes in. Except it doesn't. As I've been testing the game, I've been starting the player outside, and everything works as it should. So I suppose my question is: does the player NEED to start on the same screen as where the scrolling will begin? Because this will screw my intro up if I can't find a way around it. I've tried putting
GameSet(G_PARALLAX,PlayerGet(P_ X) );
elsewhere than within the BeginNewGame function and it doesn't seem to do anything.
Sorry that's very vague. I hope there's a simple solution but I suspect it will get complicated {yolkfolk}:sob:
That... worked... {yolkfolk}:yahoo: {yolkfolk}:yahoo: {yolkfolk}:yahoo: {yolkfolk}:joy: {yolkfolk}:cheers:
For some reason I would never have thought of that. I guess I still don't fully understand, but that's one more obstacle over! Thanks a lot
The tutorial includes a small water area you can enter with aqualung gear, it also talks you through the settings for draining energy from the player when entering water, without aqualung, before eventually drowning. At this point I seem to have ran into a problem with the safe respawn position of the player, I have worked out that the the game is seeing the river rock bed as a safe respawn point as the player is in contact with it before their energy is fully depleted, the result being that after death the player appears back in the water and dies again before being able to make it out.
I have been though the code and spotted a note that suggests the ability to create custom respawn points but I am not exactly sure how to do this and link it to the death in water (seems that a safe respawn point for water would be a single global command rather than a bespoke....).
Not really sure that this IS the answer, it may be I have a simple property/setting incorrect but I just can't see the wood for the trees.
Any help much appreciated, this is the last bug I have before completing my first small demo !
I just had a little look at this - it's not a problem I've had to deal with before. It looks like your best bet is to go into the player.gs file and find the IsPlayerSafe() function. Then you'll need to delete |(1<<MAT_WATER) from the first line.
That should stop it from recording your position as safe when underwater.
Alternatively check out post 251 on page 26 of this thread to see Jamie's rather splendid coding to determine whether to respawn on dry land or under water when you drown. I would suggest adding a scuba specific DropObject command in the game.gs file so that he doesn't drop the scuba when underwater
func DropObject_100() //if scuba is 100
{
if PlayerGet(P_MATCENTER) == MAT_WATER)
{
Message1 (4,3, ""No way, I'll drown""); MessagePop(); return;
}
idx = ObjFind(100); DoDropObject(idx);
}I am sure I can work it out from here :tup:
I'm back for a bit of help. I have been straying from the tutorial and adding my own bits and bobs, for a newbie all in all it's gone quite well...
I decided to tackle the menu.gs and remove the Load / Save function as for this short demo tutorial these options make it a little too easy. I managed to 'hack' that to pieces whilst continuing to code other game bits over a week or so, during this time the laptop sound was turned OFF, so of course I didn't notice at what point my music and sound effects stopped working {dizzy}:lookup:
I am guessing it is when I was in and around the menu.gs .... I have tried for a few days to fix this but with no joy, the sound on other DizzyAge games I have works OK. Would appreciate if someone could cast an eye and help me out so I can pack it up and send it to a few of my friends who are also Dizzy fans.
Thanks !
/////////////////////////////////////////////////////////////////////////////////
// menus.gs
// Deals with main menu, game menu, inventory menu and other related menus
// The MainMenu is a looping game sequence called when the game starts, from start.gs
// It usually shows a cover screen and it allows players to start a new game.
// It can also open a dialog menu, allowing players to load a saved game, read info, exit, etc.
// The game menu pauses the game and open a dialog menu allowing player to save, load, or restart the current game.
// The inventory pauses the game and allows the player to select an item from the inventory.
// Advanced users can rewrite menus behaiour, to match their game's needs.
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// MainMenu
// For classic game menu, with cover screen and optional attract mode.
// Uses KEY_ACTION to begin game and KEY_MENU to open dialog menu.
// Set MAINMENU_ATTRACT to 1 in gamedef.gs if you want to allow attract mode.
// For attract mode, your mainmenu room must have some valid content.
/////////////////////////////////////////////////////////////////////////////////
func MainMenu()
{
GameSet(G_PAUSE,0); // unpause the game
PlayerSetPos(PLAYER_MAINMENUX,PLAYER_MAINMENUY);// set player position in the mainmenu room
GameSet(G_COVER,1); // show cover screen
MusicStop(); // stop any playing music
MusicFade(0,0); // set music fade options
MusicPlay(MUSIC_DEFAULT); // plays default music
// mainmenu loop
ret = 1;
frame = 0;
framemax = 180; // frames interval to toggle attract mode on and off
mode = 0; // 0=cover, 1=attract
while(true)
{
stop;
frame++;
if(frame>=framemax && MAINMENU_ATTRACT)
{
frame = 0;
mode = !mode; // toggle attract mode
RoomSetName( GameGet(G_ROOMX), GameGet(G_ROOMY), (mode==0)?"PRESS ACTION TO START":"WELCOME TO DIZZY" );
}
GameSet(G_COVER,mode==0);
PlayerSet(P_DISABLE,mode==0);
if( mode==0 ) // cover mode
{
ret = 1;
if( GetKeyHit(KEY_ACTION) ) break; // start
if( GetKeyHit(KEY_MENU) ) // main menu
{
ret = OpenDialogMainMenu(); // 1=start,2=load,0=nothing
if(ret) break; // start
frame = 0;
}
}
else
if( mode==1 ) // attract mode
{
// foul around
if(gs_rand(10)==1 && PlayerGet(P_STATUS)==STATUS_WALK)
PlayerSet(P_DIR,gs_rand(2)?-1:1);
if(PlayerGet(P_DIR)==-1)
SetKey(KEY_LEFT,1);
else
SetKey(KEY_RIGHT,1);
if(gs_rand(20)==0)
SetKey(KEY_JUMP,1);
if(gs_rand(20)==0 && PlayerGet(P_STATUS)==STATUS_WALK)
PlayerEnterSpin(gs_rand(2)?-1:1);
if( GameGet(G_KEYSHIT)!=0 ) // any key hit
{
frame=0;
mode = 0;
}
}
}
ClearKeys(); // clear any resident keys
if(ret==1) // start new game
{
GameSet(G_COVER,0); // hide cover
GameSet(G_PAUSE,0); // unpause the game
PlayerSet(P_DISABLE,0); // enable the player
PlayerEnterIdle(); // start in idle
BeginNewGame(); // call user function to begin a new game (set player's position, etc)
}
}
/////////////////////////////////////////////////////////////////////////////////
// Opens the MainMenu dialog.
// Uses DialogMainMenu() function for dialog creation.
// Returns 1 if game must start with intro, 2 if game was loaded, 0 otherwise
/////////////////////////////////////////////////////////////////////////////////
func OpenDialogMainMenu()
{
GamePause(1);
select = RunDialogSelect( gs_fid("DialogMainMenu"), 4, 0 );
ret = 0;
if(select==0)
{
ret = 1;
}
//else
//if(select==1)
//{
// ret = OpenDialogFiles(0) ? 2 : 0;
//}
else
if(select==1)
{
OpenDialogOptions();
}
else
if(select==2)
{
OpenDialogCredits();
}
else
if(select==3)
{
if(OpenDialogQuestion("EXIT GAME ?",1))
GameCommand(CMD_EXIT);
}
GamePause(0);
return ret;
}
/////////////////////////////////////////////////////////////////////////////////
// IN: int; select; default selection
// Dialog creation function used by OpenDialogMainMenu().
/////////////////////////////////////////////////////////////////////////////////
func DialogMainMenu( select )
{
text = "{a:center}GAME MENUnn{c:0xff0000}";
if(select==0) text += "{f:1}START{f:0}n"; else text += "STARTn";
//if(select==1) text += "{f:1}LOAD{f:0}n"; else text += "LOADn";
if(select==1) text += "{f:1}OPTIONS{f:0}n"; else text += "OPTIONSn";
if(select==2) text += "{f:1}CREDITS{f:0}n"; else text += "CREDITSn";
if(select==3) text += "{f:1}EXIT{f:0}"; else text += "EXIT";
DialogPush();
DialogSetText(text);
DialogSetColor(COLOR_DIALOG);
DialogFitCenter();
}
/////////////////////////////////////////////////////////////////////////////////
// Opens the GameMenu dialog.
// Uses DialogGameMenu() function for dialog creation.
/////////////////////////////////////////////////////////////////////////////////
func OpenDialogGameMenu()
{
GamePause(1);
select = RunDialogSelect( gs_fid("DialogGameMenu"), 4, 0 );
//if(select==1)
//{
//OpenDialogFiles(1);
//}
//else
//if(select==2)
//{
// OpenDialogFiles(0);
//}
//else
if(select==1)
{
OpenDialogOptions();
}
else
if(select==2)
{
if(OpenDialogQuestion("RESTART GAME ?",1))
GameCommand(CMD_START);
}
else
if(select==3)
{
if(OpenDialogQuestion("EXIT GAME ?",1))
GameCommand(CMD_EXIT);
}
GamePause(0);
}
/////////////////////////////////////////////////////////////////////////////////
// IN: int; select; default selection
// Dialog creation function used by OpenDialogGameMenu().
/////////////////////////////////////////////////////////////////////////////////
func DialogGameMenu( select )
{
text = "{a:center}GAME PAUSEDnn{c:0xff0000}";
if(select==0) text += "{f:1}RESUME{f:0}n"; else text += "RESUMEn";
// if(select==2) text += "{f:1}LOAD{f:0}n"; else text += "LOADn";
if(select==1) text += "{f:1}OPTIONS{f:0}n"; else text += "OPTIONSn";
if(select==2) text += "{f:1}RESTART{f:0}n"; else text += "RESTARTn";
if(select==3) text += "{f:1}EXIT{f:0}"; else text += "EXIT";
DialogPush();
DialogSetText(text);
DialogSetColor(COLOR_DIALOG);
DialogFitCenter();
}
/////////////////////////////////////////////////////////////////////////////////
// Opens the Options dialog.
// Uses DialogOptions() function for dialog creation.
/////////////////////////////////////////////////////////////////////////////////
func OpenDialogOptions()
{
GamePause(1);
select=0;
loop:
select = RunDialogSelect( gs_fid("DialogOptions"), 4, select );
DialogPopAll();
if(select==0)
{
vol = 100;
if(gs_inigetint("dizzy.ini","AUDIO","volfx",&vol))
vol+=10;
if(vol>100) vol=0;
gs_inisetint("dizzy.ini","AUDIO","volfx",vol);
SampleVolume(vol);
SamplePlay(FX_BEEP2);
goto loop;
}
else
if(select==1)
{
vol = 100;
if(gs_inigetint("dizzy.ini","AUDIO","volmusic",&vol))
vol+=10;
if(vol>100) vol=0;
gs_inisetint("dizzy.ini","AUDIO","volmusic",vol);
MusicVolume(vol);
goto loop;
}
else
if(select==2)
{
OpenDialogControls();
}
GamePause(0);
}
/////////////////////////////////////////////////////////////////////////////////
// IN: int; select; default selection
// Dialog creation function used by OpenDialogOptions().
/////////////////////////////////////////////////////////////////////////////////
func DialogOptions( select )
{
// sound volumes
volfx = 100;
volmusic = 100;
gs_inigetint("dizzy.ini","AUDIO","volfx",&volfx);
gs_inigetint("dizzy.ini","AUDIO","volmusic",&volmusic);
text = "{a:center}GAME OPTIONSnn{c:0xff0000}";
if(select==0)
text += "{f:1}FX VOLUME " +(str)volfx+ "%{f:0}n";
else
text +="FX VOLUME " +(str)volfx+ "%n";
if(select==1)
text += "{f:1}MUSIC VOLUME " +(str)volmusic+ "%{f:0}n";
else
text +="MUSIC VOLUME " +(str)volmusic+ "%n";
if(select==2) text += "{f:1}CONTROLS{f:0}n"; else text += "CONTROLSn";
text+="n";
if(select==3) text += "{f:1}RETURN{f:0}"; else text += "RETURN";
DialogPush();
DialogSetText(text);
DialogSetColor(COLOR_DIALOG);
w = 18*8; // keep large and fixed
h = DialogTextH()+8; // add some space
DialogSetSize(w,h);
x = (GameGet(G_ROOMW)-w)/2;
y = (GameGet(G_ROOMH)-h)/2;
DialogSetPos(x,y);
}
/////////////////////////////////////////////////////////////////////////////////
// Opens the Controls dialog.
/////////////////////////////////////////////////////////////////////////////////
func OpenDialogControls()
{
text = "{a:center}";
text += "{c:0xffff00}GAME CONTROLSnn{a:left}";
text += " {c:0xffffff}Z{c:0xffff00} OR {c:0xffffff}LEFT{c:0xffff00} - MOVE LEFTn";
text += " {c:0xffffff}X{c:0xffff00} OR {c:0xffffff}RIGHT{c:0xffff00} - MOVE RIGHTn";
text += " {c:0xffffff}SPACE{c:0xffff00} OR {c:0xffffff}UP{c:0xffff00} - JUMPn";
text += " {c:0xffffff}ENTER{c:0xffff00} - ACTIONn";
text += " {c:0xffffff}ESCAPE{c:0xffff00} OR {c:0xffffff}Q{c:0xffff00} - MENUnn";
text += " {c:0xffffff}F9{c:0xffff00} - MUTE ALL SOUNDn";
text += " {c:0xffffff}F10{c:0xffff00} - TOGGLE SCREENn";
OpenDialogMessage(text);
}
/////////////////////////////////////////////////////////////////////////////////
// Opens the Credits dialog with the authors information.
/////////////////////////////////////////////////////////////////////////////////
func OpenDialogCredits()
{
// first page
text = "{a:center}CREDITSnn{c:0xffffffff}";
text += "GAME CREATED BYn";
text += "{c:0xff0080ff}" + GAME_AUTHOR + "{c:0xffffffff}nn";
text += "ORIGINAL DIZZY GAMES BYn";
text += "{c:0xff0080ff}OLIVER TWINSnAND CODEMASTERS{c:0xffffff00}n";
OpenDialogMessage(text);
}
str g_dialogfiles_title;
/////////////////////////////////////////////////////////////////////////////////
// IN: int; mode; 0=load mode, 1=save mode
// Opens the game files dialog for load or for save.
// Uses DialogFiles() function for dialog creation.
// Returns 1 if game was loaded or saved, 0 otherwise
/////////////////////////////////////////////////////////////////////////////////
//func OpenDialogFiles( mode )
//{
// g_dialogfiles_title = (mode==0) ? "LOAD GAME" : "SAVE GAME";
// select = RunDialogSelect( gs_fid("DialogFiles"), 4, 0 );
// if(select==3 || select==-1) return 0; // give up
// file = "save"+(str)(select+1)+".gam";
// info = gs_fileinfo(file);
// if(mode==0)
// {
// if(strempty(info))
// {
// OpenDialogMessage( "SLOT IS EMPTY", 0xffff0000 );
// return 0;
// }
// return LoadGame(file);
// }
// else
// {
// if(!strempty(info))
// {
// if(!OpenDialogQuestion("OVERWRITE FILE ?",1)) return 0;
// }
// return SaveGame(file);
// }
//}
/////////////////////////////////////////////////////////////////////////////////
// IN: int; select; default selection
// Dialog creation function used by OpenDialogFiles().
/////////////////////////////////////////////////////////////////////////////////
//func DialogFiles( select )
//{
// text = "{a:center}"+g_dialogfiles_title+"nn{c:0xff0000}";
// for(i=0;i<3;i++) // { // if(select==i) text+="{f:1}"; // file = "save"+(str)(i+1)+".gam"; // info = gs_fileinfo(file); // if(strempty(info)) // { // text+=" EMPTY "; // text+="SLOT "; // } // else // { // text+=" FILE"+(str)(i+1)+" "; // text+=strupr(strsub(info,4,12)); // } // if(select==i) text+="{f:0}"; // text += " n"; // } // text += "n"; // if(select==3) text += "{f:1}RETURN{f:0}"; else text += "RETURN"; // DialogPush(); // DialogSetText(text); // DialogSetColor(COLOR_DIALOG); // DialogFitCenter(); //} ///////////////////////////////////////////////////////////////////////////////// // Opens the Finish dialog // Uses DialogFinish() function for dialog creation. ///////////////////////////////////////////////////////////////////////////////// func OpenDialogFinish() { GamePause(1); select = RunDialogSelect( gs_fid("DialogFinish"), 3, 0, 1 ); if(select==0) { gs_shell(GAME_WEBSITE); GameCommand(CMD_START); } if(select==1) { GameCommand(CMD_START); } else if(select==2) { GameCommand(CMD_EXIT); } GamePause(0); } ///////////////////////////////////////////////////////////////////////////////// // IN: int; select; default selection // Dialog creation function used by OpenDialogFinish(). ///////////////////////////////////////////////////////////////////////////////// func DialogFinish( select ) { text = "{a:center}GAME COMPLETEDnn{c:0xff0000}"; if(select==0) text += "{f:1}WEB SITE{f:0}n"; else text += "WEB SITEn"; if(select==1) text += "{f:1}RESTART{f:0}n"; else text += "RESTARTn"; if(select==2) text += "{f:1}EXIT{f:0}"; else text += "EXIT"; DialogPush(); DialogSetText(text); DialogSetColor(COLOR_DIALOG); DialogFitCenter(); } ///////////////////////////////////////////////////////////////////////////////// // [IN]: int; defaultexit=0; default selection, 0=top item (last picked), 1=exit without dropping // OUT: int; object's index, or -1 for exiting without selecting an item // Opens the Inventory dialog and allows the player to choose one item for use (or drop). // Internally, the selection goes from [0 to InventoryCount()] (last selection means return without dropping). // Uses DialogInventory() function for dialog creation. ///////////////////////////////////////////////////////////////////////////////// func OpenDialogInventory( defaultexit ) { if(!?defaultexit) defaultexit=0; GamePause(1); count = InventoryCount(); default = 0; if(defaultexit) default = count; select = RunDialogSelect( gs_fid("DialogInventory"), count+1, default ); DialogPopAll(); GamePause(0); if( select==count || select==-1 ) return -1; // no selection idx = InventoryGet(count-1-select); // item selected return idx; } ///////////////////////////////////////////////////////////////////////////////// // IN: int; select; default selection // Dialog creation function used by OpenDialogInventory(). ///////////////////////////////////////////////////////////////////////////////// func DialogInventory( select ) { DialogPopAll(); // close all old dialogs (RunDialogSelect can handle only one) // construct text text = "{a:center}YOU ARE CARRYINGnn{c:0xff0000}"; // push elements names in reverse order (last is first) count = InventoryCount(); if(count>0)
{
for(i=count-1;i>=0;i--)
{
idx = InventoryGet(i);
if(select==count-1-i) text += "{f:1}";
text += ObjGetName(idx);
if(select==count-1-i) text += "{f:0}";
text += "n";
}
height = 5+count;
}
else
{
text += "{c:0xffffffff}N O T H I N Gn";
height = 5+1;
}
if(select==count) text += "{f:1}";
text += "nEXIT AND DON'T DROP";
if(select==count) text += "{f:0}";
// construct dialog
DialogPush();
DialogSetText(text);
DialogSetColor(COLOR_DIALOG);
//DialogFitCenter();
// compute position considering the tooltip dialog
border = 16;
w = DialogTextW()+8; // add some space
h = DialogTextH()+8; // add some space
DialogSetSize(w,h);
x = (GameGet(G_ROOMW)-w)/2;
y = (GameGet(G_ROOMH)-h-40)/2; // tooltip dialog (40)
y2 = y+h+border;
DialogSetPos(x,y);
// tooltip dialog
DialogPush();
DialogSetText("{c:0xff00ffff}CHOOSE ITEM TOnUSE OR DROP");
DialogSetColor(0xffffffff);
w = DialogTextW()+8; // add some space
h = DialogTextH()+8; // add some space
DialogSetSize(w,h);
x = (GameGet(G_ROOMW)-w)/2;
DialogSetPos(x,y2);
}
/////////////////////////////////////////////////////////////////////////////////Also, I remember when making my first game, the sound stopped working and I think I fixed it by replacing the .ini file. Never found out why it worked though.
Don't apologise for stating the obvious Simon, all of us have mumbled 'Oh for ****'s sake', whilst banging our head on the keyboard at least once. {dizzy}:mad:
Most of the time there's no need to faff around with the .ini file (as long as the audio enabled line is equal to 1).
I still sometimes take about 5 minutes to work out silly typing errors such as forgetting to put the backward slash at the end of a conversation before the two sets of quotes when the compiler shuts the game down. {yolkfolk}:scratch:
M4, personally, I think it's easier to just set the music going at the start of the BeginNewGame function as the menu file just brings up the game and inventory options. If you do want to edit out the load and save options, just remember that each 'menu' has a number to show the available options so make sure you amend it correctly.
If it makes it easier, try thinking along these lines as an very simple example of how the menus file functions
func DialogChoiceZ (select)
{
text = THINK;
if (select) == 1) text = GOOD THOUGHTS;
if (select) == 2) text = BAD THOUGHTS;
if (select) == 0) text = EXIT;
}
func OpenDialogChoiceZ()
{
GamePause(1);
select = RunDialogSelect (gs_fid("DialogChoiceZ") 3,0) //choice of three, 0 is the default
if (select==1) {goodthoughts();} //opens this function
if (select==2) {badthoughts();} //opens this function
if (select==0) {MessagePop();} //closes window
GamePause(0);
}Hello. Is it real to make pipe transportation of Dizzy through the pipes (like in Spellbound) in dizzyage?
Hi deflector, I did this in my game 'Almost Spellbound Dizzy', feel free to unpak and check it out.
Basically, I created 'fatter' tiles and added them as disabled, then used a massive status check with a tile that switched the thin/fat tiles in sequence and had room updates and moved 'disabled' Dizzy into the room where the pipes started changing.
An easier way to do it would be to switch Dizzy to a 'fat tile' and move the x and y co-ordinates over the 'normal' sized pipe to give the impression of movement. Switching tiles is similar to the way you switch Dizzy movement tiles when in water.
Good luck. :tup:
Good day! I've done fade screen codes like it was described in this thread before. Is it possible to apply it only for the active game screen (not for the hud panel and border)?