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: Stalfos  (Read 1617 times)

0 Members and 1 Guest are viewing this topic.
Stalfos
« on: December 30, 2011, 09:30:06 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 262
So I've finished creating all of my basic enemies and have spend the last few weeks bug fixing and improving some AI. The original Stalfos I made did not have the jumping towards link's position ability so I've been working on a new stalfos.  Unfortunately I seem to have messed up my Stalfos codes. It goes in jump action, but except for the sprite change it doesnt work that well, most off the time the Stalfos doesn't even move.
For now its supposed to change sprite and then move towards the link object ( with changed sprite ) in a lineair movement, stopped by the mail solid (parent) object. ( making it look like it moves a bit up is something to work on after the code below is fixed. ) Its the last part of the enemie creation & debugging stage the game is in, so it would be nice if I could get help, finish it and move on to the next part of the project.

Code: [Select]
Information about object: obj_StalfosG
Sprite: sprStalfosG
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent: objHurt2
Mask:

Create Event:

execute code:

HP=3
stunned=0
jumping=0
jumpcountdown=0
image_speed=0
targetx=x
targety=y
alarm[0]=random(10)

Alarm Event for alarm 0:

execute code:

if(!global.pause && !stunned && !jumping){
switch floor(random(4)){ //Pick a random number, make it an integer, and see what it is
case 0:
direction=360 //Right
sprite_index=sprStalfosG
break;
case 1:
direction=90 //Up
sprite_index=sprStalfosG
break;
case 2:
direction=180 //Left
sprite_index=sprStalfosG
break;
case 3:
direction=270 //Down
sprite_index=sprStalfosG
break;
}
//Set the speed
switch floor(random(3)){ //Could also be zero, as sometimes the Stalfos stop.
case 0:
speed=1
break;
case 1:
speed=.75
break;
case 2:
speed=0
break;
//Reset the alarm
}}
alarm[0]=15+random(15)
if(stunned){
    stunned=0
}

Alarm Event for alarm 1:

execute code:

image_alpha=1

Alarm Event for alarm 2:

execute code:

image_blend=c_white

Alarm Event for alarm 3:

execute code:

//counting down till a new jump can happen
if jumpcountdown>0
{
jumpcountdown-=1
alarm[3]=1
}

Alarm Event for alarm 4:

execute code:

if(!global.pause){

mp_linear_step_object(obj_link.x,obj_link.y,distance_to_object(obj_link),objDense)
targetx=obj_link.x
targety=obj_link.y
sprite_index=sprStalfosGj
}

if(global.pause){ alarm[4]=10}

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(speed){
    image_speed=0.3
}
else{
    image_speed=0
}
if place_meeting(x,y,obj_link) && obj_link.usingshield{
    if global.facing="U"{
        sound_play(Bump)
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if global.facing="D"{
        sound_play(Bump)
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if global.facing="R"{
        sound_play(Bump)
        if(place_free(x-5,y)){
            x+=5
        }
    }
    if global.facing="L"{
        sound_play(Bump)
        if(place_free(x+5,y)){
            x-=5
        }
    }
}
if place_meeting(x,y,objFirerod) or place_meeting(x,y,objIcerod) or place_meeting(x,y,objMRod) && (image_alpha=1 or stunned )&& !jumping {
    sound_play(EHit)
    HP-=1
    image_alpha=0.75
    alarm[1]=10
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
}
if place_meeting(x,y,objFire) or place_meeting(x,y,objWind)or place_meeting(x,y,Arrow) or place_meeting(x,y,objfirer) or place_meeting(x,y,objHammer)or place_meeting(x,y,objSwordshoot) && (image_alpha=1 or stunned )&& !jumping {
    sound_play(EHit)
    HP-=2
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}
}
if place_meeting(x,y,Explosion) && (image_alpha=1 or stunned ){
    sound_play(EHit)
    HP-=3
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}

if place_meeting(x,y,objicer) && !stunned && !jumping {
    sound_play(EHit)
    instance_create(self.x,self.y,objChink)
    stunned=1
    speed=0
    image_speed=0
    image_blend=c_blue-150
    alarm[0]=180
    alarm[2]=180
}

if place_meeting(x,y,objBoomerang) && global.boomerlvl=1 && !stunned && !jumping{
    sound_play(EHit)
    instance_create(self.x,self.y,objChink)
    stunned=1
    speed=0
    image_speed=0
    image_alpha=0.8
    alarm[0]=90
    alarm[1]=90
}

if place_meeting(x,y,objBoomerang) && global.boomerlvl=2 && !stunned && !jumping{
    sound_play(EHit)
    HP-=1
    instance_create(self.x,self.y,objChink)
    stunned=1
    speed=0
    image_speed=0
    image_alpha=0.7
    alarm[0]=120
    alarm[1]=120
}
if HP<=0{
   instance_change(objEDie,true)
}

execute code:

if !jumping{
if place_meeting(x,y,objSword) or place_meeting(x,y,objSwordCharge) && global.swordlvl=1 && (image_alpha=1 or stunned ){
    sound_play(EHit)
    HP-=1
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}

if place_meeting(x,y,objSwordSpin) && global.swordlvl=1 && (image_alpha=1 or stunned ){
    sound_play(EHit)
    HP-=2
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}

if place_meeting(x,y,objSword) && global.swordlvl=2 && (image_alpha=1 or stunned ){
    sound_play(EHit)
    HP-=2
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}

if place_meeting(x,y,objSwordSpin) && global.swordlvl=2 && (image_alpha=1 or stunned ){
    sound_play(EHit)
    HP-=4
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}

if place_meeting(x,y,objSwordCharge) && global.swordlvl=2 && (image_alpha=1 or stunned ){
    sound_play(EHit)
    HP-=3
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}

if place_meeting(x,y,objSwordCharge) && global.swordlvl=3 && (image_alpha=1 or stunned ){
    sound_play(EHit)
    HP-=5
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}

if place_meeting(x,y,objSwordSpin) && global.swordlvl=3 && (image_alpha=1 or stunned ){
    sound_play(EHit)
    HP-=7
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}

if place_meeting(x,y,objSword) && global.swordlvl=3 && (image_alpha=1 or stunned ){
    sound_play(EHit)
    HP-=4
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction =0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    image_alpha=0.75
    alarm[1]=10
}
}

execute code:

if !stunned && jumping && image_alpha=1
{
   if direction=90 && place_meeting(x,y-1,objdeepwater) or place_meeting(x,y-1,objlava)or place_meeting(x,y-3,objHole)or place_meeting(x,y-1,objHole2){
       y+=2
       direction=270
            alarm[0]=10
            sprite_index=sprStalfosG
        }
   
    if direction=270 && place_meeting(x,y+1,objdeepwater)or place_meeting(x,y+1,objlava)or place_meeting(x,y+1,objHole)or place_meeting(x,y+1,objHole2) {
          y-=2
          alarm[0]=10
          direction=90
          sprite_index=sprStalfosG
        }
 
    if direction=360 or direction=0 && place_meeting(x+1,y,objdeepwater)or place_meeting(x+1,y,objlava)or place_meeting(x+1,y,objHole)or place_meeting(x+1,y,objHole2){
        x-=2
          alarm[0]=10
          direction=180
          sprite_index=sprStalfosG
        }
 
    if direction=180 && place_meeting(x-1,y,objdeepwater) or place_meeting(x-1,y,objlava)or place_meeting(x-1,y,objHole)or place_meeting(x-1,y,objHole2) {
       x+=2
            alarm[0]=10
            direction=360
            sprite_index=sprStalfosG
        }

}

execute code:

if stunned or image_alpha<=1 &&  !jumping
{
   if direction=90 && place_meeting(x,y-1,objdeepwater)or place_meeting(x,y-1,objlava) {
         x=other.x
        y=other.y 
          instance_change(objDrown,true)
        }
   
    if direction=270 && place_meeting(x,y+1,objdeepwater) or place_meeting(x,y+1,objlava) {
       x=other.x
        y=other.y 
        instance_change(objDrown,true)
        }
 
    if direction=360 or direction=0 && place_meeting(x+1,y,objdeepwater) or place_meeting(x+1,y,objlava){
      x=other.x
        y=other.y 
   instance_change(objDrown,true)
        }
 
    if direction=180 && place_meeting(x-1,y,objdeepwater) or place_meeting(x-1,y,objlava) {
       x=other.x
        y=other.y 
  instance_change(objDrown,true)
        }


       
       
        if direction=90 && place_meeting(x,y-3,objHole)or place_meeting(x,y-1,objHole2){
           x=other.x
        y=other.y 
        instance_change(objDrop,true)
        }
   
    if direction=270 && place_meeting(x,y+1,objHole)or place_meeting(x,y+1,objHole2) {
       x=other.x
        y=other.y 
           instance_change(objDrop,true)
        }
 
    if direction=360 or direction=0 && place_meeting(x+1,y,objHole)or place_meeting(x+1,y,objHole2){
       x=other.x
        y=other.y 
         instance_change(objDrop,true)
        }
 
    if direction=180 && place_meeting(x-1,y,objHole)or place_meeting(x-1,y,objHole2) {
       x=other.x
        y=other.y 
        instance_change(objDrop,true)
        }
}


 


   

execute code:

//initiate attack

if distance_to_object(obj_link)<33 && jumping=0 && jumpcountdown=0
{
jumping=1
alarm[4]=3
}

//switch from jump status to normal walking

if jumping=1 && x=targetx && y=targety
{
jumpcountdown=120
alarm[3]=1
jumping=0
alarm[0]=5
}

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
}

Collision Event with object objMagic:

execute code:


    sound_play(EHit)
    HP-=2
    if direction=90{
        if(place_free(x,y+5)){
            y+=5
        }
    }
    if direction=270{
        if(place_free(x,y-5)){
            y-=5
        }
    }
    if direction=360 or direction=0{
        if(place_free(x-5,y)){
            x-=5
        }
    }
    if direction=180{
        if(place_free(x+5,y)){
            x+=5
        }
    }
    with other{instance_destroy()}


Logged
Pages: [1]   Go Up

 


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



Page created in 0.658 seconds with 39 queries.