// Welcome to the KTBYTE coder!
// Feel free to run some code, create a new project, or work on a PSET problem!
// Press the run button or "CTRL + ENTER" to run the code below!
int width=1000;
int length=1000;
int lmx=100;
int lmy=0;
int speed=10;
int weight=0;
int weightCount=10;
int speedCount=speed;
int weightCount2=weightCount;
int obstacleLength=150;
boolean touching=false;
int obstacleWidth=100;
int moved=0;
int moveCounter=moved;
Sprite lm = new Sprite(lmx,lmy,100,100);
Sprite obstacle = new Sprite("https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Square-white.svg/1200px-Square-white.svg.png",500,500,obstacleLength,obstacleWidth);
void setup(){
size(length,width);
}
void draw(){
background(0,255,0);
textSize(100);
// text(weight,100,500);
// text(moved, 300,800);
lm.display();
obstacle.display();
lm.forward(speed);
if (speed!=0){
weight+=weightCount;
moved+=weightCount;
}
if(!lm.isInsideScreen()){
if(lm.getX()>=length&&lm.getY()>=width){
lm.moveToPoint(960,960);
weightCount2=0;
speedCount=0;
weightCount=weightCount2;
speed=speedCount;
} else if(lm.getX()<0&&lm.getY()>=width){
lm.moveToPoint(40,960);
weightCount2=0;
speedCount=0;
weightCount=weightCount2;
speed=speedCount;
}else{
lmy+=100;
lm.moveToPoint(lm.getX(),lmy);
speedCount*=-1;
speed=speedCount;
}
}
if(weight>=1000){
speed=0;
weightCount=0;
}
if(lm.touchingSprite(obstacle)){
lm.moveToPoint(lm.getX(),lmy-obstacleWidth);
moved=0;
touching=true;
// z=0;
}
if(touching&&moved>=250){
lm.moveToPoint(lm.getX(),lmy);
touching=false;
moveCounter=0;
}
// lm.moveToPoint(l,y+100);
// while()
}
void keyPressed() {
if (key == 'w') {
weight=0;
speed=speedCount;
weightCount=weightCount2;
}
}