ALARM 2
if not instance_exists(self)
{
instance_destroy()
instance_create(x,y,objonerupee)
}
(^I know that this is awful and does not work )
Okay this won't work. As Martijn said it won't be executed, because he does not exist anymore. If you want to place a ruppee instance, where octorok instance was, you should do this in the DESTROY event, of the octorok.
CREATE
alarm[0]=60
alarm[1]=40
alarm[2]=30
OKTOH=2
image_speed=0.5
I don't see anything wrong with this besides the useless "alarm[2]=30" code. But it does not do anything with the object.
ALARM 0
switch floor(random(6)){ //Pick a random number, make it an integer, and see what it is
case 0:
direction=0 //Right
sprite_index=OktR
image_speed=0.1
speed=floor(2)
break;
case 1:
direction=90 //Up
sprite_index=OktU
image_speed=0.1
speed=floor(2)
break;
case 2:
direction=180 //Left
sprite_index=OktL
image_speed=0.1
speed=floor(2)
break;
case 3:
direction=270 //Down
sprite_index=OktD
image_speed=0.1
speed=floor(2)
break;
case 4:
a=instance_create(x,y,objOKTE);
a.direction=direction
a.speed=4
if direction = 0 //Right
{
sprite_index=OktER
}
if direction = 90 //Up
{
sprite_index=OktEU
}
if direction = 180 //Left
{
sprite_index=OktEL
}
if direction = 270 //Down
{
sprite_index=OktED
}
image_speed=0.05
speed=floor(0)
speed=0
break;
case 5:
a=instance_create(x,y,objOKTE);
a.direction=direction
a.speed=4
if direction = 0 //Right
{
sprite_index=OktER
}
if direction = 90 //Up
{
sprite_index=OktEU
}
if direction = 180 //Left
{
sprite_index=OktEL
}
if direction = 270 //Down
{
sprite_index=OktED
}
image_speed=0.05
speed=floor(0)
break;
}
//Set the speed
speed=floor(random(2)) //Could also be zero, as sometimes the octorocs stop.
//Reset the alarm
alarm[0]=30+random(30)
There are somethings wrong with this, but nothing that causes your problems.
1) speed=floor(2) is the same as speed=2. Taking the floor of a constant numeral value returns the same numeral value. The call to floor() is additional overhead which isn't doing anything. I know GML only uses real value numbers, but it isn't going to add a fraction to it when you don't give it.
2) In case 4 you do this:
speed=floor(0)
speed=0
You are repeating the exact same thing in twice after each other.
3) case 5 and case 4 are exactly the same.
4) After the switch statement you have "speed=floor(random(2))" this invalidates any code that sets the speed inside the switch statements. Therefore you have a bunch of useless statements. Also the speed will always be 0 or 1, resulting that the octorok never gets the speed of 2 what you are trying to do in the switch.
ALARM 1
dif = abs(direction-point_direction(self.x,self.y,objLink.x,objLink.y))
if dif<5 {
a=instance_create(x,y,objOKTE);
a.direction=direction
a.speed=4
speed=0
if direction = 0 //Right
{
sprite_index=OktER
}
if direction = 90 //Up
{
sprite_index=OktEU
}
if direction = 180 //Left
{
sprite_index=OktEL
}
if direction = 270 //Down
{
sprite_index=OktED
}
image_speed=0.05
}
alarm[1]=45+random(45)
Nothing wrong with this, but I wonder if it is necessary and it isn't better paced in the step event.
STEP
if position_meeting(x,y,InvisibleWall or objBush or objRock or objPot or objInvisibleWall or NoEnemy or NoEnemyKlein or objTree or objPalmTree or objHouse or objFountin or objLink ) {speed=0}
if OKTOH <= 0
{ instance_destroy()}
if position_meeting(x,y,objLinkSword) {OKTOH -= 1}
-the movement of the Octorok does not work perfect
-the HP of the Octorok (OKTOH) don't work
-the collision does not work
The movement imperfections are probably due to your code in ALARM 0 event. I saw there that you did "image_speed=0.1". This means that for every 10 gamecycles you change the frame.
The other two errors are due to faulty code in the STEP event.
The collision doesn't work because of the line "if position_meeting(x,y,InvisibleWall or objBush or objRock or objPot or objInvisibleWall or NoEnemy or NoEnemyKlein or objTree or objPalmTree or objHouse or objFountin or objLink )" There are probably two errors in there.
1) I guess in syntax it is okay, but I don't think the boolean expression can't be used as the 3rd argument for position meeting. The boolean expression returns true or false and because there is no object with the objectID (read: not instanceID) of 1 and 0 the if statement is always seen as false and therefore does not execute the things within the if statement.
2) The second problem has to do with the use of position_meeting() instead of place_meeting(). But you probably need to change this to how you want the movement to behave.
3) Well the third problem has more to do with what happens when you solve the collision problem. In your current code you only check the current position and not where the octorok is going. So once it collides with a object it gets stuck. Because its speed is always set to 0 no matter where the object is and in which direction the octorok is going.
The problem with HP has to do with this "if position_meeting(x,y,objLinkSword) {OKTOH -= 1}" Once more the position_meeting() evaluates as false. This has to do with the nature of position_meeting. You should use place_meeting(). Position_meeting only takes the bounding box of objLinkSword into account. To put it simple:Position_meeting evaluates true when the point given by x and y is inside the bounding box of one instance of the requested object.
Place_meeting takes into account the bounding box of both obj and self. To put this simple: Place_Meeting evaluates true, when the origin of self is placed at position given by x and y and the bounding boxes of both the obj and self intersect.
So use place_meeting instead of position_meeting and you should be closer to the solution. I say closer, because I can forsee another behavioral error. You code isn't complete yet. As a hint I'll give you this: Take the position from Link and the octorok towards each other into account and look at the direction Link is facing.
PS: I find it interesting that you use "NoEnemyKlein" as one of the object indicators.