Hi everybody,
I need help with my first processing project.
I need to develop a mario like game for school, but I have some problems
How can I set a gravity ? Because when I trie to set y = y+1 in the test, the smiley is going down but when it is on the floor it is impossible to go on left or right, I have a problem with the test of the position but I don’t know where.
My second problem is that I don’t know how to set that when the smiley is near a specific tile it is necessary to tap a key (like ‘t’) to break the tile and if you don’t tap the key, the tile won’t break.
I hope that my explanation is not to bad because I am starting with developpement and there is a long time I have not write in English.
This is my actual sketch
import ptmx.*;
Ptmx map;
PImage smiley;
int x , y, score=0;
boolean left, right, up, down;
void setup() {
size(800, 600);
smiley = loadImage("smiley.png"); // charge une image smiley.png sous le nom smiley
map = new Ptmx(this, "niv1.tmx");
map.setDrawMode(CENTER);
map.setPositionMode("CANVAS");//Default Position Mode
x = int(map.mapToCanvas(map.getMapSize()).x / 2);
y = int(map.mapToCanvas(map.getMapSize()).y / 2);
imageMode(CENTER);
}
void draw(){
background(map.getBackgroundColor());
map.draw(x, y);
image(smiley, width / 2, height / 2); //défini la position du smiley par rapport à la fenetre d'affichage
textSize(24);
fill(128);
text("Score " +score, 300,18);
int prevX = x;
int prevY = y;
if(left) x -= 3;
if(right) x += 3;
PVector overTile = map.canvasToMap(x, y+15);
switch(map.getTileIndex(0, round(overTile.x), round(overTile.y))){
case 4:
break;
case 5:
map.setTileIndex(0, round(overTile.x), round(overTile.y), 4);
score= score+1;
break;
default:
x = prevX;
}
if(up) y -= 3;
if(down) y += 3;
switch(map.getTileIndex(0, round(overTile.x), round(overTile.y))){
case 4:
y = y+1;
break;
case 5:
map.setTileIndex(0, round(overTile.x), round(overTile.y), 4);
score= score+1;
y = y+1;
break;
default:
y = prevY;
}
}
void keyPressed(){
if(keyCode == LEFT) left = true;
if(keyCode == RIGHT) right = true;
if(keyCode == UP) up = true;
if(keyCode == DOWN) down = true;
}
void keyReleased(){
if(keyCode == LEFT) left = false;
if(keyCode == RIGHT) right = false;
if(keyCode == UP) up = false;
if(keyCode == DOWN) down = false;
}