Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualtimgranstrom

Posted 22 April 2013 - 10:09 AM

this won't work since it checks for everything and it just really freaks out haha..

 

I found a "solution" to this problem though, but I'm not sure it's a good one or not..

 

in the Entity Class, I made another variable.

protected String entityName; //The name of an entity

This works so that if you want to, you can give your entity object a name for various reasons.

 

then in the ball,paddle and ai class, I add their entity names in their constructors like this:

this.entityName = "Paddle";

and so on.

 

Then the collision detection in their update methods looks like this:

 

 

ball:

//If there is an obstacle
	    if(obstacle != null) {
	        if(obstacle.entityName == "Paddle") {
	           this.invGoingLeft();
	        }
	        
	        if(obstacle.entityName == "Wall") {
	          this.invGoingDown();
	        }
	    }

paddle and ai are identical in the collision detection:

 if(obstacle != null) {
		        if(obstacle.entityName == "Wall") {
		        	
		        if(obstacle.getY() < getY()){
		           this.collideDown = false;
		           this.collideUp = true;
		        } else {
		            this.collideDown = true;
		            this.collideUp = false;
		        }
		        }
		        if(obstacle.entityName != "Wall"){
		        	this.collideDown = false;
		            this.collideUp = false;
		        }
		    }

 

 

Is this a good way or would this be considered a bad way to check what it collides with?

 

I get that in more advanced games where there are more objects and factors etc this would probably be a bad way.

 

But what about in this game?


#2timgranstrom

Posted 22 April 2013 - 10:08 AM

this won't work since it checks for everything and it just really freaks out haha..

 

I found a "solution" to this problem though, but I'm not sure it's a good one or not..

 

in the Entity Class, I made another variable.

protected String entityName; //The name of an entity

This works so that if you want to, you can give your entity object a name for various reasons.

 

then in the ball,paddle and ai class, I add their entity names in their constructors like this:

this.entityName = "Paddle";

and so on.

 

Then the collision detection in their update methods looks like this:

 

 

ball:

//If there is an obstacle
	    if(obstacle != null) {
	        if(obstacle.entityName == "Paddle") {
	           this.invGoingLeft();
	        }
	        
	        if(obstacle.entityName == "Wall") {
	          this.invGoingDown();
	        }
	    }

paddle and ai are identical in the collision detection:

 if(obstacle != null) {
		        if(obstacle.entityName == "Wall") {
		        	
		        if(obstacle.getY() < getY()){
		           this.collideDown = false;
		           this.collideUp = true;
		        } else {
		            this.collideDown = true;
		            this.collideUp = false;
		        }
		        }
		        if(obstacle.entityName != "Wall"){
		        	this.collideDown = false;
		            this.collideUp = false;
		        }
		    }

 

 

Is this a good way or would this be considered a bad way to check what it collides with?

 

I get that in more advanced games where there are more objects and factors etc this would probably be a bad way.

 

But what about in this game?


#1timgranstrom

Posted 22 April 2013 - 10:07 AM

this won't work since it checks for everything and it just really freaks out haha..

 

I found a "solution" to this problem though, but I'm not sure it's a good one or not..

 

in the Entity Class, I made another variable.

protected String entityName; //The name of an entity

This works so that if you want to, you can give your entity object a name for various reasons.

 

then in the ball,paddle and ai class, I add their entity names in their constructors like this:

this.entityName = "Paddle";

and so on.

 

Then the collision detection in the classes update method looks like this:

 

 

ball:

//If there is an obstacle
	    if(obstacle != null) {
	        if(obstacle.entityName == "Paddle") {
	           this.invGoingLeft();
	        }
	        
	        if(obstacle.entityName == "Wall") {
	          this.invGoingDown();
	        }
	    }

paddle and ai are identical in the collision detection:

 if(obstacle != null) {
		        if(obstacle.entityName == "Wall") {
		        	
		        if(obstacle.getY() < getY()){
		           this.collideDown = false;
		           this.collideUp = true;
		        } else {
		            this.collideDown = true;
		            this.collideUp = false;
		        }
		        }
		        if(obstacle.entityName != "Wall"){
		        	this.collideDown = false;
		            this.collideUp = false;
		        }
		    }

 

 

Is this a good way or would this be considered a bad way to check what it collides with?

 

I get that in more advanced games where there are more objects and factors etc this would probably be a bad way.

 

But what about in this game?


PARTNERS