We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Newb who wants to make game
Pages: 1 2 3 
Newb who wants to make game (Read 7770 times)
Re: Newb who wants to make game
Reply #15 - Jan 17th, 2007, 2:45am
 
Believe it or not I actually get all of both of those programs. The game is going to be very simple so I doubt the game engine will not work with the graphics. Thanks for the draw() and setup() functions Im obviously going to need them to make a game. I think with a slight bit of tweaking I can make the image move with the keys. Are there any functions that work if images intersect? Im definitely going to need one for my game to work easily. Eg, there is a picture of the floor and the guy moves down untill he reaches the floor or a platform. GRAVITY! If there arent then it would save me a lot of trouble of plotting all the images exact coordinates just to use built in rectangles and circles like the bot program.
Re: Newb who wants to make game
Reply #16 - Jan 17th, 2007, 2:13pm
 
You'll have to do all the movement/collison/gravity stuff yourself I'm afraid, there's no generic functions to do it.
Re: Newb who wants to make game
Reply #17 - Jan 17th, 2007, 5:48pm
 
Here's the basic framework to get you started, as shown from other people's examples

Code:


//everything that you want to load should be taken care of here
void setup(){

//define your screen size
size(500,500);

}

//this gets called every frame and draws to screen
void draw(){

//draw a black background
background(0);

}

//whenever your mouse is pressed, this gets called
void mousePressed(){

//if you don't believe me, uncomment the following
//println("mouse is pressed!");
//println("mouse was at " + mouseX + ", " + mouseY);
}

//whenever your keyboard is touched, this gets called
void keyPressed(){

//println("the key that was pressed: " + key);

}





And then on a seperate "tab" for neatness sakes you can implement your objects for your game, like characters, enemies, physics engines, what have you.
Re: Newb who wants to make game
Reply #18 - Jan 18th, 2007, 12:11am
 
Sorry for having to bug you with the animation stuff, but I think I'm just going to use 2D primitives for the game just to make it that much simpler. also, I'm going to scram the gravity concept. once i've made my first game then I could figure out how to do them but I want to make a semi easy program first. I think il go for an asteroids-type game but with levels.
I'l keep you posted once I have some code
Re: Newb who wants to make game
Reply #19 - Jan 19th, 2007, 6:30pm
 
Well, my idea for the primitives would be far too hard to make  becouse I would have to do some serious equations and geometry so Im going to use my original Idea. I've gotten the mask function to work how I want and I just going to use boxes around the sprites for collisions. I should be able to figure it out on my own. Im just trying to change your first animation syntax to my liking. Then Im going to work on the physics and movement. The one problem is that Im having a little trouble to get the private funcions to work. Il figure it out and keep you posted keep you posted.
Re: Newb who wants to make game
Reply #20 - Jan 19th, 2007, 7:01pm
 
I modified the original animated sprite code so that it indluded a mask burt im having trouble putting the sprite index into it. heres whats listed under setup:

 PImage mframe[];
 mframe = new PImage[4];
 PImage mframemask[];
 mframemask = new PImage[4];
 int mcurrframe = 0;
 mframe[0] = loadImage("pyros1.bmp");
 mframe[1] = loadImage("pyros2.bmp");
 mframe[2] = loadImage("pyros3.bmp");
 mframe[3] = loadImage("pyros4.bmp");
 mframemask[0] = loadImage("pyros1mask.bmp");
 mframemask[1] = loadImage("pyros2mask.bmp");
 mframemask[2] = loadImage("pyros3mask.bmp");
 mframemask[3] = loadImage("pyros4mask.bmp");
 ASprite pyros = new ASprite(mframe[0], mframe[1], mframe[2], mframe[3],  mframemask[0], mframemask[1], mframemask[2], mframemask[3], 30);

and then the class has this listed under it:

ASprite(PImage[] f,PImage[] m, float fps)
 {
   frames = f;
   maskf = m;
   frameLength = 1000/fps; // set frameLength in milliseconds
   currFrame = 0;
   timer = millis();
   x = 0;
   y = 0;
 }

I keep getting an error that says that im not indexing the pictures right. How do I list them so they are put into the array properly?
Re: Newb who wants to make game
Reply #21 - Jan 19th, 2007, 8:51pm
 
An array is a single item (despite having many parts).

So for a function asking for:

ASprite(PImage[] f,PImage[] m, float fps)

you would give it:

ASprite pyros = new ASprite(mframe,  mframemask, 30);

You can't give a function the wrong number of parameters, ASprite takes 3, so it will throw its toys out of the pram if you don't give it 3 or don't provide another method that accepts what you're providing.

And if you've got files ending in numbers you could make life easier by doing this:
Code:

PImage [] pimage = new PImage[10];
for(int i = 0; i < pimage.length; i++){
pimage[i] = loadImage("myimage"+i+".jpg");
}
Re: Newb who wants to make game
Reply #22 - Jan 20th, 2007, 3:28am
 
Ok so I finally got the animation to work so Im starting on the physics. Is draw() the only funstion that gets repeated every frame? or can I make a new one that gets repeated every second or so that I can put in a different tab and run parallel with draw()? Thanks for the help so far, I know the basics now and just need help on some of the more discreet concepts
Re: Newb who wants to make game
Reply #23 - Jan 20th, 2007, 5:09pm
 
The procedural nature of computers is fairly ubiquitous. If you want to work with computers you should generally have the mind set that everything you're going to do is going to run like so:
  • Action 1
  • Action 2
  • Action 3
  • Action 4
  • Action 5

    So you would design what's going in to draw() in some magic order and accept the intrinsically non-parallel nature of computers today.

    Or you can research threads.
  • Re: Newb who wants to make game
    Reply #24 - Jan 20th, 2007, 10:48pm
     
    I think what he wants is

    Code:

    void draw(){

    //draw something

    anotherFunction();

    }

    void anotherFunction(){
    //do something else!
    }



    Am I right?


    Otherwise yes.. multi-threads are fun but it would overcomplicate your project at this stage. I find that you shouldn't ever need it unless you are doing some form of network data or data streaming.
    Re: Newb who wants to make game
    Reply #25 - Jan 21st, 2007, 3:05am
     
    As much as I would LOVe to do a multithreaded game, it would only overcomplicate a simple game. I will just execute all of my functions using draw and by using the thing you suggested. I need a little advice on one part though. I've sucessfully put in animations and made movement of the character.

    There are two things I need help on. First, is that I used if statements under keypressed() to make movement (if (keyCode == UP) then move up etc) but the movement starts out sluggish before getting up to speed. I tried using while keyCode == UP in essentially the same way but the program freezed as soon as I pushed UP. Is there any way to get the while to work or to get rid of the sluggishness?

    Second, to do the intersections, I am making a class for eac different guy which has their collision size in it (basically a rectangle with coordinates). In order to simplify the collision, I need to be able to get the class to return its built in coordinates at command. How can I get the class to return integers on command which it has stored? Even if the integer is private, I should be able to make a function of the class to make it return the integer right?

    Thanks, You guys have been a huge help so far
    Re: Newb who wants to make game
    Reply #26 - Jan 21st, 2007, 11:14am
     
    For the key stuff, the best idea is to have a boolean storing the state, e.g.

    Code:
    boolean keyUP=false;

    void keyPressed()
    {
    if(keyCode==UP)
    keyUP=true;
    }

    void keyReleased()
    {
    if(keyCode==UP)
    keyUP=false;
    }


    So keyUP will be true whilst the key is held down.

    As for the intersect, I think you may be better only having one class for guys, with variables for all the difference between them.
    e.g.
    Code:
    class guy
    {
    int posx,posy;
    int boxWidth,boxHeight;
    PImage[] frames;

    guy(int px, int py, int bw, int bh, PImage[] a, PImage[] b)
    {
    posx=ps;
    posy=py;
    boxWidth=bw;
    bohHeight=bh;
    for(int i=0;i<a.length;i++)
    {
    a[i].mask(b[i]);
    }

    }

    // a function to give the boxWidth
    int getBoxWidth()
    {
    return boxWidth;
    }
    }


    The reason for this is that if you have different classes, even though they have the same functions it's very hard to use them in the same way without having lots and lots and lots of code doing the same thing over and over, instead of just looping through an array of guys.
    Re: Newb who wants to make game
    Reply #27 - Jan 21st, 2007, 5:06pm
     
    Ok everything so far is working. The one thing I need now is a way to flip the picture horizontally. Is there a way to do this in processing? Either using a command/ built in function or a relatively easy way of making my own function. If it is too complicated then I an just flip the pictures in Paint and import them into the library as a different name then call them up as something else. The one problem with this is that I'm trying to keep the game small a flipped version of the same picture uses up valuable space. Thanks for the keyReleased thing, thats really useful.
    Re: Newb who wants to make game
    Reply #28 - Jan 21st, 2007, 6:40pm
     
    Code:

    PImage source, target, back;
    void setup(){
    size(400, 400);
    for(int i = 0; i < 1000; i++){
    fill(random(255));
    rect(random(width), random(height), 50, 50);
    }
    source = get();
    target = new PImage(width, height);
    for(int x = 0; x < source.width; x++){
    for(int y = 0; y < source.height; y++){
    target.pixels[(width - 1) - x + y * width] = source.pixels[x + y * width];
    }
    }

    back = source;
    }
    void draw(){
    image(back, 0, 0);
    }
    void mousePressed(){
    if(back == source){
    back = target;
    } else {
    back = source;
    }
    }
    Re: Newb who wants to make game
    Reply #29 - Jan 23rd, 2007, 6:42pm
     
    Quote:
    Can ANYONE tell me how to get a game up and running. (...) I hope this experience will allow me to get a good understanding at java and programming.


    <grin> It propably will, but you're propably in for quite a lot, so take your time with this, start small and try to build up step by step. I would like to heavily recommend http://fivedots.coe.psu.ac.th/~ad/jg which IMHO provides a good introduction on the subject and covers all techniques you will need to get succesfully going.
    Pages: 1 2 3