Tips and Tricks for beginner game dev

Started by
8 comments, last by Looniper 8 years, 2 months ago

Recently i have been taking classes on codecademy, and i am done with java. so i know java to some degree. but i dont know how to use them to make games.

firstly i want to make some kind of text based quiz program. but i dont know how to run this quiz program, and what the code i use to define what the user is typing, if they can even type (plz tell me is this i possible and what program to run the code)

for example:

if userinput("b")

System.out.println("that is correct")

and second, i want to go on to develop a sidescroller platform game, what engine should i use and how do i like kinda link up the sprites of the character to the picture and such. can someone explain or link some tutorials that can teach me the basics of coding in gaming. i really want ot learn to code.

thx in advance ^^

Advertisement

If you want to develop a simple game in Java, I'd suggest you to learn about libgdx. It's a popular game library that is simple to use.

Code for a sample platform game using libgdx

Complete tutorial for a simple 2D game

Of course, there are many tutorials and books out there.

Hope this helps.

what program to run the code)
for example:
if userinput("b")
System.out.println
[snip]
i really want ot learn to code.


This is not a Game Design question. Programming and game design are not the same thing. Moving this to For Beginners. Please post only game design questions in the Game Design forum.

-- Tom Sloper -- sloperama.com

firstly i want to make some kind of text based quiz program
I would suggest you first focus on this one, until it's running. The first thing you need is make clear for yourself what "some kind of" means. Without knowing what you want to have exactly, it's extremely hard to write code.

(It's like writing a solution without knowing what problem you are actually solving.)

Try to make more precise what should happen at each step, in each possible case. More details is better, Even more details is even more better.

A few questions to ponder and get you going:

- What should the program print first?

- Assuming you want to ask questions in your quiz, where do these come from? What information do you need with each question?

- If you have more than one question, how do you select one for the user?

- What information should you present to the user?

- What do you expect the user to reply?

- Can you skip a question?

- Can you ask for a different question?

- How do you decide the given answer is correct or wrong?

- What happens if the user gave the wrong answer?

- What happens if the user gave the right answer?

- What if he/she replies something else? (empty text, or "I don't know", for example)

- How do you decide the program is done?

Yep lots of questions you can ask eh? :)

The more clear it becomes to you what the program should exactly do, the easier it is to code, since you don't have to think about that while coding.

and what the code i use to define what the user is typing, if they can even type (plz tell me is this i possible and what program to run the code)
You better get good at finding answers to questions like this; programming is constantly working at the edge of what you know, and often even outside that.

I don't know the answer to your questions either, but I know search engines are pretty good at coughing up links to such answers. It's unlikely that you are the first person that want to read a line of text, so no doubt someone else has already asked this very question, and got an answer.


if userinput("b")

System.out.println("that is correct")

If I understand, you're asking how to get keyboard input from the user.
Using your variable "userinput"


import java.util.Scanner;

Scanner userinput = new Scanner (System.in);


I don't often use Java so I can't recall how to test if a key is actively depressed or released, but standard input is handled by the Scanner in the standard util library.

You will need more advanced keyboard handling to make a side-scroller that responds to it.
I would suggest following one of the many tutorials on making a Flappy Bird game in Java. It will cover input, scrolling the screen, and collision/events. Then you can take the constituent aspects and fit them to your own purpose.

if userinput("b")
System.out.println("that is correct")

If I understand, you're asking how to get keyboard input from the user.
Using your variable "userinput"

import java.util.Scanner;Scanner userinput = new Scanner (System.in);
I don't often use Java so I can't recall how to test if a key is actively depressed or released, but standard input is handled by the Scanner in the standard util library.
You will need more advanced keyboard handling to make a side-scroller that responds to it.
I would suggest following one of the many tutorials on making a Flappy Bird game in Java. It will cover input, scrolling the screen, and collision/events. Then you can take the constituent aspects and fit them to your own purpose.
Thank you so much this was really enlightning. I will try the flappy bird thing. And thank you everyone else. One more question tho.
I i have to type
Import java.util.Arraylist to use arraylist. Because thats mainly what i want to be using to store the different answers, and then print each arraylist to the console using a FOR EACH loop. If you know what i mean.

Import java.util.Arraylist to use arraylist.

--
Edited, Never mind, I misunderstood what you were asking.

Arraylist has a different (but similar) syntax.

firstly i want to make some kind of text based quiz program

I would suggest you first focus on this one, until it's running. The first thing you need is make clear for yourself what "some kind of" means. Without knowing what you want to have exactly, it's extremely hard to write code.
(It's like writing a solution without knowing what problem you are actually solving.)

Try to make more precise what should happen at each step, in each possible case. More details is better, Even more details is even more better.
A few questions to ponder and get you going:
- What should the program print first?

- Assuming you want to ask questions in your quiz, where do these come from? What information do you need with each question?
- If you have more than one question, how do you select one for the user?
- What information should you present to the user?
- What do you expect the user to reply?
- Can you skip a question?
- Can you ask for a different question?
- How do you decide the given answer is correct or wrong?
- What happens if the user gave the wrong answer?
- What happens if the user gave the right answer?
- What if he/she replies something else? (empty text, or "I don't know", for example)
- How do you decide the program is done?

Yep lots of questions you can ask eh? :)


The more clear it becomes to you what the program should exactly do, the easier it is to code, since you don't have to think about that while coding.


and what the code i use to define what the user is typing, if they can even type (plz tell me is this i possible and what program to run the code)

You better get good at finding answers to questions like this; programming is constantly working at the edge of what you know, and often even outside that.
I don't know the answer to your questions either, but I know search engines are pretty good at coughing up links to such answers. It's unlikely that you are the first person that want to read a line of text, so no doubt someone else has already asked this very question, and got an answer.
Thx dude for your answer.

Well

- i want the questiona to come in a line kinda.

ArrayList<String> alternatives = new ArrayList<string>;

Alternatives.add("A, example");
Alternatives.add("B, example");
Alternatives.add("C, example");

System.out.println("example question A");

for (ArrayList : alternatives);

If userinput = "B"

System.out.println("that is correct");

System.out.println("example question B");

Else if

System.out.println("wrong answer")

//User input is what the user types into the console program. What program do i use to run such a text based jav program excactly

- no you should not be able to skip or change. That would be to difficult for me.

- I expect them to type in A, B or C (or maby even D(?))^^

But would this program i listed be usable in theori? And what do i run it in. Btw currently using notepad++.

//User input is what the user types into the console program. What program do i use to run such a text based jav program excactly
At the lowest level, the Java compiler, and the Java interpreter. They come in a JDK (Java Development Kit). Note this is different from a JRE (Java Runtim Environment), which only contains the Java interpreter.

The Java compiler translates your program text to byte-code (a machine-usable form of your program). The Java interpreter takes the byte-code, and then runs it.

"The lowest level" here means you have to type a command-line command to run the compile and the interpreter. While it's a useful skill in its own, people are inherently lazy, and wrote programs that do this thing for you, which leads to your second question

And what do i run it in. Btw currently using notepad++
I am not a Windows user, but I heard notepad++ is quite useful. I don't know if it can handle compilation and execution of Java programs. But as with all the other questions that look like someone else may already have run into it, it's worth trying a search engine with a few keywords like "notepad++ java compile" or "notepad++ java run" or so. 99.9% of these things are simply available by looking for it.

If notepad++ doesn't seem to work for you, there are a zillion other Java editors. I use Eclipse (you'd need Eclipse JDT). It's an IDE, an integrated development system with editor, a compiler, and a way to run programs, all in one. You can type Java code, (and the editor helps you, as it understand Java too), and with a simple click you can run the code as well.

For more information (yep, it's another of those 99.9% questions), try searching with something like "java eclipse development getting started".


But would this program i listed be usable in theori? And what do i run it in. Btw currently using notepad++.

The logic is sound, but I don't know if the syntax is all correct. (I need to get jdk on this machine)

To run it you use the same two steps that you would usually use.
Assuming that you call the document "test.java" and the class is called "choices"
Open the DOS console (CMD)
go to where you saved.
javac test.java

-- creates a file containing the class as bytecode

java choices

-- loads the class into the java interpreter

Notepad++ is designed as a source code editor, and a very good one at that, not an IDE.
You can make it work as one, however.
Notepad++ as a Java IDE
This link walks you through setting it up to compile and run your java.

Or there are NetBeans, Eclipse, and several other Java IDEs available for download.

This topic is closed to new replies.

Advertisement