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 - bx83

#61
Yes - crowds are Objects, tank is Character.
#62
CW: But how would he paint them over? DrawCircle(black); ds.Release(); somehow get all characters to move over the Circles? Ah I'm sure it's possible, will investigate...
Khris: which answer, the grid? Already got that semi-programmed...
#63
I'm making a Pacman clone.
In it, I want to have unexplored maze be filled with a little circular pill that my main character can eat up. There are 40 objects allowed on screen; no idea how many characters, but probably not 20 I have +200 little pills.
Does anyone have any idea how to solve this problem? How can I get the little round pills in all free squares and then get them to change graphic or destroy() when my Character collides with them?

#64
Thank you :)
#65
How do you do 'to the power of 2' / 'squared'?
#66
I'm trying to work out some vectors:

Code: ags
//defs
  int tmx, tmy, cx, cy;       //x,y coords of tankman (tmx,tmy) and yourself (cx,cy)
  float Ftmx, Ftmy, Fcx, Fcy;    //their float equivalents

  float vc[4];           //define direction vectors
  vc[0]=-1.0;
  vc[1]=-1.0;
  vc[2]=-1.0;
  vc[3]=-1.0;  //set to -1 so non-existant directions don't come back as shortest vector ie. 0 distance
  
...

  Ftmx=IntToFloat(tmx);   //get Float values from original ints
  Ftmy=IntToFloat(tmy);
  Fcx=IntToFloat(cx);
  Fcy=IntToFloat(cy);

  if (C.up==1) {     //if we have direction up...
        cy--;
        if(cy<0)cy=9;
        vc[0] = Maths.Sqrt((Fcx-Ftmx)^2 + (Fcy-Ftmy)^2);      <----- ERROR! Type mismatch: cannot convert 'int' to 'float'


Wait what?
I tried putting in ^2.0 instead of ^2, but unsurprisingly this didn't work. Nothing else is not a float :/
#67
'Object' as in 'I've had a stroke'.
I mean, 6-7 years ago my day job was writing (well, maintaining) a mainframe interface via C# for a government web-portal. Now it's writing a Pacman clone. So, you know.
#68
Basically, it looks like an object (class), but just says 'struct'. Has its own functions, is its own replicable thing, but never anymore than a struct. But it sounds like AGS script is more complex.

Update: oooh, it has casting?
#69
Out of interest, why is there no reserved word for ‘class’ or even ‘object’? Can you have constructors/deconstructers?
Strange having an object instance never referred to as object and using ‘struct’ to define.
#70
Very well explained, thank you CW :)  Hopefully I wont make that mistake in the future (hopefully...)

One more one:

Tankman.ash
Code: ags

managed struct Crowd {
  int aX;     //actual x eg. 312
  int aY;     //actual y eg. 472
  int tX;     //target x - x centre of target tile
...
  import void ResetTimers(Crowd *crowd);
...


Tankman.asc
Code: ags
void Crowd::ResetTimers(Crowd *crowd)
{...}

[much lower down]

void Crowd::ResetCrowd(Crowd *crowd)
{
...
  ResetTimers(this);   <-----ERROR: 'Undefined token ResetTimers'
...
}


How the hell is this undefined? I need to put Crowd:: in front of it? If I do, it says 'Variable '::' is already defined'
#71
Okay.

in Tankman.ash:
Code: ags
Tile *theGrid[];    //dynamic array of pointers
Crowd* rabble[5];    //5 crowds


in Room52.asc:
Code: ags
function game_start()
{
  theGrid[]=new Tile[numRows*numCols];  //define it as a new Tile array of size rows*colums  <----error this line
}


Failed to save room room52.crm; details below
room52.asc(3): Error (line 3): array index not specified


I'm going to bed, its midnight :/
#72
So I put these:

Tile theGrid[]=new *Tile[numRows*numCols];
Crowd rabble[5];

...into a function in a room, into area above code in a room, the Tankman.ash and .asc.
Always the error: Error (line xx): Cannot declare local instance of managed type

Would it be possible to do the struct definitions, the function definition, and everything, just in one room? I am getting in over my head for a Pacman clone :/
#73
So if I did a

import Tile *theGrid[] = new Tile[numRows*numCols];

Inside of Tankman.ash, it would be global to the .asc and a room which imports __Tankman?

Would I need to declare the dynamic array in the Tile struct to show its extendible?
#74
Okay, I've simplified a bit. 'Grid' is now gone; to create a map of Tiles, I've just put it into a Tile array[rows*columns]; as you can see in Tankman.asc

But...

Tankman.ash
Code: ags
// new module header
struct __Tankman
{
  import function Enable();
  import function Disable();
};
import __Tankman Tankman;


#define numRows     8
#define numCols     10

managed struct Tile {
  int x;  //x centre of tile
  int y;  //y centre of tile
  //String refName;
  bool up;      //has up direction
  bool right;   //has right direction
  bool down;    //has down direction
  bool left;    //has left direction
  int content;  //is it a free tile or blocked space?
};

#define numCrowds   5

managed struct Crowd {
  int aX;     //actual x eg. 312
  int aY;     //actual y eg. 472
  int tX;     //target x - target char/tile x coord - '3' for 'tile 34'
  int tY;     //target y - target char/tile y coord - '4' for 'tile 34'
  
  int mode;   //mode, 0=chase, attack=1, scatter=2, scared=3, regen=4
  int timer1; //timer to stay in mode
  int timer2; //timer to stay aggressive
  int waittimer;  //timer for wait between attacks/cooldown time
  int dir;    //0=up, 1=right, 2=down, 3=left  Never Eat Soggy Wheatbix
  int nogo;   //opposite direction to where your pointed; dir/nogo 0/2 1/3 2/0 3/1
  int moving; //1=moving to next coord, 0=not moving, decision/action time
  int id;     //0..4
  
  import void SetupCrowds();
  import void ResetCrowd(Crowd *crowd);
  import void ResetTimers(Crowd *crowd);
  import void FindTargetBasedOnMode(Crowd *crowd, int mode);
  import void MoveCrowdToTarget(Crowd *crowd);
  import int SetNogo(int dir);
};


Tankman.asc
Code: ags
__Tankman Tankman;
export Tankman;

bool gEnabled = false;
export gEnabled;

Tile *theGrid[numRows*numCols]; //global tile grid       <----ERROR! Tankman.asc(7): Error (line 7): expected ']'
Crowd *rabble[5];               //global crowd array

function __Tankman::Enable()
{
  gEnabled = true;
}

function __Tankman::Disable()
{
  gEnabled = false;
}

export Tile;
export Crowd;

//true=even, false=odd
bool isEven(int n)
{
...


What is wrong with line 7 of Tankman.asc?

Will these variables, theGrid[] etc, be global to the module? Any room they're defined in? I just want store it in a module, use it in a room.
#75
Okay, I've changed my code and got rid of most errors; but still some remain:

Tankman.ash
Code: ags
// new module header
struct __Tankman
{
  import function Enable();
  import function Disable();
};
import __Tankman Tankman;


#define numRows     8
#define numCols     10

struct Tile {
  int x;  //x centre of tile
  int y;  //y centre of tile
  String refName;
  bool up;      //has up direction
  bool right;   //has right direction
  bool down;    //has down direction
  bool left;    //has left direction
  int content;  //is it a free tile or blocked space?
};

managed struct Grid {
  import void SetupGridValues();
  import Tile Grid::RandomFreeSquare();         <---------------ERROR: Tankman.ash(26): Error (line 26): Member variable cannot be struct
  import Tile Grid::TileFromRef(String refName);
};


#define numCrowds   5

managed struct Crowd {
  int aX;     //actual x eg. 312
  int aY;     //actual y eg. 472
  int tX;     //target x - target char/tile x coord - '3' for 'tile 34'
  int tY;     //target y - target char/tile y coord - '4' for 'tile 34'
  
  int mode;   //mode, 0=chase, attack=1, scatter=2, scared=3, regen=4
  int timer1; //timer to stay in mode
  int timer2; //timer to stay aggressive
  int waittimer;  //timer for wait between attacks/cooldown time
  int dir;    //0=up, 1=right, 2=down, 3=left  Never Eat Soggy Wheatbix
  int nogo;   //opposite direction to where your pointed; dir/nogo 0/2 1/3 2/0 3/1
  int moving; //1=moving to next coord, 0=not moving, decision/action time
  int id;     //0..4
  
  import void SetupCrowds();
  import void ResetCrowd(Crowd *crowd);
  import void ResetTimers(Crowd *crowd);
  import void FindTargetBasedOnMode(Crowd *crowd, int mode);
  import void MoveCrowdToTarget(Crowd *crowd);
  import int SetNogo(int dir);
};



Tankman.asc
Code: ags
__Tankman Tankman;
export Tankman;

bool gEnabled = false;
export gEnabled;

Tile *theGrid[numRows*numCols]; //global tile grid
Crowd *rabble[5];               //global crowd array

function __Tankman::Enable()
{
  gEnabled = true;
}

function __Tankman::Disable()
{
  gEnabled = false;
}

export Tile;
export Crowd;


//true=even, false=odd
bool isEven(int n)
{
...
}

//put in y, get x
int GetRowRange(int y)
{
...
}

//put in x, get y
int GetColRange(int x)
{
...
}

//set opposite direction to current direction; you cannot ever go in this direction
//eg. you are headed right; you cannot go backwards, so nogo=left
int Crowd::SetNogo(int dir)
{
...
}

//x1 is to the left of x2
//0=left
//1=same square
//2=right
int IsLeftOf(int x1, int x2)
{
...
}

//y1 is above y2
//0=up
//1=same square
//2=down
int IsUpOf(int y1, int y2)
{
...
}

//look up tile number, get actual tile returned
Tile Grid::TileFromRef(String refName)
{
...
}

//get a tile's refName from it's x,y coords eg x=3, y=4, refname string "34"
String RefFromTile(int x, int y)
{
...
}

//reset a crowd's timers
//todo: put something here to get new decision on where to go, or put in next planned decision
void Crowd::ResetTimers(Crowd *crowd)
{
...
}

//get a random free square pointer
//free is content=0
Tile* Grid::RandomFreeSquare()
{
...
}

//is an object overlapping a character, even by a pixel?
//note: doesn't account for transparent squares overlapping
bool IsOverlappingCO(Character *ch, Object *ob)
{
...
}  

//is an character overlapping another character, even by a pixel?
//note: doesn't account for transparent squares overlapping
bool IsOverlappingCC(Character *ch1, Character *ch2)
{
...
}  

//reset crowd's variables/initialise a new crowd
void Crowd::ResetCrowd(Crowd *crowd)
{
...
}


//go through crowd array, intialise all
void Crowd::SetupCrowds()
{
...
}

//intial setup for grid values
void Grid::SetupGridValues()
{
...
}

//using mode, set x,y target and strategy
void Crowd::FindTargetBasedOnMode(Crowd *crowd, int mode)
{
...
}

//move a crowd it's tX,tY target coord,
//and set 'moving' to '1' for 'not on a tile centre, better move 1 closed'
//and '0' for 'on a tile's centre; better make my next decision now i'm at tile 67, my target tile'
void Crowd::MoveCrowdToTarget(Crowd *crowd)
{
...
}


Room52.asc
Code: ags
// room script file

///////////////
// VARIABLES //
///////////////

#define DISTANCE 1  //0000// distance player walks in Tapping mode before he stops
#define MAX_BULLETS 3
#define MAX_LNDMINE 5
#define AG_WALL 2
#define FirstCrowdIndex 5
#define LastCrowdIndex 9

int AG_BULLETS=1;
int AG_LNDMINE=0;

int KeyboardMovement_KeyDown = 380; // down arrow
int KeyboardMovement_KeyLeft = 375; // left arrow
int KeyboardMovement_KeyRight = 377; // right arrow
int KeyboardMovement_KeyUp = 372; // up arrow

KeyboardMovement_Directions KeyboardMovement_CurrentDirection;// = eKeyboardMovement_Stop; // stores current walking direction of player character
KeyboardMovement_Directions newdirection; // declare variable storing new direction

//I must add these to reference and use them outside the module.ash, but... it doesn't work :/
import bool isEven(int n);
import int GetRowRange(int y);
import int GetColRange(int x);
import int IsLeftOf(int x1, int x2);
import int IsUpOf(int y1, int y2);
import String RefFromTile(int x, int y);
import Tile Grid::RandomFreeSquare();
import Tile Grid::TileFromRef(String refName);
import bool IsOverlappingCO(Character *ch, Object *ob);
import bool IsOverlappingCC(Character *ch1, Character *ch2);
import int Crowd::SetNogo(int dir);
import void Crowd::ResetTimers(Crowd *crowd);
import void Crowd::ResetCrowd(Crowd *crowd);
import void Crowd::SetupCrowds();
import void Grid::SetupGridValues();
import void Crowd::FindTargetBasedOnMode(Crowd *crowd, int mode);
import void Crowd::MoveCrowdToTarget(Crowd *crowd);


////////////////////
// ROOM FUNCTIONS //
////////////////////


function room_Load()
{
  Tankman.Enable();
  
	gIconbar.Visible=false;
	
  cTankman.Baseline=768;
  cTankman.SetAsPlayer();
  
  cJulius.x=2000;   //the main character of the game; he's here, but off-screen
  cJulius.y=2000;
  
  AG_playing=true;
  AG_gameover=false;
  
  newdirection=eKeyboardMovement_Up;

  oC0.SetView(322); //set crowd views
  oC1.SetView(322);
  oC2.SetView(322);
  oC3.SetView(322);
  oC4.SetView(322);
  
  
}



function room_RepExec()
{
  
    //control tank - set joystick according to direction
    if (IsKeyPressed(KeyboardMovement_KeyDown)) {
      newdirection = eKeyboardMovement_Down; // down arrow
      oJoyStick.Graphic=4122;
      //Display("currdir %d",KeyboardMovement_CurrentDirection);//2
    }
    else if (IsKeyPressed(KeyboardMovement_KeyLeft)) {
      newdirection = eKeyboardMovement_Left; // left arrow
      oJoyStick.Graphic=4124;
      //Display("currdir %d",KeyboardMovement_CurrentDirection);//3
    }
    else if (IsKeyPressed(KeyboardMovement_KeyRight)) {
      newdirection = eKeyboardMovement_Right; // right arrow
      oJoyStick.Graphic=4118;
      //Display("currdir %d",KeyboardMovement_CurrentDirection);//4
    }
    else if (IsKeyPressed(KeyboardMovement_KeyUp)) {
      newdirection = eKeyboardMovement_Up; // up arrow
      oJoyStick.Graphic=4120;
      //Display("currdir %d",KeyboardMovement_CurrentDirection);//5
    }
    
    //check if area in front of tank is a wall
    if (GetWalkableAreaAt(cTankman.x, cTankman.y)!=AG_WALL) {
      switch (newdirection) {
        
        case eKeyboardMovement_Down:
        oJoyStick.Graphic=4122;
          if (GetWalkableAreaAt(cTankman.x, cTankman.y+(DISTANCE))!=AG_WALL) {
            cTankman.Loop=0;
            cTankman.y+=DISTANCE;
          } else {
            newdirection=KeyboardMovement_CurrentDirection;
          }
          break;
      
        case eKeyboardMovement_Left:
        oJoyStick.Graphic=4124;
          if (GetWalkableAreaAt(cTankman.x-(DISTANCE), cTankman.y)!=AG_WALL) {
            cTankman.Loop=1;
            cTankman.x-=DISTANCE;
          } else {
            newdirection=KeyboardMovement_CurrentDirection;
          }
          break;
          
        case eKeyboardMovement_Right:
        oJoyStick.Graphic=4118;
          if (GetWalkableAreaAt(cTankman.x+(DISTANCE), cTankman.y)!=AG_WALL) {
            cTankman.Loop=2;
            cTankman.x+=DISTANCE;
          } else {
            newdirection=KeyboardMovement_CurrentDirection;
          }
          break;
        
        case eKeyboardMovement_Up:
        oJoyStick.Graphic=4120;
          if (GetWalkableAreaAt(cTankman.x, cTankman.y-(DISTANCE))!=AG_WALL) {
            cTankman.Loop=3;
            cTankman.y-=DISTANCE;
          } else {
            newdirection=KeyboardMovement_CurrentDirection;
          }
          break;
      }//switch
    }//if
  
    // update current direction to new direction
    KeyboardMovement_CurrentDirection = newdirection;
  
}


Basically, I'm making a Pacman clone game, called Tankman. I want to store Tankman as a module, and then a room I can 'import' it into and use the objects/art/etc. to create the final working game. Perhaps I should just fit it in 1 room?..
#76
I have, in Tankman.ash (trying to make my own Pacman clone):

Code: ags

...

struct Crowd {
  int aX;     //actual x eg. 312
  int aY;     //actual y eg. 472
  int tX;     //target x - target char/tile x coord - '3' for 'tile 34'
  int tY;     //target y - target char/tile y coord - '4' for 'tile 34'
  
  int mode;   //mode, 0=chase, attack=1, scatter=2, scared=3, regen=4
  int timer1; //timer to stay in mode
  int timer2; //timer to stay aggressive
  int waittimer;  //timer for wait between attacks/cooldown time
  int dir;    //0=up, 1=right, 2=down, 3=left  Never Eat Soggy Wheatbix
  int nogo;   //opposite direction to where your pointed; dir/nogo 0/2 1/3 2/0 3/1
  int moving; //1=moving to next coord, 0=not moving, decision/action time
  int id;     //0..4
  
  import void SetupCrowds();
  import void ResetCrowd(Crowd *crowd);    <--ERROR!
  import void ResetTimers(Crowd *crowd);
  import void FindTargetBasedOnMode(Crowd *crowd, int mode);
  import void MoveCrowdToTarget(Crowd *crowd);
};


Tankman.ash(17): Error (line 17): Cannot declare pointer to non-managed type

When I take away the '*' pointer, it compiles fine - but it means it sends a copy of Crowd, then loses it. What am I doing wrong to not use pointers?
#77
Khris, could you... show us the code? If only for educational purposes about how to make a dynamic sprite out of a sprite. That is amazing; I was planning to just use a translucent circle under a character as a shadow, that's it.
#78
Wow, is this available in a Module?
#79
Okie doke.
Do you happen to know how I could create an array of structs?
ie:

GlobalScript: (I presume? though game and all variables are in a room...)

Code: ags
struct Grid {
  int x;
  int y;
  String refName;
  bool up;
  bool right;
  bool down;
  bool left;
};

#define numRows  8
#define numCols   10

//10 rows * 8 columns
Grid *theGrid[numRows*numCols];

Grid SetupValues()
{
  theGrid[0].x=0; theGrid[0].y=0; theGrid[0].refName="00"; theGrid[0].up=0; theGrid[0].right=1; theGrid[0].down=0; theGrid[0].left=1; //0,0
  theGrid[1].x=0; theGrid[1].y=0; theGrid[1].refName="01"; theGrid[1].up=1; theGrid[1].right=1; theGrid[1].down=0; theGrid[1].left=1; //0,1
  ......
}

Grid* XYToIndex(int x, int y)
{
  //note for ref 52, x=5, y=2
  return theGrid[y*numRows+x];
}


function IndexToXY(int i)
{
  return theGrid[(i % numCols)*(i / numCols)];
}



ps my grid is of the form:
50px square each grid reference

00 01 02 03 04 05 06 07 08 09
10 11 12 13 14 15 16 17 18 19
20 21 22 ....

corresponding to 50px x 50px squares of the graphical map.

So... does the above make any sense in logic or syntax? I'm flying blind but trying.
#80
This instantly makes sense, thank you :)
SMF spam blocked by CleanTalk