Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

boogyman19946

Member Since 15 May 2010
Offline Last Active Today, 12:55 PM

Topics I've Started

cannot find symbol even though its defined

Yesterday, 07:53 PM

Hello folks. It has been a while since I posted on the forums.

 

I've revived a project from ages ago, and I've been going through the source trying to get the thing to work. I'm getting the following errors:

 

E:\NetBeansProjects\Digestion\src\Entity\Entity.java:164: error: cannot find symbol
			mMotionModule.resetTimer();
			             ^
  symbol:   method resetTimer()
  location: variable mMotionModule of type MotionModule
E:\NetBeansProjects\Digestion\src\Entity\Entity.java:173: error: cannot find symbol
			mMotionModule.update(this, manager.getEntities());
			             ^
  symbol:   method update(Entity,LinkedList<Entity>)
  location: variable mMotionModule of type MotionModule
E:\NetBeansProjects\Digestion\src\Entity\Entity.java:176: error: cannot find symbol
			mPathfindingModule.update();
			                  ^
  symbol:   method update()
  location: variable mPathfindingModule of type PathfindingModule
E:\NetBeansProjects\Digestion\src\Entity\Entity.java:189: error: cannot find symbol
			mHealthModule.draw(canvas);
			             ^
  symbol:   method draw(GameCanvas)
  location: variable mHealthModule of type HealthModule
4 errors
E:\NetBeansProjects\Digestion\nbproject\build-impl.xml:605: The following error occurred while executing this line:
E:\NetBeansProjects\Digestion\nbproject\build-impl.xml:246: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)

 

I thought this was a rather routine error: I probably just misspelled a few function names. The thing is though, I haven't. To make extra sure, I copied and pasted them into place but the compiler still gives me those errors. Even more strange, NetBeans' error highlighter does not mark these lines as errors. Only the compiler. 

 

Here is the Entity class (errors are marked with line comments)

package Entity;

import java.awt.geom.Rectangle2D;

import Core.Level.Level;
import Core.Messages.Message;
import Core.Messages.MessageQueue;
import Entity.EntityScripting.EntityScript;
import Entity.Modules.*;
import Graphics.GameCanvas;

public class Entity {
	private String mName;
	private Rectangle2D.Float mBoundRect;
	private int mDepth;
	
	private Level mLevel;
	
	private String m_pwd;
	private EntityScript mObjectScript;

	private HealthModule mHealthModule;
	private MotionModule mMotionModule;
	private GraphicsModule mGraphicsModule;
	private SoundModule mSoundModule;
	private PathfindingModule mPathfindingModule;
	
	private MessageQueue mMessageQueue;

	public Entity(Level level) {
		mLevel = level;
		mName = "Default";
		mBoundRect = new Rectangle2D.Float(0, 0, 0, 0);
		m_pwd = null;  
		mObjectScript = null;
		
		mHealthModule = null;
		mMotionModule = null;
		mGraphicsModule = null;
		mPathfindingModule = null;
		mSoundModule = null;
		
		mMessageQueue = new MessageQueue();
	}

	public boolean initialize(String pwd, EntityScript objectScript, int x, int y, String[] arguments) {
		m_pwd = pwd;
		mObjectScript = objectScript;
		
		mBoundRect.x = x;
		mBoundRect.y = y;
		
		mObjectScript.create(this, arguments);
		
		return true;
	}
     
        // ...
        // Snip unrelated functions
        // ...

	public void reset() {
		if(mMotionModule != null)
			mMotionModule.resetTimer();                        // Error occurs here
		
		mObjectScript.reset();
	}
	
	public void update(EntityManager manager) {
		processMessages();
		
		if(mMotionModule != null)
			mMotionModule.update(this, manager.getEntities()); // Error occurs here
		
		if(mPathfindingModule != null)
			mPathfindingModule.update();                       // Error occurs here
		
		mObjectScript.processKeys();
		mObjectScript.update();
	}
	
	public void draw(GameCanvas canvas) {
		if(mGraphicsModule != null) {
			mGraphicsModule.draw(canvas);
			mObjectScript.draw();
		}
		
		if(mHealthModule != null) {
			mHealthModule.draw(canvas);                        // Error occurs here
		}
	}
}

 

 

and the MotionModule class (the error is the same for the other two classes featuring different functions)

 

package Entity.Modules;

import java.awt.geom.*;
import java.util.LinkedList;

import Entity.Entity;
import Util.GameTimer;
import Util.Vector2D;

public class MotionModule {
	private static class Force	{
		String name;
		Vector2D force;
		
		public Force(String name, Vector2D force) {
			this.name = name;
			this.force = force;
		}
	}

	private double mMass;
	
	private Vector2D mVelocity;
	private double mTerminalVelocity;
	
	private LinkedList<Force> mForces;
	
	private Vector2D mJumpForce;
	private boolean mJump;
	private boolean mCanJump;
	private boolean mCanDoubleJump;
	private boolean mDoubleJumpFlag;
	
	private boolean mStopOnSolid;
	private double mGravity;
	
	private GameTimer mTimer;
	
	//////////////////////
	// PUBLIC INTERFACE //
	//////////////////////	
	public MotionModule(double mass, double terminalVelocity) {
		mMass = mass;
		
		mVelocity = new Vector2D(0.0f, 0.0f);
		mTerminalVelocity = terminalVelocity;
		
		mForces = new LinkedList<Force>();
		
		mJumpForce = new Vector2D(0.0, 0.0);
		mJump = false;
		mDoubleJumpFlag = false;
		
		mStopOnSolid = false;
		mGravity = 0.0;
		
		mTimer = new GameTimer();
	}

        // ...
        // Snip unrelated functions
        // ...

	public void resetTimer() {
		mTimer.reset();
	}
	
	public void update(Entity entity, LinkedList<Entity> entityList) {
		// Elapsed time in seconds
		double elapsedTime = getTimeStep();
		
		Rectangle2D.Float entRect = entity.getObjectRect();
		
		//////////////////
		// Move forward //
		//////////////////
		Vector2D deltaPos = integrateVelocity(elapsedTime);
		
		entRect.x += deltaPos.x;
		entRect.y += deltaPos.y;
		
		/////////////////////
		// Check collision //
		/////////////////////
		Entity obstacle = null;
		boolean collisionFree = false;
		while(!collisionFree) {
			for(Entity worldEntity: entityList) {
				if(!entRect.intersects(worldEntity.getObjectRect()))
					continue;

				Rectangle2D.Float obstRect = worldEntity.getObjectRect();

				Vector2D entCenter = new Vector2D(entRect.x + entRect.width/2, entRect.y + entRect.height/2);
				Vector2D obstCenter = new Vector2D(obstRect.x + obstRect.width/2, obstRect.y + obstRect.height/2);

				Vector2D obstClosestCorner = closestCornerToCenter(entCenter, obstRect);
				Vector2D entClosestCorner = closestCornerToCenter(obstCenter, entRect);

				Vector2D posShift = obstClosestCorner.subtract(entClosestCorner).projectOn(deltaPos);

				entClosestCorner = entClosestCorner.subtract(posShift);

				Vector2D collisionNormal = getCollisionNormal(entClosestCorner, obstClosestCorner, deltaPos);
				

				entRect.x -= posShift.x;
				entRect.y -= posShift.y;
			}
			
			collisionFree = true;
		}
	}
}

 

 

The package hierarchy is as follows <src>/Entity/Modules

The Entity class resides in package Entity, whereas all the Modules reside in Entity/Modules

 

Does anyone have any idea as to why I'm getting this seemingly baseless error? Some folks said it has to do with classpaths. I looked through the project properties but I have not found anything that might cause this.


Moving objects based on friction or not

09 July 2012 - 06:31 PM

I have a little bit of a dilemma regarding the "correctness" of my physics simulation.

The game I'm working on is a 2D sidescroller and my question pertains to the method of simulation self-propelled motion (walking).

Currently, I'm basically faking the motion of the objects in the game, but I'd very much like to move beyond that and introduce a reasonably correct way to move objects about. My problem stems from the fact that in order to move, we apply a force against the ground and, after application of suitable laws of motion (I believe the third law is most notable in this case), we end up accelerating while the ground seems to stay put.

The way I see it is that I would have to check what other objects I'm in contact with, add up all the forces, check what objects I'm pushing against, and workout the acceleration. I looked around articles to see if any of them mention doing things this way, but I couldn't find anything on it. My question is as follows:

Is it at all feasible to simulate game physics that way or should I just fake the initial forces and pushing action?

I can't seem to find the right way to convey what I'm trying to say, but if you guys can't make out what I'm saying, let me know and I'll try explaining again.

PARTNERS