GPWiki.org
GPWiki.org
It is currently Wed May 22, 2013 5:13 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Dec 08, 2012 3:09 am 
Hello
I have a game engine with the standard game loop format, but its poorly structured how can I use a class like this one to reuse code for each classes ?

Ive seen it done but I don't yet understand how to use.


Code:

/*
  Every individual object will inherit its variables from this class
  and not have to declare its own only for its overloaded constructos to initialise them.
*/

package game;
import java.awt.Rectangle;


abstract public class Sprite
{   
    public int x ;
    public int y ;
    public float xVel ;
    public float yVel ;
    public int width ;
    public int height ;
    public int gravity ;   
    public boolean falling ;
    public boolean readyToFallFromLedgeAndFalling ;
    public boolean jumping ;
    Rectangle collision_bounds ;
   
        public void isFalling()
        {
           
        }
        public void isJumping()
        {
           
        }
        // ....... other
}



Top
  
 
PostPosted: Sun Dec 09, 2012 8:22 pm 
Level 1 Cleric
User avatar

Joined: Sun Nov 11, 2012 8:11 am
Posts: 10
Location: Toronto
You're going to want to have an array which stores every instance of Sprite, including any instance which inherits Sprite.

In the game loop, you're going to want to loop through the array executing Update of every instance, then again doing the draw functions.

Each object would inherit Sprite's drawing and update functions, overloading when necessary and from there all you need to do is fill in the blanks for each object.

I'm not experienced with java, but here's some example JavaScript. So, for example I have a state machine and I'm viewing the game, every update of that state we'll call this function. currentstate.draw would then draw all the map objects by running the following function.
Code:
function mapobject_draw(visuals)   
{
   for(i=0; i<mapobjectArray.length;i++)
      {
      mapobjectArray[i].draw(visuals);
      }
}



I hope that helps.

_________________
http://ryanspice.com/


Top
 Profile  
 
PostPosted: Fri Apr 19, 2013 8:12 am 
Bit Baby

Joined: Thu Apr 18, 2013 6:19 am
Posts: 8
That I do not really understand, so come learn about.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group