Problem to load an image
in
Programming Questions
•
1 year ago
Hi everybody !
I do a snake and ladders for school and it's really hard !!!
I loaded all the images (i think it's ok but i'm not sure). I've two dice. If the dice does 6, the first player go on the case 6. I need that the 6th illustration and the 6th text comes on the stage.
Somebody can help me ? I hope my english isn't so bad...
THANK YOU !!!!
Tab 1 :
Pion psi;
Pion phi;
Pion joueurCourant;
Dice d1, d2;
PImage fond, jeton1, jeton2;
String[] screenNames = { "demeterPresentation", "heraSaJalousie", "apollonPresentation", "aresPresentation", "cronosProphetie", "vaCase12", "hephaistosNaissance", "hadesPresentation", "artemisDeesseVierge", "zeusNaissance", "dionysosCuisseJupiter", "ionMythe", "heraPresentation", "enlevementPersephone", "hermesAmoursDescendances", "ixionMythe", "apollonNaissance", "hestiaVirginite", "passe2foisTour", "aphroditePresentation", "orpheeMort", "zeusPresentation", "dionysosRetourThebes", "hadesTitanomachie", "aresAmours", "artemisPresentation", "heraclesMythe", "apollonGuerreTroie", "hermesConducteurAme", "ouranosPresentation", "attendReleve", "telegonosMythe", "hestiaPresentation", "gaiaPresentation", "demeterDemophonTriptoleme", "hephaistosPresentation", "heraZeusUnissent", "hermesVolBoeufsApollon", "rheaMythe", "demeterSansNom", "narcisseEcho", "retourCase30", "artemisNaissance", "cronosPresentation", "poseidonPresentation", "hadesSouverainEnfer", "panMythe", "dionysosPresentation", "hephaistosTalentArtistique", "aresAthena", "oedipeMythe", "attendReleve2", "harmonieMythe", "theseeMythe", "hermesNaissance", "erosPsyche", "heraTiresias", "recommence", "apollonDieuVengeur", "gagne" };
String mkScreenFileName(int c) {
return ( c + "." + screenNames[c-1] + ".png");
}
String illustrations(int c) {
return ("I" + c + ".jpg");
}
String questions(int c) {
return ("Q" + c + ".png");
}
String answersA(int c) {
return ("A" + c + ".png");
}
String answersB(int c) {
return ("B" + c + ".png");
}
String answersC(int c) {
return ("C" + c + ".png");
}
void setup() {
size(1200, 750);
fond = loadImage("plateauDuJeu.jpg");
jeton1 = loadImage("jetonOrange.png");
jeton2 = loadImage("jetonNoir.png");
psi=new Pion(1);
phi=new Pion(2);
joueurCourant=psi;
d1=new Dice(260, 15);
d2=new Dice(310, 15);
}
void draw() {
image(fond, 0, 0);
psi.display();
phi.display();
d1.display();
d2.display();
if (d1.endThrow()) { //avance joueur courant après lancer de dés
println( d1.currentValue+1 + d2.currentValue+1 );
d1.state=0;
joueurCourant.moveAnim( d1.currentValue+1 + d2.currentValue+1 );
}
}
void changeJoueur() {
if (joueurCourant==psi) {
joueurCourant = phi;
PFont fontPhi = loadFont("Verdana-14.vlw");
textFont (fontPhi, 18);
fill (0,0,0);
text("joueur 2", 1100, 200);
}
else {
joueurCourant=psi;
PFont fontPsi = loadFont("Verdana-14.vlw");
textFont (fontPsi, 18);
int x = 1100;
fill (0,0,0);
text("joueur 1", x, 150);
}
}
void keyPressed() {
if (key == 'a') psi.nextPosition();
if (key == 'b') phi.nextPosition();
//if (key == 'z') { d1.throwDice(); d2.throwDice(); };
}
void mousePressed() {
if (mouseX>d1.x-5 & mouseX<d2.x+35 & mouseY>d1.y-5 & mouseY<d2.y+35 & !joueurCourant.startAnim) {
d1.throwDice();
d2.throwDice();
}
}
Tab 2 : The dice
String faceOne = "000" +
"010" +
"000";
String faceTwo = "000" +
"101" +
"000";
String faceThree = "100" +
"010" +
"001";
String faceFour = "101" +
"000" +
"101";
String faceFive = "101" +
"010" +
"101";
String faceSix = "101" +
"101" +
"101";
class Dice {
String[] allFaces;
int currentValue = 0;
int rollRate = 100;
int nextFlip;
int x, y; //position
color c; //couleur des points
int state; //0 standby, 1=start lancer, 2=fin de lancer
//constructeur
Dice(int x0, int y0) {
allFaces = new String[6];
allFaces[0] = faceOne;
allFaces[1] = faceTwo;
allFaces[2] = faceThree;
allFaces[3] = faceFour;
allFaces[4] = faceFive;
allFaces[5] = faceSix;
rollRate=1200;
state=0;
x=x0; y=420;
}
void update() {
if (millis() >= nextFlip && rollRate < 1000) {
//anim lancement de dés
currentValue = int(random(5.99));
rollRate *= 1.5;
nextFlip = millis() + rollRate;
}
if ( rollRate > 1000 ) {
//fini - résultat final en vert
if (state==1) state=2;
c=color(255);
} else {
//temporaire pendant lancement
c=color(255);
}
}
Boolean endThrow() {//true quand les dés s'arrêtent
return (rollRate > 1000 & state==2);
}
void display() {
update();
drawDice(x, y, allFaces[currentValue]);
}
void throwDice() {//lance les dés
rollRate = 20;
state=1;
nextFlip = millis() + rollRate;
}
void throwOnClick() {
if (mouseX>x-5 & mouseX<x+35 & mouseY>y-5 & mouseY<y+35) throwDice();
}
void drawDice(int x, int y, String face) {
char spotVal;
//dessine bord et fond
fill(142,11,11);
rect(x-5, y-5, 30, 30);
noStroke();
fill(c);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
spotVal = face.charAt((j * 3) + i);
if (spotVal == '1') {
ellipse(x + (i * 10), y + (j * 10), 5, 5);
}
}
}
}
}
Tab 3 :
//position des cases sur le tableau de l'oie
int[] cases = { 55, 598, 55, 499, 55, 399, 55, 299, 55, 199, 55, 101, 182, 101, 301, 101, 496, 101, 496, 182, 496, 283, 496, 381, 496, 483, 496, 623, 419, 623, 419, 516, 419, 416, 419, 313, 419, 172, 323, 172, 133, 172, 133, 246, 133, 347, 133, 449, 133, 550, 133, 691, 225, 691, 348, 691, 469, 691, 583, 691, 583, 582, 583, 480, 583, 376, 583, 279, 583, 178, 583, 100, 732, 100, 851, 100, 1028, 100, 1028, 177, 1028, 280, 1028, 381, 1028, 481, 1028, 622, 947, 622, 947, 517, 947, 413, 947, 314, 947, 172, 841, 172, 661, 172, 661, 246, 661, 348, 661, 449, 661, 549, 661, 687, 766, 687, 867, 687, 867, 566, 867, 464};
class Pion {
float x;
float y;
float nx, ny; //new position a atteindre
int joueur;
int pos; //numero de la case ou le pion se trouve
int posToGo;
Boolean startAnim=false;
Pion(int joueur0) {
joueur=joueur0;
if (joueur==1) {
x=27; y=687;
}
else {
x=67; y=687;
}
nx=x; ny=y;
}
void moveTo(int nextCase) {//numero de la case, 1ere case=0
if (nextCase>=cases.length) {
println("fin de parcours");
return;
}
nx = cases[nextCase*2];
ny = cases[nextCase*2+1];
pos = nextCase;
}
void move(int n) {//avance de n cases
moveTo(pos+n);
}
void moveAnim(int n) {//avance de n cases pas par pas
posToGo = pos+n;
startAnim=true;
nextPosition();
}
void nextPosition() {
moveTo(pos+1);
}
void display() {
if (abs(nx-x)>.5 | abs(ny-y)>.5) {//anim nextposition
x += (nx-x)/10.0; //anim par relaxation
y += (ny-y)/10.0;
}
else if (startAnim=true & pos!=posToGo) {
nextPosition();
}
else if (startAnim=true & pos==posToGo) {
startAnim=false;
}
if (joueur==1) {
image(jeton1, x, y);
}
else {
image(jeton2, x,y);
}
}
}
I do a snake and ladders for school and it's really hard !!!

I loaded all the images (i think it's ok but i'm not sure). I've two dice. If the dice does 6, the first player go on the case 6. I need that the 6th illustration and the 6th text comes on the stage.
Somebody can help me ? I hope my english isn't so bad...
THANK YOU !!!!

Tab 1 :
Pion psi;
Pion phi;
Pion joueurCourant;
Dice d1, d2;
PImage fond, jeton1, jeton2;
String[] screenNames = { "demeterPresentation", "heraSaJalousie", "apollonPresentation", "aresPresentation", "cronosProphetie", "vaCase12", "hephaistosNaissance", "hadesPresentation", "artemisDeesseVierge", "zeusNaissance", "dionysosCuisseJupiter", "ionMythe", "heraPresentation", "enlevementPersephone", "hermesAmoursDescendances", "ixionMythe", "apollonNaissance", "hestiaVirginite", "passe2foisTour", "aphroditePresentation", "orpheeMort", "zeusPresentation", "dionysosRetourThebes", "hadesTitanomachie", "aresAmours", "artemisPresentation", "heraclesMythe", "apollonGuerreTroie", "hermesConducteurAme", "ouranosPresentation", "attendReleve", "telegonosMythe", "hestiaPresentation", "gaiaPresentation", "demeterDemophonTriptoleme", "hephaistosPresentation", "heraZeusUnissent", "hermesVolBoeufsApollon", "rheaMythe", "demeterSansNom", "narcisseEcho", "retourCase30", "artemisNaissance", "cronosPresentation", "poseidonPresentation", "hadesSouverainEnfer", "panMythe", "dionysosPresentation", "hephaistosTalentArtistique", "aresAthena", "oedipeMythe", "attendReleve2", "harmonieMythe", "theseeMythe", "hermesNaissance", "erosPsyche", "heraTiresias", "recommence", "apollonDieuVengeur", "gagne" };
String mkScreenFileName(int c) {
return ( c + "." + screenNames[c-1] + ".png");
}
String illustrations(int c) {
return ("I" + c + ".jpg");
}
String questions(int c) {
return ("Q" + c + ".png");
}
String answersA(int c) {
return ("A" + c + ".png");
}
String answersB(int c) {
return ("B" + c + ".png");
}
String answersC(int c) {
return ("C" + c + ".png");
}
void setup() {
size(1200, 750);
fond = loadImage("plateauDuJeu.jpg");
jeton1 = loadImage("jetonOrange.png");
jeton2 = loadImage("jetonNoir.png");
psi=new Pion(1);
phi=new Pion(2);
joueurCourant=psi;
d1=new Dice(260, 15);
d2=new Dice(310, 15);
}
void draw() {
image(fond, 0, 0);
psi.display();
phi.display();
d1.display();
d2.display();
if (d1.endThrow()) { //avance joueur courant après lancer de dés
println( d1.currentValue+1 + d2.currentValue+1 );
d1.state=0;
joueurCourant.moveAnim( d1.currentValue+1 + d2.currentValue+1 );
}
}
void changeJoueur() {
if (joueurCourant==psi) {
joueurCourant = phi;
PFont fontPhi = loadFont("Verdana-14.vlw");
textFont (fontPhi, 18);
fill (0,0,0);
text("joueur 2", 1100, 200);
}
else {
joueurCourant=psi;
PFont fontPsi = loadFont("Verdana-14.vlw");
textFont (fontPsi, 18);
int x = 1100;
fill (0,0,0);
text("joueur 1", x, 150);
}
}
void keyPressed() {
if (key == 'a') psi.nextPosition();
if (key == 'b') phi.nextPosition();
//if (key == 'z') { d1.throwDice(); d2.throwDice(); };
}
void mousePressed() {
if (mouseX>d1.x-5 & mouseX<d2.x+35 & mouseY>d1.y-5 & mouseY<d2.y+35 & !joueurCourant.startAnim) {
d1.throwDice();
d2.throwDice();
}
}
Tab 2 : The dice
String faceOne = "000" +
"010" +
"000";
String faceTwo = "000" +
"101" +
"000";
String faceThree = "100" +
"010" +
"001";
String faceFour = "101" +
"000" +
"101";
String faceFive = "101" +
"010" +
"101";
String faceSix = "101" +
"101" +
"101";
class Dice {
String[] allFaces;
int currentValue = 0;
int rollRate = 100;
int nextFlip;
int x, y; //position
color c; //couleur des points
int state; //0 standby, 1=start lancer, 2=fin de lancer
//constructeur
Dice(int x0, int y0) {
allFaces = new String[6];
allFaces[0] = faceOne;
allFaces[1] = faceTwo;
allFaces[2] = faceThree;
allFaces[3] = faceFour;
allFaces[4] = faceFive;
allFaces[5] = faceSix;
rollRate=1200;
state=0;
x=x0; y=420;
}
void update() {
if (millis() >= nextFlip && rollRate < 1000) {
//anim lancement de dés
currentValue = int(random(5.99));
rollRate *= 1.5;
nextFlip = millis() + rollRate;
}
if ( rollRate > 1000 ) {
//fini - résultat final en vert
if (state==1) state=2;
c=color(255);
} else {
//temporaire pendant lancement
c=color(255);
}
}
Boolean endThrow() {//true quand les dés s'arrêtent
return (rollRate > 1000 & state==2);
}
void display() {
update();
drawDice(x, y, allFaces[currentValue]);
}
void throwDice() {//lance les dés
rollRate = 20;
state=1;
nextFlip = millis() + rollRate;
}
void throwOnClick() {
if (mouseX>x-5 & mouseX<x+35 & mouseY>y-5 & mouseY<y+35) throwDice();
}
void drawDice(int x, int y, String face) {
char spotVal;
//dessine bord et fond
fill(142,11,11);
rect(x-5, y-5, 30, 30);
noStroke();
fill(c);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
spotVal = face.charAt((j * 3) + i);
if (spotVal == '1') {
ellipse(x + (i * 10), y + (j * 10), 5, 5);
}
}
}
}
}
Tab 3 :
//position des cases sur le tableau de l'oie
int[] cases = { 55, 598, 55, 499, 55, 399, 55, 299, 55, 199, 55, 101, 182, 101, 301, 101, 496, 101, 496, 182, 496, 283, 496, 381, 496, 483, 496, 623, 419, 623, 419, 516, 419, 416, 419, 313, 419, 172, 323, 172, 133, 172, 133, 246, 133, 347, 133, 449, 133, 550, 133, 691, 225, 691, 348, 691, 469, 691, 583, 691, 583, 582, 583, 480, 583, 376, 583, 279, 583, 178, 583, 100, 732, 100, 851, 100, 1028, 100, 1028, 177, 1028, 280, 1028, 381, 1028, 481, 1028, 622, 947, 622, 947, 517, 947, 413, 947, 314, 947, 172, 841, 172, 661, 172, 661, 246, 661, 348, 661, 449, 661, 549, 661, 687, 766, 687, 867, 687, 867, 566, 867, 464};
class Pion {
float x;
float y;
float nx, ny; //new position a atteindre
int joueur;
int pos; //numero de la case ou le pion se trouve
int posToGo;
Boolean startAnim=false;
Pion(int joueur0) {
joueur=joueur0;
if (joueur==1) {
x=27; y=687;
}
else {
x=67; y=687;
}
nx=x; ny=y;
}
void moveTo(int nextCase) {//numero de la case, 1ere case=0
if (nextCase>=cases.length) {
println("fin de parcours");
return;
}
nx = cases[nextCase*2];
ny = cases[nextCase*2+1];
pos = nextCase;
}
void move(int n) {//avance de n cases
moveTo(pos+n);
}
void moveAnim(int n) {//avance de n cases pas par pas
posToGo = pos+n;
startAnim=true;
nextPosition();
}
void nextPosition() {
moveTo(pos+1);
}
void display() {
if (abs(nx-x)>.5 | abs(ny-y)>.5) {//anim nextposition
x += (nx-x)/10.0; //anim par relaxation
y += (ny-y)/10.0;
}
else if (startAnim=true & pos!=posToGo) {
nextPosition();
}
else if (startAnim=true & pos==posToGo) {
startAnim=false;
}
if (joueur==1) {
image(jeton1, x, y);
}
else {
image(jeton2, x,y);
}
}
}
1