Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Request help: Dodongo snake  (Read 1115 times)

0 Members and 1 Guest are viewing this topic.
Request help: Dodongo snake
« on: January 13, 2013, 03:20:59 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 261
Simply put: I have two objects a head objects that has a random movement part in it and a body object that follows the head object, currently using the codes below, but it looks horrible. All suggestions are appriciated.  Its one of the last mini-bosses that are yet uncompleted, I can do 1 object bosses and 1 other 2 object boss without a problem, but this one with the following in it seems to be more then I can do alone.

<a href="http://www.youtube.com/watch?v=82O67egCpuI" target="_blank">http://www.youtube.com/watch?v=82O67egCpuI</a>

Code: [Select]
Information about object: objDodongo1Head
Sprite: sprDodongohead
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Mask:

Create Event:

execute code:

if global.killed1Dmboss=1 {instance_destroy()}
HP=3
eating=0
swollen=0
image_speed=0
alarm[0]=10
alarm[2]=15

Alarm Event for alarm 0:

execute code:

if(!global.pause  ){
switch floor(random(4)){ //Pick a random number, make it an integer, and see what it is
case 0:
direction=360 //Right
image_index=2
break;
case 1:
direction=90 //Up
image_index=3
break;
case 2:
direction=180 //Left
image_index=0
break;
case 3:
direction=270 //Down
image_index=1
break;
}
//Set the speed
switch floor(random(2)){ //Pick a random number, make it an integer, and see what it is
case 0:
speed=0
break;
case 1:
speed=0.5
break;
}
//Reset the alarm
}
alarm[0]=55+random(20)


Alarm Event for alarm 1:

execute code:

image_alpha=1

Step Event:

execute code:

if !place_free(x+1,y) && ( direction=360 or direction = 0 ){speed=0; x=xprevious; y=yprevious}
if !place_free(x,y-1) && direction=90 {speed=0; x=xprevious; y=yprevious}
if !place_free(x-1,y) && direction=180 {speed=0; x=xprevious; y=yprevious}
if !place_free(x,y+1) && direction=270 {speed=0; x=xprevious; y=yprevious}
if(!global.pause){


if HP<=0{
   instance_change(objEDie,true)
}
}

End Step Event:

execute code:

vx = 0 //Set up some placeholders to save space
vw = 160
vy = 32
vh = 158

if (x< vx)
{
x=xprevious
y=yprevious
}

else if ((x+sprite_width) > vx+vw)
{
x=xprevious
y=yprevious
}

else if (y< vy)
{
x=xprevious
y=yprevious
}

else if ((y+sprite_height) > vh)
{
x=xprevious
y=yprevious
}



Code: [Select]
Information about object: objDodongo1body
Sprite: sprDodongobody
Solid: false
Visible: true
Depth: 1
Persistent: false
Parent:
Mask:

Create Event:

execute code:

if global.killed1Dmboss=1 {instance_destroy()}
activated=0
alarm[0]=2

Alarm Event for alarm 0:

execute code:

activated=1

Step Event:

execute code:

targetx=objDodongo1Head.x
targety=objDodongo1Head.y

if activated=1 && objDodongo1Head.speed=.5 && (objDodongo1Head.direction=360 or objDodongo1Head.direction=0)
{
x=targetx-15;y=targety-1;speed=.5
}

if activated=1 && objDodongo1Head.speed=.5 && objDodongo1Head.direction=90
{
x=targetx;y=targety+15;speed=.5
}

if activated=1 && objDodongo1Head.speed=.5 && objDodongo1Head.direction=180
{
x=targetx+15;y=targety-1;speed=.5
}

if activated=1 && objDodongo1Head.speed=.5 && objDodongo1Head.direction=270
{
x=targetx;y=targety-16;speed=.5
}

if activated=1 && objDodongo1Head.speed=0
{
move_towards_point(objDodongo1Head.x,objDodongo1Head.y,0.5)
}

if activated=1 && self.x=objDodongo1Head.x && self.y=objDodongo1Head.y
{
speed=0
activated=0
}

if activated=0 && objDodongo1Head.speed=0.5
{
alarm[0]=3
}


//direction=360 //Right
//direction=90 //Up
//direction=180 //Left
//direction=270 //Down

End Step Event:

execute code:

vx = 0 //Set up some placeholders to save space
vw = 160
vy = 32
vh = 158

if (x< vx)
{
x=xprevious
y=yprevious
}

else if ((x+sprite_width) > vx+vw)
{
x=xprevious
y=yprevious
}

else if (y< vy)
{
x=xprevious
y=yprevious
}

else if ((y+sprite_height) > vh)
{
x=xprevious
y=yprevious
}

Logged
TLOZ: Chaos Rising
http://www.zfgc.com/forum/index.php?topic=37003.0

Current project: attempting to write a fantasy novel ( in dutch )
Re: Request help: Dodongo snake
« Reply #1 on: January 13, 2013, 08:05:39 pm »
  • *
  • Reputation: +12/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1247
Going through the coding is a pain, but maybe I can help with the general concept.
If you remove the tail, does the head function like you want it to?
Logged
Still working on my Alttp-engine: http://www.zfgc.com/forum/index.php?topic=33701.0
Want to help out in whatever way you are talented? Send me a PM.
Re: Request help: Dodongo snake
« Reply #2 on: January 13, 2013, 08:31:07 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 261
Sorry, I'm not used to commenting my code and most likely things could have been done more efficiently.

about the head functions: not yet completely as i want but thats some change in the movement speed and the alarm that changes the times between directions. But yes if not taking the above things in consideration the head moves correctley without the tail object.
Logged
TLOZ: Chaos Rising
http://www.zfgc.com/forum/index.php?topic=37003.0

Current project: attempting to write a fantasy novel ( in dutch )
Re: Request help: Dodongo snake
« Reply #3 on: January 13, 2013, 08:52:29 pm »
  • *
  • Reputation: +12/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1247
Okay. Then you'll want to have the tail object follow the head without interfering with the AI or movement script of that head. Is that the case in your engine? Can enemy objects move through each other without interfering?

How do you want the tail to follow btw? If you move the head in a direction, should it stops and waits for the tail to catch up? Or do you have something else in mind?
Logged
Still working on my Alttp-engine: http://www.zfgc.com/forum/index.php?topic=33701.0
Want to help out in whatever way you are talented? Send me a PM.
Re: Request help: Dodongo snake
« Reply #4 on: January 13, 2013, 09:21:49 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 261
yes, the body can move underneath the head without interfering with it. Its indeed to follow the head its movement. The tail only has to catch up when the head goes to movement speed 0, this should happen random only and not every time it changes direction.
Logged
TLOZ: Chaos Rising
http://www.zfgc.com/forum/index.php?topic=37003.0

Current project: attempting to write a fantasy novel ( in dutch )
Re: Request help: Dodongo snake
« Reply #5 on: January 13, 2013, 09:31:52 pm »
  • *
  • Reputation: +12/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1247
Why not give the tail some simple instructions (to be perform every step) like so:

Code: [Select]
movement_speed = 0;

If (head.x < x then) {var1 = left; var2 = abs(head.x-x)}
else if (head.y < y then) {var1 = up; var2 = abs(head.y-y)}
else if (head.x > x then) {var1 = right; var2 = abs(head.x-x)}
else if (head y > y then) {var1 = down; var2 = abs(head.y-y)}

movement direction = var1;
movement speed = min(var2, 1);

I don't think you have to make it any more complicated then that (aside from catching pause mode and the boss being killed of course). Try it out and see what happens. I'm assuming the head moves at a faster speed then 1 so I figured the tail should move a little slower to get that "getting up" effect. Just tweak it to your own preference.
« Last Edit: January 13, 2013, 09:33:26 pm by Martijn dh »
Logged
Still working on my Alttp-engine: http://www.zfgc.com/forum/index.php?topic=33701.0
Want to help out in whatever way you are talented? Send me a PM.
Re: Request help: Dodongo snake
« Reply #6 on: January 13, 2013, 09:38:26 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 261
thank you, I will try this out as soon as I have time to work on it again ( in a few days ) for now I'm off to sleep.
A good night to all
Logged
TLOZ: Chaos Rising
http://www.zfgc.com/forum/index.php?topic=37003.0

Current project: attempting to write a fantasy novel ( in dutch )
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.079 seconds with 34 queries.

anything