Help with another simple game
in
Programming Questions
•
3 years ago
I'm trying to get the game to reset if the ball hits the line, but it just dons't want to work please help! thank you!
- float speed = 2; // movement of player speed
- int size = 15; // Width of the shape
- float xpos, ypos; // Starting position of shape
- float x1 = random(600);
- float y1 = random(200);
- float y2 = random(200);
- void setup()
- {
- size(800, 200);
- noStroke();
- frameRate(30);
- smooth();
- xpos = 40;
- ypos = 100;
- }
- void draw()
- {
- background(102);
- smooth();
- noStroke();
- move();
- collidewithbackwall();
- linecollide();
- ellipse(xpos, ypos, size, size);
- stroke(0);
- line(x1,y1,x1,y2);
- }
- void move()
- {
- xpos += speed;
- }
- void collidewithbackwall()
- {
- if((xpos + size ) >= width) {
- print("you win!");
- xpos = 40;
- speed = 0;
- }
- }
- void linecollide()
- {
- if((xpos=x1) && (xpos>y1) && (xpos<y2)){
- print("you lose!");
- xpos = 40;
- speed = 0;
- }
- }
1