Jump to content

  • Log In with Google      Sign In   
  • Create Account

GameGeezer

Member Since 07 Feb 2010
Offline Last Active Yesterday, 12:49 PM

#5131095 Need feedback on code design for maps of an RPG

Posted by GameGeezer on 13 February 2014 - 01:03 PM

public int getX()
{
return super.getX();
}

This is neither necessary nor proper style. The geX() method inherited will be visible as long as it's public.

int rectWidth = 50;
             int rectHeight = 50;
             // left
             leftRectangle = new Rectangle(((int)(getWidth() * -.04)) - camera.getX(),getY() - camera.getY(),rectWidth,getHeight());
             // right
             rightRectangle = new Rectangle(((int)(getWidth())) - camera.getX(),getY() - camera.getY(),rectWidth,getHeight());
             // top
             topRectangle = new Rectangle((int)(getWidth() *  0)- camera.getX(),(int) ((getHeight() * -0.06) - camera.getY()) ,getWidth(),rectHeight);
             // down
             downRectangle = new Rectangle((int)(getWidth() * 0)- camera.getX(),getHeight()  - camera.getY() ,getWidth(),rectHeight);
 
 
 
             if(link.getRectangle().intersects(leftRectangle))
             {
                       MapTracker.SCREEN = 1;
             }
             // right wall collision
             else if(link.getX() + link.getIdleRightWidth() > ((int)(getWidth())) - camera.getX())
             {
                       camera.setX(camera.getX() - camera.getSpeed());
             }
             // top wall collision
             else if(link.getY() < (int) ((getHeight() * -0.06) - camera.getY()) + topRectangle.getHeight() - 10 )
             { 
                       camera.setY(camera.getY() + camera.getSpeed());
             }
             // down wall collision
             else if( (link.getY() + link.getIdleDownHeight() > downRectangle.getY()))
             { 
                       camera.setY(camera.getY() - camera.getSpeed());
             }

Try not to create objects when it's not necessary. Why not just check if the player's x, y coordinates are within the camera frustum, if not shift the Scene.

 

Try using a node based scene heiarchy it will be much more flexible

/**
 *
 * @author William Gervasio
 *
 */

import java.util.ArrayList;
import java.util.List;

import core.util.Node;
import core.util.math.Vector2;


public abstract class SceneNode extends Node<SceneNode> {

    private Vector2 translation;
    private List<IBehavior> behaviors = new ArrayList<IBehavior>();
    private float sceneTime;

    public SceneNode() {
        this(new Vector2());
    }

    public SceneNode(Vector2 translation) {
        this.translation = translation;
    }

    public void render(int delta) {
        for (Node<SceneNode> node : this.getSubnodes()) {
            ((SceneNode) node).render(delta);
        }
    }

    public void renderDebug(int delta) {
        for (Node<SceneNode> node : this.getSubnodes()) {
            ((SceneNode) node).renderDebug(delta);
        }
    }

    public void update(int delta) {
        this.sceneTime += delta;

        for (IBehavior behavior : behaviors) {
            behavior.act(this);
        }

        for (Node<SceneNode> node : this.getSubnodes()) {
            ((SceneNode) node).update(delta);
        }
    }

    public SceneNode setTranslation(Vector2 translation) {
        return setTranslation(translation.x, translation.y);
    }

    public SceneNode setTranslation(float x, float y) {
        for (Node<SceneNode> node : this.getSubnodes()) {
            Vector2 offset = ((SceneNode) node).getTranslation().sub(x, y);
            ((SceneNode) node).setTranslation(offset.add(x, y));
        }
        translation.set(x, y);

        return this;
    }

    public SceneNode translate(Vector2 translation) {
        return translate(translation.x, translation.y);
    }

    public SceneNode translate(float x, float y) {
        for (Node<SceneNode> node : this.getSubnodes()) {
            ((SceneNode) node).getTranslation().add(x, y);
        }
        translation.add(x, y);

        return this;
    }

    public Vector2 getTranslation() {
        return translation;
    }

    public float getX() {
        return translation.x;
    }

    public float getY() {
        return translation.y;
    }

    public float getSceneTime() {
        return sceneTime;
    }

/**
 *
 * @author William Gervasio
 *
 */

import java.util.ArrayList;
import java.util.List;

public class Node<T> implements Cloneable {

    private List<Node<T>> subnodes;

    public Node() {
        this(new ArrayList<Node<T>>());
    }

    public Node(List<Node<T>> subnodes) {
        this.subnodes = subnodes;
    }

    public void attach(Node<T> node) {
        subnodes.add(node);
    }

    public void clearNodes() {
        subnodes.clear();
    }

    public void detach(Node<T> node) {
        subnodes.remove(node);
    }

    public void deepDetach(T node) {
        subnodes.remove(node);
        for (Node<T> i : subnodes) {
            i.deepDetach(node);
        }
    }

    public boolean hasNode(Node<T> node) {
        return subnodes.contains(node);
    }

    public List<Node<T>> getSubnodes() {
        return subnodes;
    }

    public void setSubnodes(List<Node<T>> subnodes) {
        this.subnodes = subnodes;
    }





#5004577 Android Game development

Posted by GameGeezer on 27 November 2012 - 11:26 AM

Don't think of this as an android specific problem. Your question isn't very clear, but if you're looking for collision detection and physics there is a nice android port of box2d.
http://code.google.com/p/androidbox2d/

As for the "rectangular bound bitmap," I'm unsure of what you're talking about. Rendering is done with Opengl ES and is pretty much the same as Opengl.
Take a look at andEngine, It'll make development alot easier if you're a novice.
http://www.andengine.org/


#4975127 Java tips

Posted by GameGeezer on 31 August 2012 - 06:51 AM

Java: How To Program (Published by DEITEL) is what I learned from.
or
Building java programs by stuart Reges and Marty Stepp

Both are very good books but can get a bit pricey(Most tech books do), find a used one on amazon. Like Rip-Off said noone will ever force all the information you need in game development down your throat(yes even in college most likely). You're young, kick the asses of everyone around you and be the best; all you need is drive.


#4933935 SDL selection based on color

Posted by GameGeezer on 22 April 2012 - 08:37 PM

Have a generic country object that either has a name or id you can use to idenify each country with. when a player clicks on the object check to see if that point is contained within the shape, if it is then select that country. Your method sounds a bit messy to say the least, I would really rethink how you're approaching the problem.


#4925221 circular gravity

Posted by GameGeezer on 25 March 2012 - 06:31 PM

Why not use the actual equation for gravity. Posted Image,(courtesy of Wikipedia) Since F=ma you can solve for the acceleration of each object by solving for the force and then dividing by the mass of the object being moved. I wrote this code and never ended up even testing it out so there are without a doubt some trig errors and general logic mistakes but you may use this as an outline.

public void accelerateDueToGravityAtAPoint(BaseObject object1,BaseObject object2)
{
  float dist = object1.getPosition().dist(object2.getPosition());
  float force = (float) (GRAVITATIONAL_CONSTANT *((object1.getMass()+ object2.getMass()) / Math.pow(dist,2)));

  if(object1.isStatic() == false)
  {
   float angle = (float) Math.atan(
	 (object1.getPosition().y-object2.getPosition().y)/
	 (object1.getPosition().x-object2.getPosition().x));
  
   object1.setAcceleration(new Vector2(
	 (float)(force/object1.getMass()*Math.cos(angle)), //x component of the acceleration f/m
	 (float)(force/object1.getMass()*Math.sin(angle))));//y component of the acceleration f/m
  }
  if(object2.isStatic() == false)
  {
   float angle = (float) Math.atan(
	 (object2.getPosition().y-object1.getPosition().y)/
	 (object2.getPosition().x-object1.getPosition().x));
  
   object2.setAcceleration(new Vector2(
	 (float)(force/object2.getMass()*Math.cos(angle)),
	 (float)(force/object2.getMass()*Math.sin(angle))));
  }
}
final float GRAVITATIONAL_CONSTANT = 0.00012f;

If you want your objects to rotate around their center of mass due to the force of gravity pulling them you could look at torque caused on the objects.

t =rfsin(o) // since there is no torque arm just is a constant like 1 or so for r
t = Ia //I is rotational inetia and a is rotational acceleration
Ia = rfsin(o)
a = (rfsin(o)/I

you can calculate intertia I as either a disk or a spere if you want(google rotational inertia it isn't complicated)

Then just update the objects angular velocity basted on the angular acceleration
and update your objects angular position based on that.


#4875646 Voxel Data Structure

Posted by GameGeezer on 23 October 2011 - 11:01 AM

If you don't feel like reinventing the wheel, take a look at PolyVox. I've found it very useful.


PARTNERS