I'm not sure if this should be in Beginners Technical Questions or here, so move it if I put it in the wrong place.
I am trying to make a turn based strategy. here is my global script:
#sectionstart game_start // DO NOT EDIT OR REMOVE THIS LINE
function game_start() // called when the game starts, before the first room is loaded
{
GiveScore(5);
}
#sectionend game_start // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart repeatedly_execute // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
}
#sectionend repeatedly_execute // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart on_key_press // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) {// called when a key is pressed. keycode holds the key's ASCII code
if (IsGamePaused()==1) keycode=0; // game paused, so don't react to keypresses
if (keycode==17) QuitGame(1); // Ctrl-Q
if (keycode==363) SaveGameDialog(); // F5
if (keycode==365) RestoreGameDialog(); // F7
if (keycode==367) RestartGame(); // F9
if (keycode==434) SaveScreenShot("scrnshot.pcx"); // F12
if (keycode==9) InventoryScreen(); // Tab, show inventory
if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
if (keycode==22) Debug(1,0); // Ctrl-V, version
if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
while (player.Moving) Wait(1);
if (keycode==375 && Character.GetAtScreenXY(player.x-20, player.y) != cRed1){
player.WalkStraight(player.x-20, player.y);
GiveScore(-1);
if (game.score == 0 && player.ID == 0) {
while (player.Moving) Wait(1);
player.ChangeView (1);
cRed2.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
if (game.score == 0 && player.ID == 1) {
while (player.Moving) Wait(1);
player.ChangeView (1);
//Enemy's turn
cRed1.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
}
if (keycode==377) {
player.WalkStraight(player.x+20, player.y);
GiveScore(-1);
if (game.score == 0 && player.ID == 0) {
while (player.Moving) Wait(1);
player.ChangeView (1);
cRed2.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
if (game.score == 0 && player.ID == 1) {
while (player.Moving) Wait(1);
player.ChangeView (1);
//Enemy's turn
cRed1.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
}
if (keycode==380) {
player.WalkStraight(player.x, player.y+20);
GiveScore(-1);
if (game.score == 0 && player.ID == 0) {
while (player.Moving) Wait(1);
player.ChangeView (1);
cRed2.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
if (game.score == 0 && player.ID == 1) {
while (player.Moving) Wait(1);
player.ChangeView (1);
//Enemy's turn
cRed1.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
}
if (keycode==372) {
player.WalkStraight(player.x, player.y-20);
GiveScore(-1);
if (game.score == 0 && player.ID == 0) {
while (player.Moving) Wait(1);
player.ChangeView (1);
cRed2.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
if (game.score == 0 && player.ID == 1) {
while (player.Moving) Wait(1);
player.ChangeView (1);
//Enemy's turn
cRed1.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
}
}
#sectionend on_key_press // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart on_mouse_click // DO NOT EDIT OR REMOVE THIS LINE
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 // right-click, so cycle cursor
{
gPopup.Visible = true;
}
}
#sectionend on_mouse_click // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart interface_click // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button) {
}
#sectionend interface_click // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart Quit_Click
function Quit_Click(GUIControl *control, MouseButton button) {
QuitGame(1);
}
#sectionend Quit_Click
#sectionstart popupclose_Click
function popupclose_Click(GUIControl *control, MouseButton button) {
gPopup.Visible = false;
}
#sectionend popupclose_Click
#sectionstart Help_Click
function Help_Click(GUIControl *control, MouseButton button) {
Display("Arrow keys: Move");
}
#sectionend Help_Click
#sectionstart character1_a // DO NOT EDIT OR REMOVE THIS LINE
function character1_a() {
// script for Character 1 (RED2): Any click on character
}
#sectionend character1_a // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart unhandled_event // DO NOT EDIT OR REMOVE THIS LINE
function unhandled_event(int what, int type) {
}
#sectionend unhandled_event // DO NOT EDIT OR REMOVE THIS LINE
As you may have gathered, I have very little idea what I am doing.
I have the character switching code in each of the sections to move the character. Now I realized that the enemy code will have to be duplicated four times, once for each direction of movement. There is no way that this is the best way to do this, so I thought I would let one of you tell me a better way.
I also am having problems with collision detection of the characters. How can I make them not walk over each other? If I make the characters solid, they move right next to each other then stop, and then they are no longer lined up with the grid that I am using for the map.
Help???
I am trying to make a turn based strategy. here is my global script:
#sectionstart game_start // DO NOT EDIT OR REMOVE THIS LINE
function game_start() // called when the game starts, before the first room is loaded
{
GiveScore(5);
}
#sectionend game_start // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart repeatedly_execute // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute() {
}
#sectionend repeatedly_execute // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart on_key_press // DO NOT EDIT OR REMOVE THIS LINE
function on_key_press(int keycode) {// called when a key is pressed. keycode holds the key's ASCII code
if (IsGamePaused()==1) keycode=0; // game paused, so don't react to keypresses
if (keycode==17) QuitGame(1); // Ctrl-Q
if (keycode==363) SaveGameDialog(); // F5
if (keycode==365) RestoreGameDialog(); // F7
if (keycode==367) RestartGame(); // F9
if (keycode==434) SaveScreenShot("scrnshot.pcx"); // F12
if (keycode==9) InventoryScreen(); // Tab, show inventory
if (keycode==19) Debug(0,0); // Ctrl-S, give all inventory
if (keycode==22) Debug(1,0); // Ctrl-V, version
if (keycode==1) Debug(2,0); // Ctrl-A, show walkable areas
if (keycode==24) Debug(3,0); // Ctrl-X, teleport to room
while (player.Moving) Wait(1);
if (keycode==375 && Character.GetAtScreenXY(player.x-20, player.y) != cRed1){
player.WalkStraight(player.x-20, player.y);
GiveScore(-1);
if (game.score == 0 && player.ID == 0) {
while (player.Moving) Wait(1);
player.ChangeView (1);
cRed2.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
if (game.score == 0 && player.ID == 1) {
while (player.Moving) Wait(1);
player.ChangeView (1);
//Enemy's turn
cRed1.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
}
if (keycode==377) {
player.WalkStraight(player.x+20, player.y);
GiveScore(-1);
if (game.score == 0 && player.ID == 0) {
while (player.Moving) Wait(1);
player.ChangeView (1);
cRed2.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
if (game.score == 0 && player.ID == 1) {
while (player.Moving) Wait(1);
player.ChangeView (1);
//Enemy's turn
cRed1.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
}
if (keycode==380) {
player.WalkStraight(player.x, player.y+20);
GiveScore(-1);
if (game.score == 0 && player.ID == 0) {
while (player.Moving) Wait(1);
player.ChangeView (1);
cRed2.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
if (game.score == 0 && player.ID == 1) {
while (player.Moving) Wait(1);
player.ChangeView (1);
//Enemy's turn
cRed1.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
}
if (keycode==372) {
player.WalkStraight(player.x, player.y-20);
GiveScore(-1);
if (game.score == 0 && player.ID == 0) {
while (player.Moving) Wait(1);
player.ChangeView (1);
cRed2.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
if (game.score == 0 && player.ID == 1) {
while (player.Moving) Wait(1);
player.ChangeView (1);
//Enemy's turn
cRed1.SetAsPlayer();
player.ChangeView (2);
GiveScore(5);
}
}
}
#sectionend on_key_press // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart on_mouse_click // DO NOT EDIT OR REMOVE THIS LINE
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 // right-click, so cycle cursor
{
gPopup.Visible = true;
}
}
#sectionend on_mouse_click // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart interface_click // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button) {
}
#sectionend interface_click // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart Quit_Click
function Quit_Click(GUIControl *control, MouseButton button) {
QuitGame(1);
}
#sectionend Quit_Click
#sectionstart popupclose_Click
function popupclose_Click(GUIControl *control, MouseButton button) {
gPopup.Visible = false;
}
#sectionend popupclose_Click
#sectionstart Help_Click
function Help_Click(GUIControl *control, MouseButton button) {
Display("Arrow keys: Move");
}
#sectionend Help_Click
#sectionstart character1_a // DO NOT EDIT OR REMOVE THIS LINE
function character1_a() {
// script for Character 1 (RED2): Any click on character
}
#sectionend character1_a // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart unhandled_event // DO NOT EDIT OR REMOVE THIS LINE
function unhandled_event(int what, int type) {
}
#sectionend unhandled_event // DO NOT EDIT OR REMOVE THIS LINE
As you may have gathered, I have very little idea what I am doing.
I have the character switching code in each of the sections to move the character. Now I realized that the enemy code will have to be duplicated four times, once for each direction of movement. There is no way that this is the best way to do this, so I thought I would let one of you tell me a better way.
I also am having problems with collision detection of the characters. How can I make them not walk over each other? If I make the characters solid, they move right next to each other then stop, and then they are no longer lined up with the grid that I am using for the map.
Help???