Radar Quesion

Started by jamesreg, Sun 10/02/2019 14:48:02

Previous topic - Next topic

jamesreg

I have a radar gui on screen with two buttons

BEnemy1 is the npc enemy character moving around randomly on screen
BGreenDot is a button that is meant to be my location.

I have the mouse set to center of screen as a target cursor in a scrolling room
The radar shows BEnemy1 moving around as he is supposed to

But I am having problems with it not showing my position.

Note: The button tries to move but just is jumpy in the same location does not switch like it is supposed to

Here is my code for the radar

Code: ags
BEnemy1.X = cEnemy1.x/75  + (BEnemy1.Width) / 5;
  BEnemy1.Y = cEnemy1.y/80  + (BEnemy1.Width) / 5;
  
  bGreenDot.X = mouse.x/75 + (BEnemy1.Width) /5;
  bGreenDot.X=  mouse.y/75 + (BEnemy1.Width) /5;


And in case anyone wants to know or it will help here is my entire room code incase something else is messing it up like my setting the mouse to center of screen or something.

Code: ags
// room script file

//Functions
bool modeWasFlipped;
  function Nav_Mode () 
{
 
  Bridge_Battle=true;
  mouse.Visible=false;
 gTargetCursor.Visible=true;
  gTargetCursor.Centre();
  //cEgo.Transparency=100;
  cEgo.Transparency=0;
  mouse.Mode=eModeInteract;
  gGui1.Visible=true;
  
}
  
function Cursor_Mode ()
{
 
  Bridge_Battle=false;
  Mouse.Mode=eModePointer;
  mouse.Visible=true;
  gTargetCursor.Visible=false;
  cEgo.Transparency=100;
}

int centerX, centerY,  wrapWidth=1, wrapHeight=1, viewportX, viewportY;
//BEFORE ROOM LOAD SCRIPTS
function room_Load()
{
  
 BattleMode=true;
 mouse.Mode=eModeInteract;
  Nav_Mode();
  
  // Just calculate some useful values:
  
  centerX = System.ViewportWidth/2;
  centerY = System.ViewportHeight/2;
   wrapWidth = Room.Width - System.ViewportWidth;
   wrapHeight = Room.Height - System.ViewportHeight;
 }
 
// Moved all the stuff to do with the battle into its own function, to keep things tidy
void updateBattle()
{
  // TODO: Update ships and stuff
  mouse.Update(); // This makes sure we get the most up-to-date mouse coordinates
  // Calculate viewport scrolling
  int moveX = mouse.x - centerX;
  int moveY = mouse.y - centerY;
 
  // Move viewport, wrapping around
  viewportX = (viewportX + moveX + wrapWidth) % wrapWidth;
  viewportY = (viewportY + moveY + wrapWidth) % wrapWidth;
  SetViewport(viewportX, viewportY);
  mouse.SetPosition(centerX, centerY);
}


//scripts that repeatedly fire
function room_RepExec() {
  if (cEnemy1.Room == 2) {
   if (cEnemy1.Moving == false) {
     cEnemy1.Walk(Random(Room.Width), Random(Room.Height));
  }
}

 ///RADAR Enemy 1
  BEnemy1.X = cEnemy1.x/75  + (BEnemy1.Width) / 5;
  BEnemy1.Y = cEnemy1.y/80  + (BEnemy1.Width) / 5;
  
  bGreenDot.X = mouse.x/75 + (BEnemy1.Width) /5;
  bGreenDot.X=  mouse.y/75 + (BEnemy1.Width) /5;
 
 //lOCK Mouse to follow mouse
 cEgo.x = mouse.x;
 cEgo.y = mouse.y;
 

  
  
    

  // Testing script to exit game 
 
  
 //Hot ket to find enemy
if (IsKeyPressed(eKeyT)){
    SetViewport(cEgo.x, cEgo.y);
  }
 
  if (IsKeyPressed(eKeyEscape)) {
    QuitGame(0);
  }
  //End of Testing Script  
 
  if(IsKeyPressed(eKeyZ))
  {
    // We only switch mode if we haven't already done so during this keypress
    if(modeWasFlipped == false) // another way to write this is just: if(!modeWasFlipped)
    {
      if(Bridge_Battle == true)  // or just: if(Bridge_Battle)
        Cursor_Mode();
      else
        Nav_Mode();
 
      modeWasFlipped = true; // We've switched mode, so set the flag
    }
  } // End: IsKeyPressed(eKeyZ)
  else // the key is released, so we reset the flag
    modeWasFlipped = false;
 
  if(Bridge_Battle == true) // Same: if(Bridge_Battle)
    updateBattle();
}



Matti

I think in line 5 it's supposed to be bGreenDot.Y:

Code: ags

bGreenDot.X = mouse.x/75 + (BEnemy1.Width) /5;
bGreenDot.Y = mouse.y/75 + (BEnemy1.Width) /5;


jamesreg

#2
Code: ags
BEnemy1.X = cEnemy1.x/75  + (BEnemy1.Width) / 5;
  BEnemy1.Y = cEnemy1.y/80  + (BEnemy1.Width) / 5;
  
  bGreenDot.X = mouse.x/75 + (bGreenDot.Width) / 5;
  bGreenDot.Y =  mouse.y/80 + (bGreenDot.Width) / 5;

I fixed the errors of having the wrong button listed in script but it still will not show my movements the code for the enemy movement works perfectly. I thought if I used the same code for where my mouse was at it would do the same thing but it does not. Could it have anything to do with me having the mouse in the center of the screen and constantly having it stay there?

Also the /75 and the /80 and /5 I really do not know if those numbers are what I need I just put numbers in there until my enemy radar showed the correct location.

It is showing me in the right location but when i move the radar button just shakes a bit but does not move like the enemy blip does

SMF spam blocked by CleanTalk