Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075919 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:33:55 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Resetting enemies off-screen
Pages: [1]
Print
Author Topic: Resetting enemies off-screen  (Read 680 times)
Kevin
Level 3
***


I am the reinforcements.


View Profile Email
« on: October 17, 2010, 11:20:09 AM »

Is there a relatively easy way in GM8 to have instances reset to their default positions in a room when not inside the view?

I'm working on an explorationy game that uses a single large room divided into smaller sub-rooms via views. Essentially, one view (view[0]) jumps around the map as the player moves to give the illusion that there are various rooms.

I'd like to have all instances of, say, the enemy object (ob_enemy) revert to their initial settings and positions as the view moves. Like, if you're in room-a, the view is static at given coordinates. If the player moves outside the right-boundary of the view, say, the view jumps 200 pixels to the right to make it seem as though the player has moved into room-b. When this happens, I want all of the enemies in room-a to revert to their initial state and then deactivate, while the enemies in room-b activate and the game continues. If the player moves back into room-a, the view goes back to room-a's coordinates and those enemies reactivate.

This is very poorly and confusingly explained. If anyone has any idea what I'm trying to say, advice would be so, so much appreciated. If no one can decipher it, I'll try to provide more details.
Logged

fraxcell
Level 5
*****



View Profile Email
« Reply #1 on: October 17, 2010, 11:49:23 AM »

Something like this?

Code:

//check if player is outside the view
if obj_player.x<view_xview[0] || obj_player.x>view_xview[0]+view_wview[0]
|| obj_player.y<view_yview[0] || obj_player.y>view_yview[0]+view_hview[0]
{
   //move enemies to original position if they are in the view
   with (ob_enemy){
      if collision_rectangle(view_xview[0],view_yview[0],view_xview[0]+view_wview[0],view_yview[0]+view_hview[0],self,false,false)
      { x=xstart; y=ystart; }
   }

   //deactivate instances in the previous "room"
   instance_deactivate_region(view_xview[0],view_yview[0],view_wview[0],view_hview[0],true,true

//now you move to the next "room"
)
}

I haven't checked it, but theoretically it should work, if I understand what you were trying to say. You'd also have to activate instances in the new room, which I didn't include, but it's the same concept as deactivating the ones in the old room.
Logged

Kevin
Level 3
***


I am the reinforcements.


View Profile Email
« Reply #2 on: October 17, 2010, 11:56:28 AM »

Awesome. I'll be trying this out promptly. I'll let you know how it goes.

Thanks so much!

Edit: That makes so much sense it's embarrassing. Thank you a million times. <3
« Last Edit: October 17, 2010, 01:11:30 PM by Kevin » Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic