Its my main code
Player witch;
boolean left, up, right,jump,test;
PImage playerArt;
PImage fondImage,cloud1,cloud2,rainbow1,rainbow2,tree1,tree2,tree3,tree4,grass,cobble,fondgris,fondmar,fondmar2;
int [] maprow= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
int [][] tilemap = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 13, 14, 10, 10, 10, 10, 10},
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 11, 11, 11, 11, 11},
{11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11},
{11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11},
{11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11},
{11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11},
{11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11},
{11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}
};
int row,cols;
int cellWidth, cellHeight;
void setup(){
fullScreen(P2D);
size(640,640);
//row = 10;
//cols = 10;
row = tilemap.length;
cols = tilemap[0].length;
cellWidth = 64;//pour augmenter taille faire plus 64 et ajouter row ou cols Ă la tilemap
cellHeight = 64;
witch = new Player();
left = false;
right=false;
up = false;
test = false;
playerArt = loadImage("witch3.png");
fondImage = loadImage("fond.png");
cloud1 = loadImage("cloud1.png");
cloud2 = loadImage("cloud2.png");
rainbow1 = loadImage("rainbow1.png");
rainbow2 = loadImage("rainbow2.png");
tree1 = loadImage("tree1.png");
tree2 = loadImage("tree2.png");
tree3 = loadImage("tree3.png");
tree4 = loadImage("tree4.png");
grass = loadImage("grass.png");
cobble = loadImage("cobble.png");
fondmar = loadImage("fondmar.png");
fondmar2 = loadImage("fondmar2.png");
fondgris = loadImage("fondgris.png");
}
void draw(){
background(120);
renderMap();
witch.update();
checkWallCollisions(witch);
witch.display();
}
void checkWallCollisions(Player witch){
String collisionSide = "none";
for(int i=0; i<row; i++){
for(int j=0; j<cols; j++){
if(tilemap[i][j] == 1 || tilemap[i][j] == 10 || tilemap[i][j] == 11){//check si c'est un mur//pour plus tard
int distX = floor((witch.x + witch.w/2)-(j*cellWidth+cellWidth/2));
int distY = floor((witch.y + witch.h/2)-(i*cellHeight+cellHeight/2));
int combinedHalfW = floor(witch.w/2+cellWidth/2);
int combinedHalfH = floor(witch.h/2+cellHeight/2);
if(abs(distX) < combinedHalfW){
if(abs(distY) < combinedHalfH){
int overlapX = combinedHalfW - abs(distX);
int overlapY = combinedHalfH - abs(distY);
if(overlapX >= overlapY){
if(distY > 0){
collisionSide = "TOP";
witch.y += overlapY;
}else{
collisionSide = "BOTTOM";
witch.y -= overlapY;
witch.land(witch.y);
}}else{
witch.connected=false;
if(distX > 0){
collisionSide ="Left";
witch.x += overlapX;
}else{
collisionSide = "Right";
witch.x -= overlapX;
}
}
}
}
}
}//end tilemap
}//end cols
}//end rows
void keyPressed(){
//fill(255);
//textSize(24);
//text("keyCode: " + keyCode, 50, 50);
//ASCII character codes
switch(keyCode){
case 37:
left = true;
break;
case 38:
up = true;
break;
case 39:
right = true;
break;
case 32:
jump = true;
break;
}
}
void keyReleased(){
//fill(255);
//textSize(24);
//text("keyCode: " + keyCode, 50, 50);
//ASCII character codes
switch(keyCode){
case 37:
left = false;
break;
case 38:
up = false;
break;
case 39:
right = false;
break;
case 32:
jump = false;
break;
}
}
void renderMap(){
for (int i=0; i< row; i++){
for(int j=0; j < cols; j++){
switch(tilemap[i][j]){
case 0:
image(fondImage,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 2:
image(cloud1,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 3:
image(cloud2,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 4:
image(rainbow1,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 5:
image(rainbow2,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 6:
image(tree1,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 7:
image(tree2,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 8:
image(tree3,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 9:
image(tree4,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 1:
image(fondImage,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 10:
image(grass,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 11:
image(cobble,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 12:
image(fondgris,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 13:
image(fondmar,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
case 14:
image(fondmar2,j*cellWidth,i*cellHeight,cellWidth,cellHeight);
break;
default:
println("Problème de map");
}// end for cols
}//end for rows
}//end rendernMap
}
And the code of my player class :
class Player{
int x,y,w,h;
int speedX, speedY;
int currentFrame, offsetX, offsetY, totalFrames, row, sx, sy;
int hold, delay,time;
int g;
boolean connected;
//constructeur
Player(){
x= 10;
y = 200;
w = 64;
h= 64;
currentFrame = 0;
offsetX = 0*w;
offsetY = 0*h;
row=0;
sx = 0;
sy=0;
hold =0;
delay=10;
totalFrames =4;
connected = false;
g= 1;
}
//methods
void land(int destY){
speedY =0;
connected = true;
}
void update(){
//horizontal
if(left&&!right){
speedX = -4;
totalFrames = 2;
row = 4;
}
if(right&&!left){
speedX = 4;
totalFrames = 2;
row = 3;
}
if(!left&&!right){
speedX =0;
totalFrames = 2;
row =0;
}
//vertical
if(up && connected == true){
totalFrames = 5;
row =5;
speedY = -20;
connected = false;
}
if (connected == false){
speedY += g;
}
if(y > height){
y =0;
speedY =0;
}
x += speedX;
y += speedY;
//update sprite art
sx = currentFrame *w;
sy = row * h;
hold = (hold +1) % delay;
if(hold ==0){
currentFrame =(currentFrame + 1)% totalFrames;
}}
void display(){
//fill(237,121,255);
//rect(x,y,w,h);
//fill(0);
//rect(x+w/2,y+h/2,1,1);
copy(playerArt, sx + offsetX, sy + offsetY, w, h, x, y, w, h);
}
}
My problem is that when my character is on a platform that is not solid it does not fall I have to jump before it can fall.