Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - lakotajames

#1
my code now:
Code: ags

// global script
int GridUnitWidth = 20; // set this to the width of each section of the grid
int GridUnitHeight = 20; // the height of each section

int GetGridX(int roomX) {
  return ((roomX / GridUnitWidth) * GridUnitWidth) + (GridUnitWidth / 2);
}

int GetGridY(int roomY) {
  return ((roomY / GridUnitWidth) * GridUnitWidth) + (GridUnitWidth / 2);
}


function ChangeTurn() {
	if (game.score == 0) {   
		player.ChangeView (player.View-1);
		if ((player == cRed2) || (player == cBlue2)) {
			//Switch Sides
			if (player == cRed2) cBlue.SetAsPlayer();
			if (player == cBlue2) cRed1.SetAsPlayer();
			}
			else {
			//Switch Players
			if (player == cBlue) cBlue2.SetAsPlayer();
			if (player == cRed1) cRed2.SetAsPlayer();
			}
		player.ChangeView (player.View+1);
		GiveScore(5);			
		}    
	}



void WalkToXYOnGrid(Character *theChar, int roomX, int roomY) {
  if (theChar == null) return;
  roomX = GetGridX(roomX);
  roomY = GetGridY(roomY);
  Character *charAtXY = Character.GetAtScreenXY(roomX - GetViewportX(), roomY - GetViewportY());
  if (charAtXY != null) {
    int xdiff = theChar.x - roomX;
    int ydiff = theChar.y - roomY;
    if (xdiff < 0) xdiff = -xdiff;
    if (ydiff < 0) ydiff = -ydiff;
    if (xdiff > ydiff) {
      if (theChar.x < charAtXY.x) {
        if (roomX > (GridUnitWidth / 2)) roomX -= GridUnitWidth;
        else roomX += GridUnitWidth;
      }
      else {
        if (roomX < (Room.Width - (GridUnitWidth / 2))) roomX += GridUnitWidth;
        else roomX -= GridUnitWidth;
      }
    }
    else {
      if (theChar.y < charAtXY.y) {
        if (roomY > (GridUnitHeight / 2)) roomY -= GridUnitHeight;
        else roomY += GridUnitHeight;
      }
      else {
        if (roomY < (Room.Height - (GridUnitHeight / 2))) roomY += GridUnitHeight;
        else roomY -= GridUnitHeight;
      }
    }
  }
  theChar.Walk(roomX, roomY);
}
#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) {
	WalkToXYOnGrid(player, player.x - 20, player.y);
	GiveScore(-1);
	ChangeTurn();
	}
if (keycode==377) {
	WalkToXYOnGrid(player, player.x+20, player.y);
	GiveScore(-1);
	ChangeTurn();
	}
if (keycode==380) {
	WalkToXYOnGrid(player, player.x, player.y+20);
	GiveScore(-1);
	ChangeTurn();
	}
if (keycode==372) {
	WalkToXYOnGrid(player, player.x, player.y-20);
	GiveScore(-1);
	ChangeTurn();
	}
}
#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 show menu
    {   
    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



Now they will no longer move upwards, and there still isn't any collision detection.  Also, they are no longer lined up with my grid, but that isn't as important as the ability to move upwards.
#2
Like on a chess board, where you are always in a square.  The pieces will never be setting on the lines, they go directly to the next square.  if i make the characters solid, then the character moves on to the next square but stops just before reaching the center, and from then on when he moves he is no longer on the squares.
#3
Thanks Pumaman.  That will help a lot.  Now, does anyone know how to make the characters so they will not run over each other?  I tried to do this here:
Code: ags
if (keycode==375 && Character.GetAtScreenXY(player.x-20, player.y) != cRed1){

It doesn't work, though.
#4
Advanced Technical Forum / Turn Based Strategy
Mon 29/09/2008 18:17:13
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???
#5
"Error: (line 42) Undefined token 'labelname'"

This wouldn't have to do with me using 2.72, would it?
#6
Thanks.  I only read the section under "other features", I didn't think to check in the scripting section  :-[
#7
I want to make text on a GUI display the contents of a string or variable.  How can I do that?
#8
Beginners' Technical Questions / Re: loading
Tue 29/01/2008 15:29:45
Thanks.
#9
Beginners' Technical Questions / loading
Mon 28/01/2008 18:17:08
is there any way i could make a gameover screen with three choices: new, continue, and quit?
i was using a room to do it in, and the new button works. but is there a way the continue button could make the load box come up, and the quit close the game?
SMF spam blocked by CleanTalk