Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Vanzare cumparare fara transfer b...

Receptie ciudata, in functie de t...

Dupa 20 ani de facultate, am uita...

Mobile.de ofera imprumut de bani ...
 problema test grila

Digi24 a disparut de pe TV Lg

Drept de proprietate intelectuala...

Jante noi shitbox
 Trinitas TV 4K

Dacia 1316 cu 6 usi ...

Frecventa modificata radio

Un nou pericol pt batrani
 Ar trebuii sa vindem imobiliarele...

Dupa renuntarea la aparat dentar

pelerinaj in Balcik

Noul format Jpegli iși propu...
 

[Processing3] joc labirint

- - - - -
  • Please log in to reply
No replies to this topic

#1
poloist11

poloist11

    New Member

  • Grup: Members
  • Posts: 20
  • Înscris: 28.05.2014
Salut ! Recent am inceput sa invat sa lucrez in Processing3 si am o problema cu o aplicatie pe care incerc sa o fac.

Jocul urmareste sa muti cursorul de pe spatial rosu pe spatial verde al ecranului, evitand obstacolele. Problema este ca functia care verifica sa nua tingi obstacolele ( sau impelmentarea ei) nu este buna.
Are cineva ceva idei?

Obstacle1[] obs1 = new Obstacle1[100];
Obstacle2[] obs2 = new Obstacle2[100];
int n=30;
float x, y, d1, d2;
boolean touch=false;
void setup() {
  size(1024, 768);
  background(50);
  for (int i =0; i<obs1.length; i++) {
	obs1[i]=new Obstacle1( x, y, d1, d2 );
  }
  for (int i =0; i<obs2.length; i++) {
	obs2[i]=new Obstacle2( x, y, d1, d2 );
  }
}
void draw() {
  if (touch == false && mouseX < width-100) {
	//desenare background
	background(50);
	fill(255, 0, 0);
	rect(0, 0, 100, height);
	fill(0, 255, 0);
	rect(width-100, 0, 100, height);
	//bila in jurul mouse-ului	
	stroke(255);
	strokeWeight(5);
	noFill();
	ellipse(mouseX, mouseY, 15, 15);
	//afisare obstacole
	strokeWeight(1);
	for (int i =0; i<n; i++) {
	  obs1[i].display();
	  obs1[i].move();
	}
	for (int i =0; i<n; i++) {
	  obs2[i].display();
	  obs2[i].move();
	}
  }
  //conditie castigare joc
  else if (touch==false && mouseX >= width-100) {
	background(255);
	textSize(180);
	fill(0);
	text("YOU WON", 100, height/2+90);
  }

  //conditie pierdere joc
  else /*if (touch==true)*/ {
	background(255);
	textSize(180);
	fill(0);
	text("GAME OVER", 100, height/2+90);
  }
}
void collide() {
  for (int i=0; i<n; i++) {
	if (mouseX>obs1[i].x-d1/2 && mouseY>obs1[i].y-d1/2 && mouseX<obs1[i].x+d1/2 && mouseY<obs1[i].y+d1/2);
	touch=true;
	break;
  }
  for (int i =0; i<n; i++) {
	if (mouseX>obs2[i].x-d1/2 && mouseY>obs2[i].y-d1/2 && mouseX<obs2[i].x+d1/2 && mouseY<obs2[i].y+d1/2);
	touch=true;
	break;
  }
}



class Obstacle1 {
  float x, y, d1, d2;
  Obstacle1(float tempX, float tempY, float tempD1, float tempD2) {
	x=random(150, width-150);
	y=random(-50, height-50);
	d1=random(20, 100);
	d2=random(20, 100);
  }
  void display() {
	fill(150,150,150,100);
	stroke(50);
	rect(x, y, d1, d2);
  }
  void move() {
	x+=random(-3, 3);
	y+=random(-3, 3);
  }
}




class Obstacle2 {
  float x, y, d1, d2;
  Obstacle2(float tempX, float tempY, float tempD1, float tempD2) {
	x=random(150, width-150);
	y=random(-50, height-50);
	d1=random(20, 100);
	d2=random(20, 100);
  }
  void display() {
	fill(150,150,150,random(100,200));
	stroke(50);
	ellipse(x, y, d1, d2);
  }
  void move() {
	x+=random(-3, 3);
	y+=random(-3, 3);
  }
}



Anunturi

Bun venit pe Forumul Softpedia!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate