Hello Everyone :) ,
Im trying to create an enemy, and i have a few randomisers which work surprisingly well :) however, i have 2 major issues with this.
1. i have some platforms on which the enemies walk, but i need them to turn back when they are on the edge. i might be able to make this work BUT my enemy has to be able to make some random jump, and not turn.
2. ( the biggest problem) I have a few randomisers, ;
- 1 , Determine howlong a random action is performed ( idle, walking left or right.)
- 2 , which action it will perform.
This works fine ! :) however, when let's say moveRight(); is called in the switch, it will only work for one "act", and it will move a few pixels instead of keeping the moveRight active unless it's told otherwise.
When my game is done , i will be happy to post it :) ..
And im just starting with greenfoot / programming in general, so please :) not too technical with the explanations !
And ofcourse to clear up, here's my code;
Thank you in advance :) , yes, you !
i Really hope you guys can help me out :) ! !
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class RibbonPig here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class RibbonPig extends Mob
{
private int richting = 1;
private int speed = 4;
//Behaviour
private int richtingRandomiser = 1;
public int behaviourTimer = 10;
public int actionRandomiser = 1;
/**
* SPRITES INLADEN
**/
//Idle left
GreenfootImage[] idleLeft = new GreenfootImage[]
{
new GreenfootImage("ribbonPig_left_stand_0.png"),
new GreenfootImage("ribbonPig_left_stand_1.png"),
new GreenfootImage("ribbonPig_left_stand_2.png")
};
//Idle right
GreenfootImage[] idleRight = new GreenfootImage[]
{
new GreenfootImage("ribbonPig_right_stand_0.png"),
new GreenfootImage("ribbonPig_right_stand_1.png"),
new GreenfootImage("ribbonPig_right_stand_2.png")
};
//Naar links lopen
GreenfootImage[] animateLeft = new GreenfootImage[]
{
new GreenfootImage("ribbonPig_left_move_0.png"),
new GreenfootImage("ribbonPig_left_move_1.png"),
new GreenfootImage("ribbonPig_left_move_2.png")
};
//naar Rechts lopen
GreenfootImage[] animateRight = new GreenfootImage[]
{
new GreenfootImage("ribbonPig_right_move_0.png"),
new GreenfootImage("ribbonPig_right_move_1.png"),
new GreenfootImage("ribbonPig_right_move_2.png")
};
/**
* Act - do whatever the RibbonPig wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
super.checkFall();
super.timer();
animate(sequence);
checkTimer(behaviourTimer);
behaviourTimer--;
System.out.println("Behaviour Timer = " + behaviourTimer);
System.out.println("sequence = " + sequence);
System.out.println("Speed = " + speed);
System.out.println("Richting = " + richting);
System.out.println("Swtich = " + actionRandomiser);
}
public void animate(int sequence) {
switch(sequence)
{
case 0:
idle(richting);
break;
case 1:
animateLeft();
break;
case 2:
animateRight();
break;
default:
break;
}
}
/*************
*Richting Checker
**********/
private void idle(int richting)
{
if(richting == 1)
{
animateIdleLeft();
}
if (richting == 2)
{
animateIdleRight();
}
}
/*************
*
*
*
*
*ANIMATIONS
*
*
*
**********/
public void animateIdleLeft()
{
if(frame == 1)
{
setImage(idleLeft[0]);
}
else if (frame == 2)
{
setImage(idleLeft[1]);
}
else if(frame == 3)
{
setImage(idleLeft[2]);
frame = 0;
return;
}
}
public void animateIdleRight()
{
if(frame == 1)
{
setImage(idleRight[0]);
}
else if (frame == 2)
{
setImage(idleRight[1]);
}
else if(frame == 3)
{
setImage(idleRight[2]);
frame = 0;
return;
}
}
public void animateRight()
{
if(frame == 1)
{
setImage(animateRight[0]);
}
else if (frame == 2)
{
setImage(animateRight[1]);
}
else if(frame == 3)
{
setImage(animateRight[2]);
frame = 0;
return;
}
}
public void animateLeft()
{
if(frame == 1)
{
setImage(animateLeft[0]);
}
else if (frame == 2)
{
setImage(animateLeft[1]);
}
else if(frame == 3)
{
setImage(animateLeft[2]);
frame = 0;
return;
}
}
/*************
*
*
*
*
*BEHAVIOUR
*
*
*
**********/
public void checkTimer(int behaviourTimer)
{
if(behaviourTimer == 0)
{
behaviourTimer();
}
}
public void behaviourTimer()
{
behaviourTimer = Greenfoot.getRandomNumber(50) + 10;
actionRandomiser = Greenfoot.getRandomNumber(3);
actionRandomiser(behaviourTimer, actionRandomiser);
}
public void actionRandomiser(int behaviourTimer, int actionRandomiser)
{
switch (actionRandomiser)
{
case 0:
speed = 0;
sequence = 0;
break;
case 1:
speed = 4;
sequence = 2;
moveRight();
richting = 2;
break;
case 2:
speed = 4;
sequence = 1;
moveLeft();
richting = 1;
break;
}
}
public void moveRight()
{
setLocation(getX()+speed, getY());
}
public void moveLeft()
{
setLocation(getX()-speed, getY());
}
}


my platform does not recognize the speed variable, i feel like there is missing a link between my piglets and my platform class.
The following code is placed in my Platform, which does nothing at this moment.