From a4433808695a5d408820e1fac351739333305e2f Mon Sep 17 00:00:00 2001 From: Edmundo Ruiz Date: Sat, 16 Aug 2014 11:51:15 -0700 Subject: [PATCH 1/2] Added Adventure Game Studio (AGS) Script language definition and samples. --- lib/linguist/languages.yml | 10 + samples/AGS Script/GlobalScript.asc | 521 ++++++++++++++++++++ samples/AGS Script/GlobalScript.ash | 4 + samples/AGS Script/KeyboardMovement_102.asc | 216 ++++++++ samples/AGS Script/KeyboardMovement_102.ash | 13 + 5 files changed, 764 insertions(+) create mode 100644 samples/AGS Script/GlobalScript.asc create mode 100644 samples/AGS Script/GlobalScript.ash create mode 100644 samples/AGS Script/KeyboardMovement_102.asc create mode 100644 samples/AGS Script/KeyboardMovement_102.ash diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index b7defba5..111ca481 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -28,6 +28,16 @@ ABAP: extensions: - .abap +AGS Script: + type: programming + lexer: C++ + color: "#B9D9FF" + aliases: + - ags + extensions: + - .asc + - .ash + ANTLR: type: programming color: "#9DC3FF" diff --git a/samples/AGS Script/GlobalScript.asc b/samples/AGS Script/GlobalScript.asc new file mode 100644 index 00000000..507cb071 --- /dev/null +++ b/samples/AGS Script/GlobalScript.asc @@ -0,0 +1,521 @@ +// main global script file + +// A function that initializes a bunch of stuff. +function initialize_control_panel() { + // Centre the control panel + gPanel.Centre(); + // Centre the Restart dialog as well + gRestartYN.Centre(); + if (!IsSpeechVoxAvailable()) { + // If there is no speech-vox file, and therefore no speech, + // disable all the controls related with speech. + lblVoice.Visible = false; + btnVoice.Visible = false; + sldVoice.Visible = false; + } + else { + // If there *is*, then set it to voice and text. It's best to use + // both whenever possible, for the player's sake. + SetVoiceMode(eSpeechVoiceAndText); + // And reflect this in the control panel. + btnVoice.Text = "Voice and Text"; + } + if (!System.SupportsGammaControl) { + // If we can't change the gamma settings, disable the relevant options. + sldGamma.Visible = false; + lblGamma.Visible = false; + } + + //And now, set all the defaults + System.Volume = 100; + sldAudio.Value = System.Volume; + SetGameSpeed(40); + sldSpeed.Value = 40; + if (IsSpeechVoxAvailable()) { + SetVoiceMode(eSpeechVoiceAndText); + btnVoice.Text = "Voice and Text"; + sldVoice.Value = 255; + SetSpeechVolume(255); + } + if (System.SupportsGammaControl) { + System.Gamma = 100; + sldGamma.Value = 100; + } +} + +// Called when the game starts, before the first room is loaded +function game_start() { + // Put the code all in a function and then just call the function. + // It saves cluttering up places like game_start. + initialize_control_panel(); + // Use the KeyboardMovement module to, per default, replicate the standard + // keyboard movement of most Sierra games. See KeyboardMovement.txt for more info + KeyboardMovement.SetMode(eKeyboardMovement_Tapping); +} + +function repeatedly_execute() { + + // Put here anything you want to happen every game cycle, even when + // the game is paused. This will not run when the game is blocked + // inside a command like a blocking Walk() + + if (IsGamePaused() == 1) return; + + // Put here anything you want to happen every game cycle, but not + // when the game is paused. +} + +function repeatedly_execute_always() { + + // Put anything you want to happen every game cycle, even + // when the game is blocked inside a command like a + // blocking Walk(). + // You cannot run blocking commands from this function. + +} + +function show_inventory_window () +{ + gInventory.Visible = true; + // switch to the Use cursor (to select items with) + mouse.Mode = eModeInteract; + // But, override the appearance to look like the arrow + mouse.UseModeGraphic(eModePointer); +} + +function show_save_game_dialog() +{ + gSaveGame.Visible = true; + // Get the list of save games + lstSaveGamesList.FillSaveGameList(); + if (lstSaveGamesList.ItemCount > 0) + { + // If there is at least one, set the default text + // to be the first game's name + txtNewSaveName.Text = lstSaveGamesList.Items[0]; + } + else + { + // No save games yet, default empty text. + txtNewSaveName.Text = ""; + } + mouse.UseModeGraphic(eModePointer); + gIconbar.Visible = false; +} + +function show_restore_game_dialog() +{ + gRestoreGame.Visible = true; + lstRestoreGamesList.FillSaveGameList(); + mouse.UseModeGraphic(eModePointer); + gIconbar.Visible = false; +} + +function close_save_game_dialog() +{ + gSaveGame.Visible = false; + mouse.UseDefaultGraphic(); + gIconbar.Visible = true; +} + +function close_restore_game_dialog() +{ + gRestoreGame.Visible = false; + mouse.UseDefaultGraphic(); + gIconbar.Visible = true; +} + +// Called when a key is pressed. keycode holds the key's ASCII code +function on_key_press(eKeyCode keycode) { + // The following is called before "if game is paused keycode=0", so + // it'll happen even when the game is paused. + + if ((keycode == eKeyEscape) && gRestartYN.Visible) { + //Use ESC to cancel restart. + gRestartYN.Visible = false; + gIconbar.Visible = true; + // If the panel's not ON, then the player must have gotten here by tapping F9, + // therefore his cursor needs restoring. If the panel IS on, then it doesn't, + // because it's already a pointer. Get used to thinking like this!! + if (!gPanel.Visible) mouse.UseDefaultGraphic(); + return; + } + if ((keycode == eKeyEscape) && gPanel.Visible) { + // Use ESC to turn the panel off. + gPanel.Visible = false; + mouse.UseDefaultGraphic(); + gIconbar.Visible = true; + return; + } + if ((keycode == eKeyEscape) && (gSaveGame.Visible)) + { + // Use ESC to close the save game dialog + close_save_game_dialog(); + return; + } + if ((keycode == eKeyEscape) && (gRestoreGame.Visible)) + { + // Use ESC to close the restore game dialog + close_restore_game_dialog(); + return; + } + + if (keycode == eKeyReturn) { + // ENTER, in this case merely confirms restart + if (gRestartYN.Visible) RestartGame(); + } + + if (IsGamePaused() || (IsInterfaceEnabled() == 0)) + { + // If the game is paused with a modal GUI on the + // screen, or the player interface is disabled in + // a cut scene, ignore any keypresses. + return; + } + + // FUNCTION KEYS AND SYSTEM SHORTCUTS + if (keycode == eKeyEscape) { + // ESC + gPanel.Visible = true; + gIconbar.Visible = false; + mouse.UseModeGraphic(eModePointer); + } + if (keycode == eKeyCtrlQ) QuitGame(1); // Ctrl-Q + if (keycode == eKeyF5) show_save_game_dialog(); // F5 + if (keycode == eKeyF7) show_restore_game_dialog(); // F7 + if (keycode == eKeyF9) { + // F9, asks the player to confirm restarting (so much better to always confirm first) + gRestartYN.Visible = true; + gIconbar.Visible = false; + mouse.UseModeGraphic(eModePointer); + } + if (keycode == eKeyF12) SaveScreenShot("scrnshot.bmp"); // F12 + if (keycode == eKeyTab) show_inventory_window(); // Tab, show inventory + + // GAME COMMAND SHORTCUTS + if (keycode == 'W') mouse.Mode=eModeWalkto; //Notice this alternate way to indicate keycodes. + if (keycode == 'L') mouse.Mode=eModeLookat; //Note that all we do here is set modes. + if (keycode == 'U') mouse.Mode=eModeInteract; //If you want something else to happen, such as GUI buttons highlighting, + if (keycode == 'T') mouse.Mode=eModeTalkto; //you'll need some more scripting done. + if (keycode == 'I') mouse.Mode=eModeUseinv; //But this will, as-is, give you some standard keyboard shortcuts your players will very much appreciate. + + // For extra cursor modes, such as pick up, feel free to add as you will. + // Uncomment the line below if you use the "Pick Up" mode. + //if (keycode == 'P' || keycode == 'G') mouse.Mode=eModePickup; + + // DEBUG FUNCTIONS + if (keycode == eKeyCtrlS) Debug(0,0); // Ctrl-S, give all inventory + if (keycode == eKeyCtrlV) Debug(1,0); // Ctrl-V, version + if (keycode == eKeyCtrlA) Debug(2,0); // Ctrl-A, show walkable areas + if (keycode == eKeyCtrlX) Debug(3,0); // Ctrl-X, teleport to room + if (keycode == eKeyCtrlW && game.debug_mode) + player.PlaceOnWalkableArea(); //Ctrl-W, move to walkable area +} + + +function on_mouse_click(MouseButton button) { + // called when a mouse button is clicked. button is either LEFT or RIGHT + if (IsGamePaused() == 1) { + // Game is paused, so do nothing (ie. don't allow mouse click) + } + else if (button == eMouseLeft) { + ProcessClick(mouse.x, mouse.y, mouse.Mode ); + } + else if (button == eMouseRight || button == eMouseWheelSouth){ + // right-click our mouse-wheel down, so cycle cursor + mouse.SelectNextMode(); + } + else if (button == eMouseMiddle) { + // Middle-button-click, default make character walk to clicked area (a little shortcut) + // Could have been just "player.Walk(mouse.x,mouse.y)", but it's best to + // leave our options open - what if you have a special script triggered + // on "walking" mode? + ProcessClick(mouse.x, mouse.y, eModeWalkto); + } + else if (button == eMouseWheelNorth) { + // Mouse-wheel up, cycle cursors + // If mode isn't WALK, set the previous mode (notice usage of numbers instead + // of eNums, when it suits us)... + if (mouse.Mode>0) mouse.Mode=mouse.Mode-1; + else + { + // ...but if it is WALK mode... + if (player.ActiveInventory!=null) + { + //...and the player has a selected inventory item, set mouse mode to UseInv. + mouse.Mode=eModeUseinv; + } + else + { + // If they don't, however, just set it to mode TALK (change this line if you add more cursor modes) + mouse.Mode=eModeTalkto; + } + } + } +} + +function interface_click(int interface, int button) { + // This function is obsolete, from 2.62 and earlier versions. +} + +function btnInvUp_Click(GUIControl *control, MouseButton button) { + invCustomInv.ScrollUp(); +} + +function btnInvDown_Click(GUIControl *control, MouseButton button) { + invCustomInv.ScrollDown(); +} + +function btnInvOK_Click(GUIControl *control, MouseButton button) { + // They pressed the OK button, close the GUI + gInventory.Visible = false; + mouse.UseDefaultGraphic(); +} + +function btnInvSelect_Click(GUIControl *control, MouseButton button) { + + // They pressed SELECT, so switch to the Get cursor + mouse.Mode = eModeInteract; + // But, override the appearance to look like the arrow + mouse.UseModeGraphic(eModePointer); +} + +function btnIconInv_Click(GUIControl *control, MouseButton button) { + + show_inventory_window(); +} + +function btnIconCurInv_Click(GUIControl *control, MouseButton button) { + + if (player.ActiveInventory != null) + mouse.Mode = eModeUseinv; +} + +function btnIconSave_Click(GUIControl *control, MouseButton button) +{ + show_save_game_dialog(); +} + +function btnIconLoad_Click(GUIControl *control, MouseButton button) +{ + show_restore_game_dialog(); +} + +function btnIconExit_Click(GUIControl *control, MouseButton button) { + + QuitGame(1); +} + +function btnIconAbout_Click(GUIControl *control, MouseButton button) { + + gPanel.Visible=true; + gIconbar.Visible=false; + mouse.UseModeGraphic(eModePointer); +} + +function cEgo_Look() +{ + Display("Damn, I'm looking good!"); +} + +function cEgo_Interact() +{ + Display("You rub your hands up and down your clothes."); +} + +function cEgo_Talk() +{ + Display("Talking to yourself is a sign of madness!"); +} + +//START OF CONTROL PANEL FUNCTIONS +function btnSave_OnClick(GUIControl *control, MouseButton button) +{ + gPanel.Visible = false; + mouse.UseDefaultGraphic(); + gIconbar.Visible = true; + Wait(1); + btnIconSave_Click(btnIconSave, eMouseLeft); +} + +function gControl_OnClick(GUI *theGui, MouseButton button) +{ + +} + +function btnAbout_OnClick(GUIControl *control, MouseButton button) +{ +Display("Adventure Game Studio run-time engine default game."); +} + +function btnQuit_OnClick(GUIControl *control, MouseButton button) +{ + gPanel.Visible = false; + Wait(1); + QuitGame(1); + gPanel.Visible = true; + gIconbar.Visible = false; + mouse.UseModeGraphic(eModePointer); +} + +function btnLoad_OnClick(GUIControl *control, MouseButton button) +{ + gPanel.Visible = false; + mouse.UseDefaultGraphic(); + gIconbar.Visible = true; + Wait(1); + btnIconLoad_Click(btnIconLoad, eMouseLeft); +} + +function btnResume_OnClick(GUIControl *control, MouseButton button) +{ + gPanel.Visible = false; + mouse.UseDefaultGraphic(); + gIconbar.Visible = true; +} + +function sldAudio_OnChange(GUIControl *control) +{ + System.Volume = sldAudio.Value; +} + +function sldVoice_OnChange(GUIControl *control) +{ + // Sets voice volume. Note that we don't check for the existence of speech.vox - + // we did that in game_start, so if it's not there the slider won't even be available. + SetSpeechVolume(sldVoice.Value); +} + +function btnVoice_OnClick(GUIControl *control, MouseButton button) +{ + // Note that we don't check for the existence of speech.vox - we did that in game_start, + // so if it's not there the button won't even be available. + if (btnVoice.Text == "Voice and Text") { + SetVoiceMode(eSpeechVoiceOnly); + btnVoice.Text = "Voice only"; + } + else if (btnVoice.Text == "Voice only") { + SetVoiceMode(eSpeechTextOnly); + btnVoice.Text = "Text only"; + } + else if (btnVoice.Text == "Text only") { + SetVoiceMode(eSpeechVoiceAndText); + btnVoice.Text = "Voice and Text"; + } +} + +function sldGamma_OnChange(GUIControl *control) +{ + // Set the gamma. Note there's no need to check for anything else, as we ensured, + // in game_start, that the slider won't even appear if it's not possible to do this. + System.Gamma = sldGamma.Value; +} + +function btnDefault_OnClick(GUIControl *control, MouseButton button) +{ + // Reset everything to default. You'll have to edit these as well as the sliders + // if you'd rather have different default parameters. + System.Volume = 100; + sldAudio.Value = System.Volume; + sldSpeed.Value = 40; + SetGameSpeed(40); + if (IsSpeechVoxAvailable()) { + SetVoiceMode(eSpeechVoiceAndText); + btnVoice.Text = "Voice and Text"; + sldVoice.Value = 255; + SetSpeechVolume(255); + } + if (System.SupportsGammaControl) { + System.Gamma = 100; + sldGamma.Value = 100; + } +} +//END OF CONTROL PANEL FUNCTIONS + +function dialog_request(int param) +{ + // This is used by the dialog text parser if you need to process + // text that the player types in to the parser. + // It is not used by default. +} + +function sldSpeed_OnChange(GUIControl *control) +{ + SetGameSpeed(sldSpeed.Value); +} + +function btnRestart_OnClick(GUIControl *control, MouseButton button) +{ + gRestartYN.Visible=true; + gIconbar.Visible=false; +} + +function btnRestartYes_OnClick(GUIControl *control, MouseButton button) +{ + RestartGame(); +} + +function btnRestartNo_OnClick(GUIControl *control, MouseButton button) +{ + gRestartYN.Visible = false; + gIconbar.Visible = true; + // If the panel's not ON, then the player must have gotten here by tapping F9, + // therefore his cursor needs restoring. If the panel IS on, then it doesn't, + // because it's already a pointer. Get used to thinking like this!! + if (!gPanel.Visible) mouse.UseDefaultGraphic(); +} + +function btnCancelSave_OnClick(GUIControl *control, MouseButton button) +{ + close_save_game_dialog(); +} + +function btnSaveGame_OnClick(GUIControl *control, MouseButton button) +{ + int gameSlotToSaveInto = lstSaveGamesList.ItemCount + 1; + int i = 0; + while (i < lstSaveGamesList.ItemCount) + { + if (lstSaveGamesList.Items[i] == txtNewSaveName.Text) + { + gameSlotToSaveInto = lstSaveGamesList.SaveGameSlots[i]; + } + i++; + } + SaveGameSlot(gameSlotToSaveInto, txtNewSaveName.Text); + close_save_game_dialog(); +} + +function btnCancelRestore_OnClick(GUIControl *control, MouseButton button) +{ + close_restore_game_dialog(); +} + +function btnRestoreGame_OnClick(GUIControl *control, MouseButton button) +{ + if (lstRestoreGamesList.SelectedIndex >= 0) + { + RestoreGameSlot(lstRestoreGamesList.SaveGameSlots[lstRestoreGamesList.SelectedIndex]); + } + close_restore_game_dialog(); +} + +function lstSaveGamesList_OnSelectionCh(GUIControl *control) +{ + txtNewSaveName.Text = lstSaveGamesList.Items[lstSaveGamesList.SelectedIndex]; +} + +function txtNewSaveName_OnActivate(GUIControl *control) +{ + // Pressing return in the text box simulates clicking the Save button + btnSaveGame_OnClick(control, eMouseLeft); +} + +function btnDeleteSave_OnClick(GUIControl *control, MouseButton button) +{ + if (lstSaveGamesList.SelectedIndex >= 0) + { + DeleteSaveSlot(lstSaveGamesList.SaveGameSlots[lstSaveGamesList.SelectedIndex]); + lstSaveGamesList.FillSaveGameList(); + } +} diff --git a/samples/AGS Script/GlobalScript.ash b/samples/AGS Script/GlobalScript.ash new file mode 100644 index 00000000..2dab2f11 --- /dev/null +++ b/samples/AGS Script/GlobalScript.ash @@ -0,0 +1,4 @@ +// Main header script - this will be included into every script in +// the game (local and global). Do not place functions here; rather, +// place import definitions and #define names here to be used by all +// scripts. diff --git a/samples/AGS Script/KeyboardMovement_102.asc b/samples/AGS Script/KeyboardMovement_102.asc new file mode 100644 index 00000000..8776789a --- /dev/null +++ b/samples/AGS Script/KeyboardMovement_102.asc @@ -0,0 +1,216 @@ +// Main script for module 'KeyboardMovement' + +//**************************************************************************************************** +// DEFINITIONS +//**************************************************************************************************** + +#define DISTANCE 10000// distance player walks in Tapping mode before he stops + +enum KeyboardMovement_Directions { + eKeyboardMovement_Stop, + eKeyboardMovement_DownLeft, + eKeyboardMovement_Down, + eKeyboardMovement_DownRight, + eKeyboardMovement_Left, + eKeyboardMovement_Right, + eKeyboardMovement_UpLeft, + eKeyboardMovement_Up, + eKeyboardMovement_UpRight +}; + +//**************************************************************************************************** +// VARIABLES +//**************************************************************************************************** + +// keycodes as variables for future key customization functions (static variables?): +int KeyboardMovement_KeyDown = 380; // down arrow +int KeyboardMovement_KeyLeft = 375; // left arrow +int KeyboardMovement_KeyRight = 377; // right arrow +int KeyboardMovement_KeyUp = 372; // up arrow +int KeyboardMovement_KeyDownRight = 381; // PgDn (numpad) +int KeyboardMovement_KeyUpRight = 373; // PgUp (numpad) +int KeyboardMovement_KeyDownLeft = 379; // End (numpad) +int KeyboardMovement_KeyUpLeft = 371; // Home (numpad) +int KeyboardMovement_KeyStop = 376; // 5 (numpad) + +KeyboardMovement_Modes KeyboardMovement_Mode = eKeyboardMovement_None; // stores current keyboard control mode (disabled by default) + +KeyboardMovement_Directions KeyboardMovement_CurrentDirection = eKeyboardMovement_Stop; // stores current walking direction of player character + +//**************************************************************************************************** +// USER FUNCTIONS +//**************************************************************************************************** + +//==================================================================================================== + +static function KeyboardMovement::SetMode(KeyboardMovement_Modes mode) { + KeyboardMovement_Mode = mode; +} + +//==================================================================================================== + +// key customization functions here + +//==================================================================================================== + +//**************************************************************************************************** +// EVENT HANDLER FUNCTIONS +//**************************************************************************************************** + +//==================================================================================================== + +function repeatedly_execute() { + + //-------------------------------------------------- + // Pressing mode + //-------------------------------------------------- + + if ((IsGamePaused() == true) || (KeyboardMovement_Mode != eKeyboardMovement_Pressing) || (IsInterfaceEnabled() == false) || (player.on == false)) return 0; + // if game is paused, module or mode disabled, interface disabled or player character hidden, quit function + + KeyboardMovement_Directions newdirection; // declare variable storing new direction + + // get new direction: + if ( ((IsKeyPressed(KeyboardMovement_KeyDown)) && (IsKeyPressed(KeyboardMovement_KeyRight))) || (IsKeyPressed(KeyboardMovement_KeyDownRight)) ) newdirection = eKeyboardMovement_DownRight; // if down&right arrows or PgDn (numeric pad) held down, set new direction to Down-Right + else if ( ((IsKeyPressed(KeyboardMovement_KeyUp)) && (IsKeyPressed(KeyboardMovement_KeyRight))) || (IsKeyPressed(KeyboardMovement_KeyUpRight)) ) newdirection = eKeyboardMovement_UpRight; // up&right arrows or PgUp (numpad) + else if ( ((IsKeyPressed(KeyboardMovement_KeyDown)) && (IsKeyPressed(KeyboardMovement_KeyLeft))) || (IsKeyPressed(KeyboardMovement_KeyDownLeft)) ) newdirection = eKeyboardMovement_DownLeft; // down&left arrows or End (numpad) + else if ( ((IsKeyPressed(KeyboardMovement_KeyUp)) && (IsKeyPressed(KeyboardMovement_KeyLeft))) || (IsKeyPressed(KeyboardMovement_KeyUpLeft)) ) newdirection = eKeyboardMovement_UpLeft; // up&left arrows or Home (numpad) + else if (IsKeyPressed(KeyboardMovement_KeyDown)) newdirection = eKeyboardMovement_Down; // down arrow + else if (IsKeyPressed(KeyboardMovement_KeyLeft)) newdirection = eKeyboardMovement_Left; // left arrow + else if (IsKeyPressed(KeyboardMovement_KeyRight)) newdirection = eKeyboardMovement_Right; // right arrow + else if (IsKeyPressed(KeyboardMovement_KeyUp)) newdirection = eKeyboardMovement_Up; // up arrow + else newdirection = eKeyboardMovement_Stop; // if none of the above held down, set it to stop player character + + if (IsKeyPressed(KeyboardMovement_KeyStop)) newdirection = eKeyboardMovement_Stop; // if 5 (numeric pad) held down, stop player character, regardless of whether some of the above are held down + + if (newdirection != KeyboardMovement_CurrentDirection) { // if new direction is different from current direction + + if (newdirection == eKeyboardMovement_Stop) player.StopMoving(); // if new direction is the Stop command, stop movement of player character + else { // if new direction is NOT the Stop command + + int dx, dy; // declare variables storing new walk coordinates + if (newdirection == eKeyboardMovement_DownRight) { + dx = DISTANCE; + dy = DISTANCE; + } + else if (newdirection == eKeyboardMovement_UpRight) { + dx = DISTANCE; + dy = -DISTANCE; + } + else if (newdirection == eKeyboardMovement_DownLeft) { + dx = -DISTANCE; + dy = DISTANCE; + } + else if (newdirection == eKeyboardMovement_UpLeft) { + dx = -DISTANCE; + dy = -DISTANCE; + } + else if (newdirection == eKeyboardMovement_Down) { + dx = 0; + dy = DISTANCE; + } + else if (newdirection == eKeyboardMovement_Left) { + dx = -DISTANCE; + dy = 0; + } + else if (newdirection == eKeyboardMovement_Right) { + dx = DISTANCE; + dy = 0; + } + else if (newdirection == eKeyboardMovement_Up) { + dx = 0; + dy = -DISTANCE; + } + + player.WalkStraight(player.x + dx, player.y + dy, eNoBlock); // walk player character to the new coordinates + } + KeyboardMovement_CurrentDirection = newdirection; // update current direction to new direction + + } + +} + +//==================================================================================================== + +function on_key_press(int keycode) { + + //-------------------------------------------------- + // Tapping mode + //-------------------------------------------------- + + if ((IsGamePaused() == true) || (KeyboardMovement_Mode != eKeyboardMovement_Tapping) || (IsInterfaceEnabled() == false) || (player.on == false)) return 0; + // if game is paused, module or mode disabled, interface disabled or player character hidden, quit function + + KeyboardMovement_Directions newdirection; // declare variable storing new direction + + // get new direction: + if (keycode == KeyboardMovement_KeyDownRight) newdirection = eKeyboardMovement_DownRight; // if down-right key pressed, set new direction to Down-Right + else if (keycode == KeyboardMovement_KeyUpRight) newdirection = eKeyboardMovement_UpRight; + else if (keycode == KeyboardMovement_KeyDownLeft) newdirection = eKeyboardMovement_DownLeft; + else if (keycode == KeyboardMovement_KeyUpLeft) newdirection = eKeyboardMovement_UpLeft; + else if (keycode == KeyboardMovement_KeyDown) newdirection = eKeyboardMovement_Down; + else if (keycode == KeyboardMovement_KeyLeft) newdirection = eKeyboardMovement_Left; + else if (keycode == KeyboardMovement_KeyRight) newdirection = eKeyboardMovement_Right; + else if (keycode == KeyboardMovement_KeyUp) newdirection = eKeyboardMovement_Up; + else if (keycode == KeyboardMovement_KeyStop) newdirection = eKeyboardMovement_Stop; // if stop key pressed, set to stop player character + + if (newdirection != KeyboardMovement_CurrentDirection) { // if new direction is different from current direction + + if (newdirection == eKeyboardMovement_Stop) player.StopMoving(); // if new direction is the Stop command, stop movement of player character + else { // if new direction is NOT the Stop command + + int dx, dy; // declare variables storing new walk coordinates + if (newdirection == eKeyboardMovement_DownRight) { + dx = DISTANCE; + dy = DISTANCE; + } + else if (newdirection == eKeyboardMovement_UpRight) { + dx = DISTANCE; + dy = -DISTANCE; + } + else if (newdirection == eKeyboardMovement_DownLeft) { + dx = -DISTANCE; + dy = DISTANCE; + } + else if (newdirection == eKeyboardMovement_UpLeft) { + dx = -DISTANCE; + dy = -DISTANCE; + } + else if (newdirection == eKeyboardMovement_Down) { + dx = 0; + dy = DISTANCE; + } + else if (newdirection == eKeyboardMovement_Left) { + dx = -DISTANCE; + dy = 0; + } + else if (newdirection == eKeyboardMovement_Right) { + dx = DISTANCE; + dy = 0; + } + else if (newdirection == eKeyboardMovement_Up) { + dx = 0; + dy = -DISTANCE; + } + + player.WalkStraight(player.x + dx, player.y + dy, eNoBlock); // walk player character to the new coordinates + } + KeyboardMovement_CurrentDirection = newdirection; // update current direction to new direction + + } + else { // if new direction is same as current direction + player.StopMoving(); // stop player character + KeyboardMovement_CurrentDirection = eKeyboardMovement_Stop; // update current direction + } + +} + +//==================================================================================================== + +function on_event(EventType event, int data) { + + if (event == eEventLeaveRoom) KeyboardMovement_CurrentDirection = eKeyboardMovement_Stop; + +} + +//==================================================================================================== diff --git a/samples/AGS Script/KeyboardMovement_102.ash b/samples/AGS Script/KeyboardMovement_102.ash new file mode 100644 index 00000000..a1e28c2c --- /dev/null +++ b/samples/AGS Script/KeyboardMovement_102.ash @@ -0,0 +1,13 @@ +// Script header for module 'KeyboardMovement' + +#define KeyboardMovement_VERSION 101 + +enum KeyboardMovement_Modes { + eKeyboardMovement_None, + eKeyboardMovement_Tapping, + eKeyboardMovement_Pressing +}; + +struct KeyboardMovement { + import static function SetMode(KeyboardMovement_Modes mode); +}; From be86f28be175d871df22efe1437bbaf5595e3f7b Mon Sep 17 00:00:00 2001 From: Edmundo Ruiz Date: Sat, 16 Aug 2014 12:22:22 -0700 Subject: [PATCH 2/2] Raked samples file with AGS Script. --- lib/linguist/samples.json | 368 +++++++++++++++++++++++++++++++++++++- 1 file changed, 365 insertions(+), 3 deletions(-) diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index 68ba6f6b..d981b824 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -3,6 +3,10 @@ "ABAP": [ ".abap" ], + "AGS Script": [ + ".asc", + ".ash" + ], "ATS": [ ".atxt", ".dats", @@ -829,8 +833,8 @@ "exception.zep.php" ] }, - "tokens_total": 651675, - "languages_total": 892, + "tokens_total": 654392, + "languages_total": 896, "tokens": { "ABAP": { "*/**": 1, @@ -1091,6 +1095,362 @@ "pos": 2, "endclass.": 1 }, + "AGS Script": { + "function": 54, + "initialize_control_panel": 2, + "(": 281, + ")": 282, + "{": 106, + "gPanel.Centre": 1, + ";": 235, + "gRestartYN.Centre": 1, + "if": 96, + "IsSpeechVoxAvailable": 3, + "lblVoice.Visible": 1, + "false": 26, + "btnVoice.Visible": 1, + "sldVoice.Visible": 1, + "}": 107, + "else": 44, + "SetVoiceMode": 6, + "eSpeechVoiceAndText": 4, + "btnVoice.Text": 9, + "System.SupportsGammaControl": 3, + "sldGamma.Visible": 1, + "lblGamma.Visible": 1, + "//And": 1, + "now": 1, + "set": 7, + "all": 2, + "the": 15, + "defaults": 1, + "System.Volume": 5, + "sldAudio.Value": 3, + "SetGameSpeed": 3, + "sldSpeed.Value": 3, + "sldVoice.Value": 3, + "SetSpeechVolume": 3, + "System.Gamma": 3, + "sldGamma.Value": 3, + "game_start": 1, + "KeyboardMovement.SetMode": 1, + "eKeyboardMovement_Tapping": 3, + "repeatedly_execute": 2, + "IsGamePaused": 4, + "return": 8, + "repeatedly_execute_always": 1, + "show_inventory_window": 3, + "gInventory.Visible": 2, + "true": 18, + "mouse.Mode": 13, + "eModeInteract": 3, + "mouse.UseModeGraphic": 8, + "eModePointer": 8, + "show_save_game_dialog": 3, + "gSaveGame.Visible": 3, + "lstSaveGamesList.FillSaveGameList": 2, + "lstSaveGamesList.ItemCount": 3, + "txtNewSaveName.Text": 5, + "lstSaveGamesList.Items": 3, + "[": 6, + "]": 6, + "gIconbar.Visible": 15, + "show_restore_game_dialog": 3, + "gRestoreGame.Visible": 3, + "lstRestoreGamesList.FillSaveGameList": 1, + "close_save_game_dialog": 4, + "mouse.UseDefaultGraphic": 9, + "close_restore_game_dialog": 4, + "on_key_press": 2, + "eKeyCode": 1, + "keycode": 27, + "eKeyEscape": 5, + "&&": 8, + "gRestartYN.Visible": 6, + "//Use": 1, + "ESC": 1, + "to": 14, + "cancel": 1, + "restart.": 1, + "gPanel.Visible": 11, + "eKeyReturn": 1, + "RestartGame": 2, + "||": 12, + "IsInterfaceEnabled": 3, + "eKeyCtrlQ": 1, + "QuitGame": 3, + "//": 66, + "Ctrl": 1, + "-": 217, + "Q": 1, + "eKeyF5": 1, + "F5": 1, + "eKeyF7": 1, + "F7": 1, + "eKeyF9": 1, + "eKeyF12": 1, + "SaveScreenShot": 1, + "F12": 1, + "eKeyTab": 1, + "Tab": 1, + "show": 1, + "inventory": 2, + "eModeWalkto": 2, + "//Notice": 1, + "this": 1, + "alternate": 1, + "way": 1, + "indicate": 1, + "keycodes.": 1, + "eModeLookat": 1, + "//Note": 1, + "that": 1, + "we": 1, + "do": 1, + "here": 1, + "is": 10, + "modes.": 1, + "//If": 1, + "you": 1, + "want": 1, + "something": 1, + "happen": 1, + "such": 1, + "as": 2, + "GUI": 3, + "buttons": 1, + "highlighting": 1, + "eModeTalkto": 2, + "//you": 1, + "I": 1, + "P": 1, + "G": 1, + "t": 1, + "allow": 1, + "mouse": 2, + "click": 1, + "button": 33, + "eMouseLeft": 4, + "ProcessClick": 2, + "mouse.x": 2, + "mouse.y": 2, + "eMouseRight": 1, + "eMouseWheelSouth": 1, + "mouse.SelectNextMode": 1, + "eMouseMiddle": 1, + "eMouseWheelNorth": 1, + "player.ActiveInventory": 2, + "null": 2, + "//...and": 1, + "player": 13, + "has": 1, + "a": 1, + "selected": 1, + "item": 1, + "mode": 10, + "UseInv.": 1, + "eModeUseinv": 2, + "interface_click": 1, + "int": 18, + "interface": 3, + "btnInvUp_Click": 1, + "GUIControl": 31, + "*control": 31, + "MouseButton": 26, + "invCustomInv.ScrollUp": 1, + "btnInvDown_Click": 1, + "invCustomInv.ScrollDown": 1, + "btnInvOK_Click": 1, + "They": 2, + "pressed": 4, + "OK": 1, + "close": 1, + "btnInvSelect_Click": 1, + "SELECT": 1, + "so": 1, + "switch": 1, + "Get": 1, + "cursor": 1, + "But": 1, + "override": 1, + "appearance": 1, + "look": 1, + "like": 1, + "arrow": 9, + "btnIconInv_Click": 1, + "btnIconCurInv_Click": 1, + "btnIconSave_Click": 2, + "btnIconLoad_Click": 2, + "btnIconExit_Click": 1, + "btnIconAbout_Click": 1, + "cEgo_Look": 1, + "Display": 4, + "cEgo_Interact": 1, + "cEgo_Talk": 1, + "//START": 1, + "OF": 2, + "CONTROL": 2, + "PANEL": 2, + "FUNCTIONS": 2, + "btnSave_OnClick": 1, + "Wait": 3, + "btnIconSave": 1, + "gControl_OnClick": 1, + "*theGui": 1, + "btnAbout_OnClick": 1, + "btnQuit_OnClick": 1, + "btnLoad_OnClick": 1, + "btnIconLoad": 1, + "btnResume_OnClick": 1, + "sldAudio_OnChange": 1, + "sldVoice_OnChange": 1, + "btnVoice_OnClick": 1, + "eSpeechVoiceOnly": 1, + "eSpeechTextOnly": 1, + "sldGamma_OnChange": 1, + "btnDefault_OnClick": 1, + "//END": 1, + "dialog_request": 1, + "param": 1, + "sldSpeed_OnChange": 1, + "btnRestart_OnClick": 1, + "btnRestartYes_OnClick": 1, + "btnRestartNo_OnClick": 1, + "btnCancelSave_OnClick": 1, + "btnSaveGame_OnClick": 2, + "gameSlotToSaveInto": 3, + "+": 7, + "i": 5, + "while": 1, + "<": 1, + "lstSaveGamesList.SaveGameSlots": 2, + "SaveGameSlot": 1, + "btnCancelRestore_OnClick": 1, + "btnRestoreGame_OnClick": 1, + "lstRestoreGamesList.SelectedIndex": 2, + "RestoreGameSlot": 1, + "lstRestoreGamesList.SaveGameSlots": 1, + "lstSaveGamesList_OnSelectionCh": 1, + "lstSaveGamesList.SelectedIndex": 3, + "txtNewSaveName_OnActivate": 1, + "control": 2, + "btnDeleteSave_OnClick": 1, + "DeleteSaveSlot": 1, + "//****************************************************************************************************": 8, + "#define": 2, + "DISTANCE": 25, + "distance": 1, + "walks": 1, + "in": 1, + "Tapping": 2, + "before": 1, + "he": 1, + "stops": 1, + "enum": 2, + "KeyboardMovement_Directions": 4, + "eKeyboardMovement_Stop": 9, + "eKeyboardMovement_DownLeft": 5, + "eKeyboardMovement_Down": 5, + "eKeyboardMovement_DownRight": 5, + "eKeyboardMovement_Left": 5, + "eKeyboardMovement_Right": 5, + "eKeyboardMovement_UpLeft": 5, + "eKeyboardMovement_Up": 5, + "eKeyboardMovement_UpRight": 5, + "KeyboardMovement_KeyDown": 5, + "down": 9, + "KeyboardMovement_KeyLeft": 5, + "left": 4, + "KeyboardMovement_KeyRight": 5, + "right": 5, + "KeyboardMovement_KeyUp": 5, + "up": 4, + "KeyboardMovement_KeyDownRight": 3, + "PgDn": 2, + "numpad": 8, + "KeyboardMovement_KeyUpRight": 3, + "PgUp": 2, + "KeyboardMovement_KeyDownLeft": 3, + "End": 2, + "KeyboardMovement_KeyUpLeft": 3, + "Home": 2, + "KeyboardMovement_KeyStop": 3, + "KeyboardMovement_Modes": 4, + "KeyboardMovement_Mode": 4, + "eKeyboardMovement_None": 2, + "stores": 2, + "current": 8, + "keyboard": 1, + "disabled": 5, + "by": 1, + "default": 1, + "KeyboardMovement_CurrentDirection": 7, + "walking": 1, + "direction": 22, + "of": 6, + "character": 11, + "static": 2, + "KeyboardMovement": 2, + "SetMode": 2, + "Pressing": 1, + "eKeyboardMovement_Pressing": 2, + "player.on": 2, + "game": 2, + "paused": 2, + "module": 2, + "or": 8, + "hidden": 2, + "quit": 2, + "newdirection": 43, + "declare": 4, + "variable": 2, + "storing": 4, + "new": 19, + "get": 2, + "IsKeyPressed": 17, + "&": 4, + "arrows": 4, + "numeric": 2, + "pad": 2, + "held": 4, + "Down": 2, + "Right": 2, + "none": 1, + "above": 2, + "it": 1, + "stop": 7, + "regardless": 1, + "whether": 1, + "some": 1, + "are": 1, + "different": 2, + "from": 2, + "player.StopMoving": 3, + "Stop": 4, + "command": 4, + "movement": 2, + "NOT": 2, + "dx": 20, + "dy": 20, + "variables": 2, + "walk": 4, + "coordinates": 4, + "player.WalkStraight": 2, + "player.x": 2, + "player.y": 2, + "eNoBlock": 2, + "update": 3, + "key": 2, + "same": 1, + "on_event": 1, + "EventType": 1, + "event": 2, + "data": 1, + "eEventLeaveRoom": 1, + "KeyboardMovement_VERSION": 1, + "struct": 1, + "import": 1 + }, "ATS": { "//": 211, "#include": 16, @@ -72103,6 +72463,7 @@ }, "language_tokens": { "ABAP": 1500, + "AGS Script": 2717, "ATS": 4558, "Agda": 376, "Alloy": 1143, @@ -72311,6 +72672,7 @@ }, "languages": { "ABAP": 1, + "AGS Script": 4, "ATS": 10, "Agda": 1, "Alloy": 3, @@ -72517,5 +72879,5 @@ "fish": 3, "wisp": 1 }, - "md5": "6ad93b92805b6680a539a188d7c820fa" + "md5": "bfcc1394a867e7d464859dd597eba7ad" } \ No newline at end of file