Jump to content


Photo

Spawning the enemies


  • Please log in to reply
10 replies to this topic

#1 codmaker

codmaker

    GMC Member

  • New Member
  • 18 posts
  • Version:GM8

Posted 05 July 2012 - 04:29 PM

Hi I am trying to do a spawn system that when a player dies(there are 8 players) he jumps_to_position randomly to 1 of 3 differents ones
Spawn1:1712x722y
Spawn2:672x1744y
Spawn3:864x384y
Also If there is a collision with a player in that position, he has to spawn the nearest positon to the spawn without colliding with the player.

Thank you for reading and helping. You'll be in Credits!
  • 0

#2 HerpDerp

HerpDerp

    GMC Member

  • New Member
  • 215 posts
  • Version:GM8

Posted 06 July 2012 - 09:21 AM

You could use the random function on create-event of the player object.

Player CREATE-event:

//Set variable. Round means it rounds the number up or down, depending on the closest integer.
//NOTE: random(3) will never return 3, unless you use the "ceil" - function instead of "round".
SpawningPosition=round(random(3))

//Spawn code:
if SpawningPosition=0
 {
 if place_free(1712, 722) //You could also use collision_point(1712, 722, obj_player, true, true) to define a
  {			  //specific object to check at the coordinates, in case there are other objects.
  x=1712
  y=722
  }
 else
  {
  x=1712+sprite_width
  y=722+sprite_width
  }
 }

if SpawningPosition=1
 {
 if place_free(672, 1744)
  {
  x=672
  y=1744
  }
 else
  {
  x=672+sprite_width
  y=1744+sprite_width
  }
 }

if SpawningPosition=2
 {
 if place_free(864, 384)
  {
  x=864
  y=384
  }
 else
  {
  x=864+sprite_width
  y=384+sprite_width
  }
 }

This code is pretty simple. If you run into trouble let me know ;).

Edited by HerpDerp, 06 July 2012 - 09:42 AM.

  • 0

#3 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 06 July 2012 - 11:18 AM

EDIT: Whops, to slow :tongue:

Create event:
spawn_v[0, 0] = 1712
spawn_v[0, 1] = 722
spawn_v[1, 0] = 672
spawn_v[1, 1] = 1744
spawn_v[2, 0] = 864
spawn_v[2, 1] = 384

Spawn event:
spawn = irandom(2)

var tx, ty;
tx = spawn_v[spawn, 0]
ty = spawn_v[spawn, 1]

while (place_meeting(tx, ty, obj_player))
{
tx += lengthdir_x(10, random(360))
ty += lengthdir_y(10, random(360))
}
x = tx
y = ty

Edited by filulilus, 06 July 2012 - 11:19 AM.

  • 0

#4 codmaker

codmaker

    GMC Member

  • New Member
  • 18 posts
  • Version:GM8

Posted 06 July 2012 - 01:29 PM

Thank you both of you, you are in credits now!
Can you help me with this?

How can i make an object stay at same view position??

Edited by codmaker, 06 July 2012 - 01:32 PM.

  • 0

#5 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 06 July 2012 - 01:45 PM

How can i make an object stay at same view position??

You mean you like the view to follow an object?

You can simply set that in the room editor at the view tab! :thumbsup:

...or use this code... :tongue:

view_xview[0] = obj_player.x - view_wview[0] / 2
view_yview[0] = obj_player.y - view_hview[0] / 2



or did you mean an object to follow the view, like an UI?

x = view_xview[0]
y = view_yview[0]

draw_text(x + 10, y + 10, 'AMAGAD! TEXT IN THE VIEW CORNER!'

Edited by filulilus, 06 July 2012 - 01:46 PM.

  • 0

#6 codmaker

codmaker

    GMC Member

  • New Member
  • 18 posts
  • Version:GM8

Posted 06 July 2012 - 01:52 PM

Thank you, but what I am asking is: I have an object that has apeared in a random position of the room, but now we can see it in the view(obiously if the camera moves the object will get out of the view) i want to get his create xview and yview and make it persistent in the points of the view

Thank you for trying to help,my english is not the best :)

Edited by codmaker, 06 July 2012 - 01:53 PM.

  • 0

#7 HerpDerp

HerpDerp

    GMC Member

  • New Member
  • 215 posts
  • Version:GM8

Posted 06 July 2012 - 01:53 PM


How can i make an object stay at same view position??

You mean you like the view to follow an object?

You can simply set that in the room editor at the view tab! :thumbsup:

...or use this code... :tongue:

view_xview[0] = obj_player.x - view_wview[0] / 2
view_yview[0] = obj_player.y - view_hview[0] / 2



or did you mean an object to follow the view, like an UI?

x = view_xview[0]
y = view_yview[0]

draw_text(x + 10, y + 10, 'AMAGAD! TEXT IN THE VIEW CORNER!'


^ Lolled there.
  • 0

#8 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 06 July 2012 - 01:59 PM

Thank you, but what I am asking is: I have an object that has apeared in a random position of the room, but now we can see it in the view(obiously if the camera moves the object will get out of the view) i want to get his create xview and yview and make it persistent in the points of the view


I'm sorry but I don't understand the question, the only thing I can think of (other then what I've already posted) is that the player will be spawning inside the view? :confused:
  • 0

#9 codmaker

codmaker

    GMC Member

  • New Member
  • 18 posts
  • Version:GM8

Posted 06 July 2012 - 02:13 PM

I created obj_uav on a random position of view1 examle: view_xview+100, view_yview+80... the problem is that i don't know his view coordinates.
I want the object to stay in those view coordinates, even my player moves(my camera follows this object)
  • 0

#10 filulilus

filulilus

    GMC Member

  • GMC Member
  • 928 posts
  • Version:GM:Studio

Posted 06 July 2012 - 02:19 PM

Oooooooooooooooooooooh.... now I see!

You like an object to stay inside the view like he is a member of the players team? :happy:

The view varaibles like "view_xview[0]" are global variables which mean they can be accesed by any object! :thumbsup:

if x < view_xview[0]
{
//no no no, go back they way you came from!
x += 10
//or
hspeed = -hspeed
//or some other turn code...
}

if x > view_xview[0] + view_hview[0]
{
//no no no, go back they way you came from!
x -= 10
//or
hspeed = -hspeed
//or some other turn code...
}

  • 0

#11 HerpDerp

HerpDerp

    GMC Member

  • New Member
  • 215 posts
  • Version:GM8

Posted 06 July 2012 - 02:23 PM

EDIT: Too slow once more, ignore this post :D

Edited by HerpDerp, 06 July 2012 - 02:45 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users