Java topics needed to learn game dev

Hi,
What is the java knowledge required to learn java game development using a game api like libgdx or slick2d along with box2d physics. I would like to start 2D, I already have some java knowledge and was going to get this book:http://www.amazon.co.uk/Learning-Libgdx-Development-Andreas-Oehlke/dp/1782166041

I don’t have a lot experience using libraries. But learning object oriented programming is a good start. Knowing how to make and use your objects makes game programming so much simpler, learning how to use libraries after that makes it more powerfull (I guess powerfull is the right term here? :D)

I know how to create objects and use them and even constructor methods and methods but I cant get what is happening in inheritance, is it all jsut for you can use variables and methods from the clss your implementing, ex public class game extends player implements car . What does it mean?

It sounds like you need to learn java. Don’t get too excited and jump into making games or else you will just give up. There are many tutorials and I think that we have a thread on this site for java tutorials (just use the search bar). You can go check out thenewboston on YouTube for java tutorials also.

Again, just to repeat myself, DONT jump straight into games. Learn java first.

If you want some good books on OO programming, check out Object Oriented Programming books from O’reilly. Also check out their book about Design Patterns. It may be quite some effort you need to put into learning OO programming, but it makes programming much easier and understandable.

If you want to be a good programmer, make sure you know how to use Object Oriented programming and how to apply Design Patterns.

Dont get me wrong I know switch statements,loops,constructor,variables,conditionals,arrays,parameters,arguments,Object oriented, methods, constructor and today I learned inheritance. What is something that is crucial like a topic or function so i can learn it, i had a school project for java which I had been learning for a year. I got 14/15.

Grades mean nothing. I could fail a math test and still know what I’m doing, I just may not have decided to try on the test or misunderstood instructions, wasn’t prepared etc…

Like other people have said, you need to know Java first and the basic concepts of OO. Its not very good that you just learned inheritance, that tells me you really haven’t ventured far into the language yet.

There’s also no set amount of knowledge you need to know to make games. Just know Java, that’s it. After that point its up to you to utilize what you have learned. You don’t need to know everything, but knowing the basics is really recommended. Just study more Java first and then come back to game dev.

As much as I’m happy for the excitement you have trying to “jump” into something like Slick2D and LibGDX, these people are correct. If you do not “feel” the language (being able to write code with your eyes closed), you are going to have a rough time understanding how to work these engines. The reasoning is that with school, you are only scratching the surface. They teach you the variables, functions, and syntax. However, learning when and how to use this syntax is a whole different beast. There are a lot of different design patterns once you’ve breached the surface of learning the basics.

How do I get past this defense…

Tutorials. Literally it is the difference between trying to jump across an open chasm or taking a convenient bridge. If you look for the tutorials or grab books on the subject you are trying to learn, you have a much better chance of not “falling to your death” trying to understand concepts. You’ll probably learn a lot more as well, since, game development takes a lot more than simple programming knowledge.

Game development is only difficult for those who didn’t take time to fortify. Everyone always thinks that coming in with a shaky sand castle will guarantee you’ll survive the waves. However, those who read the tutorials already had the knowledge to build up a wall. Always brace yourself for impact by learning the tutorials, so when the “big wave” of problems come… you’ll be ready.

I can code well in java without any tutorial or copying any code, Give me a sort of small project which I need to complete before stepping in to games.

Pong. :wink: Then go upwards from there :slight_smile:

People often say learn the language before you start making games, this is good advice for any real game, but there’s a lot to be learned from making mini games.

step 1: draw a square or an image on the screen and get it to move with the arrow keys.
step 2: add some things that the square has to run over to collect points.
step 3: add some things which move around semi-randomly and kill the player if they touch them.

You can do all this without knowing much about programming, but you will learn things about both programming in general and making games, by making little game-like programs. Each time you complete something simple you will come up with new ideas to try out based on the experience you are building up.

Thankyou ;D

[quote]Java topics needed to learn game dev
[/quote]
Did they? Really? :wink:

Just created a program with some help from the net which draws a rectangle , and lets you move it with the arrow keys. How Can I improve the code design and improve the overall program to work better.

Here is the code:

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.*;

import javax.swing.JFrame;
import javax.swing.JTextField;

public class Main extends JFrame implements KeyListener{

int rectX = 50;
int rectY = 250;

//constructor
public Main(){
	this.setTitle("Draw Rectangle Project");
 	this.setSize(800,480);
    this.setVisible(true);
    this.setResizable(false);
	this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	addKeyListener(this);
			
}


@Override
public void keyPressed(KeyEvent e) {
	if(e.getKeyCode() == KeyEvent.VK_LEFT) {
		rectX = rectX -20;
	    repaint();
	}
	if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
		rectX = rectX + 20;
		repaint();
	}
	
	if(e.getKeyCode() == KeyEvent.VK_UP) {
		rectY = rectY - 20;
		repaint();
	}
	
	if(e.getKeyCode() == KeyEvent.VK_DOWN) {
		rectY = rectY + 20;
		repaint();
	}
}

@Override
public void keyReleased(KeyEvent e) {
	// TODO Auto-generated method stub
	
}

@Override
public void keyTyped(KeyEvent e) {
	// TODO Auto-generated method stub
	
}

public void paint(Graphics g){
	
	g.setColor(Color.RED);
	g.drawRect(rectX, rectY, 20, 20);
	g.setColor(Color.black);
	g.setFont(new Font("TimesRoman", Font.PLAIN, 20));
	g.drawString("Use arrow keys to move the rectangle",230,40);
			
}

public static void main(String[] args){
	Main object = new Main();
	
}

}

That’s fine for what it does, you could go crazy and implement various OOP ways of handling any number of rectangles, or make them change color, etc, but for moving 1 rectangle, that it fine.

One little logical nitpick:


@Override
   public void keyPressed(KeyEvent e) {
      if(e.getKeyCode() == KeyEvent.VK_LEFT) {
         rectX = rectX -20;
          repaint();
      }
      if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
         rectX = rectX + 20;
         repaint();
      }
      
      if(e.getKeyCode() == KeyEvent.VK_UP) {
         rectY = rectY - 20;
         repaint();
      }
      
      if(e.getKeyCode() == KeyEvent.VK_DOWN) {
         rectY = rectY + 20;
         repaint();
      }
   }

Can be reduced (simplified) to:


@Override
   public void keyPressed(KeyEvent e) {
      if(e.getKeyCode() == KeyEvent.VK_LEFT) {
         rectX = rectX -20;
      }
      if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
         rectX = rectX + 20;
      }
      
      if(e.getKeyCode() == KeyEvent.VK_UP) {
         rectY = rectY - 20;
      }
      
      if(e.getKeyCode() == KeyEvent.VK_DOWN) {
         rectY = rectY + 20;
      }
      repaint(); //this happens in any of the if-branches, so just hoist it out. Reduces code duplication.
   }

Also, to format code like that, put it in [code][/code] tags, or click the button with the pound sign (’#’).

You should learn about gameloops since they are the backbone to every game :slight_smile:

Agreed, there is a good introduction in the Articles and Tutorials board, but one should also recognize that his app does have a game loop, albeit a non-continuous one, which is actually just fine for the purpose of the app.

I was going to try to search for a book which could explain everything for me for example why do you always have to sue KeyEvent in the parameters of keyPressed and keyReleased and keyTyped.

And walk me through game development step by step and at last maybe I could develop a 2d paltformer without copying or searching for any code.

I looked at some code on stackoverflow and other websites to do this program.

What is the difference between these 3 : inheritance vs polymorphism vs implementation

I’m going to try to help you understand those things the best I can.

First to understand what the point of all this “inheritance” or “polymorphism” is, you must understand that the programmer (you) must try to never write the same code over and over again.

Quick example. We have 3 classes called “Apple”, “Orange”, and “Banana”. These three classes will have some similar properties, for instance, they share these methods : “public void eat()” and “public void throw()”.

However only Orange and Banana have the “public void peel()” method.

class Apple {
   public void takeOutAppleSeeds() {
       for (Seed aSeed : AppleSeeds) {
           remove(aSeed);
       }
   }
   
   public void eat() {
      bite();
      chew();
      swallow();
   }
   public void throw() {
      if (someoneIsNearMe()) {
         tossAt(personNearMe());
      } else {
         //do nothing
      }
   }
}
class Orange{
   public void eat() {
      bite();
      chew();
      swallow();
   }
   public void throw() {
      if (someoneIsNearMe()) {
         tossAt(personNearMe());
      } else {
         //do nothing
      }
   }
   
   public void peel() {
      removeSkin();
   }
}
class Banana {
   public void eat() {
      bite();
      chew();
      swallow();
   }
   public void throw() {
      if (someoneIsNearMe()) {
         tossAt(personNearMe());
      } else {
         //do nothing
      }
   }
   
   public void peel() {
      removeSkin();
   }
}

Now you can see how these classes are very similar (because they share common fields) but also different (some have methods that others do not, they are not identical).

So see how the code is repeating itself? These 3 classes are all fruit, except they extend what a fruit is. These fruit should use code from a parent class.

We know every extension of what a fruit is must be able to be eaten, and thrown. And for all the fruits listed above, they are all eaten and thrown in the same way. This is the fruit class :

class Fruit {
   public void eat() {
      bite();
      chew();
      swallow();
   }
   public void throw() {
      if (someoneIsNearMe()) {
         tossAt(personNearMe());
      } else {
         //do nothing
      }
   }
}

Now we can build off of that fruit class, extend it, because all of the following fruit need the methods in the Fruit class anyway.

class Apple extends Fruit {
      public void takeOutAppleSeeds() {
       for (Seed aSeed : AppleSeeds) {
           remove(aSeed);
       }
   }
}

Now if we create a new apple with :

Apple saucysApple = new Apple();

We can use the methods that it INHERITED from its parent class Fruit!
(Get it? Thats why its called inheritance!)

saucysApple.takeOutAppleSeeds();
saucysApple.eat();
saucysApple.throw();

Cool right? I really hope your getting it by now. Cause i’m getting tired of typing.

where do you create the sauceyapple object in the apple class or fruit class?
also what is the difference than creating an instance(object of the class) than inehritance.
ex


public class fruit {
       public static void main(String[] args]{
        
        Apple sauceyApple = new Apple();
        sauceyApple.eat(); 
        sauceyApple.throw();
         etc etc etc


       }

}


public class Apple{

    public void eat(){
    //instructions here
    }
    public void throw(){
     //instructions here
    }

}