mob creeper;//creates the name for a new mob
void setup(){
size(700,500,P3D);
//IT IS IMPOSSIBLE TO RUN THIS CODE DIRECTLY FROM YOUR PROCESSING WINDOW
//UNLESS YOU KNOW HOW TO CREATE A DATA FOLDER AND PUT AN IMAGE IN IT.
//otherwise enjoy playing with this on the web :)
creeper=new mob(loadImage("creeper.png"));//creates the mob called creeper
noStroke();
}
void draw(){
background(50,50,225);
lights();//makes some lights
fill(200,0,200);
Platform(width/2,400,0, 700,100,creeper);//places a platform
Pointer();//places a sphere on the platform
fill(0,200,0);
Creeper(350, 270, 100);// places a creeper
// I was trying to get two creepers to run simultaiously but failed
// Creeper(300 ,270 ,300);
collider(width/2,1000,0, 7000,100,creeper);//places a collider
}
void Creeper(float X, float Y,float Z){// a function that puts together the mob
pushMatrix();
creeper.Entity(X,Y,Z,100,30);
creeper.follow(2,mouseX,mouseY*2-height-200);
creeper.isTextured(false);// change the false in here to true to get a very buggy texture applied
translate(0,-16);
creeper.Texture(16,16, 24,16);// sets texture cordinats
creeper.Block(0,-20,0, 24,36,12);//body
// head
creeper.Texture(0,0, 32,16);
creeper.Block(0,-12-36,0, 24,24,24);
//legs
creeper.Texture(0,16, 16,8);
creeper.Block(6,6,12, 12,16,12);
creeper.Block(-6,6,12, 12,16,12);
creeper.Block(-6,6,-12, 12,16,12);
creeper.Block(6,6,-12, 12,16,12);
popMatrix();
}
//the class that makes the mobs for minecraft!
class mob {
//make some vairables
PImage mobSkin, Skin;
PVector Pos;
float textureX=0;
float textureY=0;
private float rot=0;
private float rto=0;
float fallAcell=0;
private Boolean isTextured=true;
mob(PImage skin){// declear variables
Skin=skin;
Pos = new PVector(0,0,0);
}
// supposed to creat a new position for the creeper so they won't over lap
PVector Entity(float x, float y, float z, float mobWidth, float mobHeight){
if(frameCount<5){
Pos.x = x;
Pos.y = y;
Pos.z = z;
} //else {
// x=Pos.x;
// y=Pos.y;
// z=Pos.z;
// }
fallAcell++;
Pos.y+=fallAcell;
translate(Pos.x,Pos.y,Pos.z);
// sphere(5);
return Pos;
}
void follow(float speed, float XO, float YO){// follow a point, ohh so eciting!
pushMatrix();
if(XO <= Pos.x) rto = 180;
else rto = 0;
rot = -atan((Pos.z-YO)/(Pos.x-XO))+radians(rto);
Pos.x += speed*cos(rot);
Pos.z -= speed*sin(rot);
popMatrix();
}
void isTextured(Boolean t){ //swicthes between the mob having an image and not
isTextured =t;
}// probably doesn't exsit in the actuall minecraft game. I mostly use it for debugging.
void Texture(int x,int y, int Width, int Height){// sets texture coordanites
mobSkin=Skin.get(x,y,Width,Height);
}
void Block(float x, float y, float z, float Xidth, float Yight, float Zepth){//this is the block function that creates blocks
pushMatrix();
rotateY(rot +radians(90));
if(!isTextured){// if there isTexture equals false
translate(x,y,z); //translates the box
box(Xidth, Yight, Zepth);//this creates a cube, with width height and depth, thats it.
}
translate(-Pos.x,-Pos.y,-Pos.z);
if(isTextured){// if isTextured is true, then run this incomplete texture map
beginShape(QUADS);
texture(mobSkin);
vertex(Pos.x + x -Xidth/2, Pos.y + y -Yight/2, Pos.z + z +Zepth/2, mobSkin.width/4,mobSkin.height/2);
vertex(Pos.x + x +Xidth/2, Pos.y + y -Yight/2, Pos.z + z +Zepth/2, mobSkin.width/2,mobSkin.height/2);
vertex(Pos.x + x +Xidth/2, Pos.y + y +Yight/2, Pos.z + z +Zepth/2, mobSkin.width/2,mobSkin.height);
vertex(Pos.x + x -Xidth/2, Pos.y + y +Yight/2, Pos.z + z +Zepth/2, mobSkin.width/4,mobSkin.height);
vertex(Pos.x + x -Xidth/2, Pos.y + y -Yight/2, Pos.z + z -Zepth/2, mobSkin.width/4,mobSkin.height/2);
vertex(Pos.x + x +Xidth/2, Pos.y + y -Yight/2, Pos.z + z -Zepth/2, mobSkin.width/2,mobSkin.height/2);
vertex(Pos.x + x +Xidth/2, Pos.y + y +Yight/2, Pos.z + z -Zepth/2, mobSkin.width/2,mobSkin.height);
vertex(Pos.x + x -Xidth/2, Pos.y + y +Yight/2, Pos.z + z -Zepth/2, mobSkin.width/4,mobSkin.height);
endShape(CLOSE);
}
popMatrix();
}
float memx=0;//currently not important
float memy=0;
float memz=0;
void endStep(){//not currently important
memx=Pos.x;
memy=Pos.y;
memz=Pos.z;
}
}
//this is a pointless comment
//the platform is not a class so we just need a void
void Platform(float x,float y, float z, float Xidth, float Yeight, mob Mob){
pushMatrix();
if(Mob.Pos.x >=x-Xidth/2 && Mob.Pos.x <=x+Xidth/2 && Mob.Pos.z >=z-Xidth/2 && Mob.Pos.z <=z+Xidth/2
&& Mob.Pos.y >=y-Yeight/2 && Mob.Pos.y <=y+Yeight/2){// if(XXXXXxxxX[ if a mob is touching the block, do this]XxmXs0)
Mob.Pos.y = y-Yeight/2;//stand on top of ground
Mob.fallAcell =0;//stopfalling
}
translate(x,y,z);//place the box to reprseant our platform
box(Xidth, Yeight, Xidth);
popMatrix();
}
void Pointer(){//makes a dot in space
pushMatrix();
translate(mouseX,350,mouseY*2-height-200);
fill(0);
sphere(10);
popMatrix();
}
//like the platform function, only it moves the mob back up to the top.
void collider(float x,float y, float z, float Xidth, float Yeight, mob Mob){
pushMatrix();
if(Mob.Pos.x >=x-Xidth/2 && Mob.Pos.x <=x+Xidth/2 && Mob.Pos.z >=z-Xidth/2 && Mob.Pos.z <=z+Xidth/2
&& Mob.Pos.y >=y-Yeight/2 && Mob.Pos.y <=y+Yeight/2){// if(XXXXXxxxX[ if a mob is touching the block, do this]XxmXs0)
Mob.Pos.y = 0;
Mob.Pos.z = 100;
Mob.Pos.x =width/2;
Mob.fallAcell =0;
}
popMatrix();
}
Came up with this to try and find out how minecraft mobs are made.
P.S. There is a texture for this mob, but I couldn't figure out how to map it properly to the shape and appears fairly buggy. If someone can help me that would be great