Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (682)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (750)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 3 4 [5] 6 7 ... 10
 41 
 on: 2016-07-20 20:35:19 
Started by OrangeRange - Last post by OrangeRange
Hi guys, I'm new here, not so new at codding (but I'm in no way a pro) and new at creating a game.

I'm creating a simple text game that runs through a GUI, no interaction or action will be made using command lines, only (mostly) using buttons (I know that this isn't exactly a text game).
This is how it will to run:

A main method in a Main class will call the OpenGame class:

1  
2  
new OpenGame().setVisible(true);
// This class extends JFrame, here the user will start a new game or load an existing one


Let's say that I want to start a new game, I'll click in the "New" button:

1  
2  
3  
4  
private void btnNewGameActionPerformed(java.awt.event.ActionEvent evt) {                                           
    this.dispose();
    new Game(GameMode.NEW); // I'll remove "GameMode" later, don't know if I'll keep using it
}


The Game class will have all of the info in the game, like the character created, list of npcs, list of locations and etc (ignore the fact that all variables are public or static, I'll change that later):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
public class Game
{
    public static final int MAXNPCS = 20;
    public static int dayCount;
    public static GameMode gameMode = GameMode.OPEN; // enum
    public EnumWeek currentDay; // enum
    public ActivityType currentActivity;    
    public Player player;    
    public ArrayList<NPC> npcs;    
    public ArrayList<Location> locations;
    public ArrayList<ActivityType> availableActivities; // enum
    public ArrayList<ActionType> availableActions; // enum
    public ArrayList<OptionType> availableOptions; // enum
    public MainWindow gameWindow; // This class extends JFrame, the contents of this JFrame will be changed with one of the following JPanels
    public GamePanel gamePanel; // This class extends JPanel, all of the interactions and conversations will happen here, it is a text area, some labels and buttons to execute the action the user wants
    public PlanningPanel planningPanel; // This class extends JPanel
    public CreateNewCharPanel newCharPanel; // This class extends JPanel
       
    private NPC npcTemp;
    private Location locationTemp;
   
    public Game(GameMode gm)
    {
        if(gm.equals(GameMode.NEW))
        {
            gameMode = GameMode.NEW;
            startNewGame();
        }
        else
            System.err.println("Invalid option");
    }
   
    public void startNewGame()
    {
        player = new Player();
        locationTemp = new Location();
        npcTemp = new NPC();
        locations = new ArrayList<>();
        npcs = new ArrayList<NPC>();
        dayCount = 0;
        currentDay = EnumWeek.SUNDAY;
        currentActivity = ActivityType.INTRO;
        availableActivities =  new ArrayList<>();
        availableActions = new ArrayList<>();
        availableOptions = new ArrayList<>();
        gameWindow = new MainWindow();
        gamePanel = new GamePanel();
        planningPanel = new PlanningPanel();
   newCharPanel = CreateNewCharPanel();
       
        // this will generate everything the game needs (at this point, its used only for tests):
        player = player.generatePlayer(player);
        npcs = npcTemp.generateNPCs(MAXNPCS);
        locations = locationTemp.generateLocations();
        availableActivities = currentDay.availableActivities(availableActivities);
       
        showGameWindow();
    }
   
    public void showGameWindow()
    {
        // some look and feel code here
        gameWindow.setVisible(true);
    }
}


I didn't include the code here, but right now, the game will be setting the gameWindow with the contents of gamePanel to show the user the intro (a short story).
Now my problems begin, I know how to show, hide or remove JPanels from a JFrame, but once gamePanel starts playing the intro and finishes it (after the user clicks on "Next" button), I don't know how to go back and "tell" the Game class that the currentActivity is finished, set the currentActivity with "NEWCHAR", set the gameWindow with the contents of newCharPanel and so on (this is the only moment that I know for sure which activity will be the next activity, after the game is "really" started or loaded, its up to the user).

I don't know if this is relevant, but I'm using NetBeans and already created the game's GUI using NetBeans.

I have read about state machines, game loops, analised code from projects like https://github.com/Progether/JAdventure and https://github.com/DanielKoren/Game-State-Manager, but I haven't had any success in implementing something that suits my needs.

Is it possible to do what I want or have I been doing it the wrong way since the begining? Can someone help me?

 42 
 on: 2016-07-20 19:27:27 
Started by BurntPizza - Last post by Ecumene
-snip-

(this is a bit loud)
<a href="http://www.youtube.com/v/Nke0Gj2SUOs?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/Nke0Gj2SUOs?version=3&amp;hl=en_US&amp;start=</a>

 43 
 on: 2016-07-20 18:41:30 
Started by matt_p - Last post by Riven
If someone with the necessary power reads this: You can close this ticket if you want to, as it solved  Wink
This is not how this forum works Smiley What if somebody wanted to add some other piece of wisdom? (Or share a good joke about... ehm... buffers!)

You can put [solved] in the subject-line though, the forum will turn it into a pretty little picture.


 44 
 on: 2016-07-20 16:04:29 
Started by matt_p - Last post by matt_p
You don't necessarily need to use BufferUtils, just use BytrBuffer.allocateDirect then use the put method of the ByteBuffer to load the array data in to the buffer. BufferUtils is a useful utility method but it hides things you should really know about.

No worries, I checked the Source of BufferUtils and found out that the methods I use now do exactly what I would have done manually.


Since I'm home now I changed the code and now everything works as expected.

Thanks again Spasi!


If someone with the necessary power reads this: You can close this ticket if you want to, as it solved  Wink

 45 
 on: 2016-07-20 14:05:54 
Started by matt_p - Last post by Spasi
You don't necessarily need to use BufferUtils, just use BytrBuffer.allocateDirect then use the put method of the ByteBuffer to load the array data in to the buffer. BufferUtils is a useful utility method but it hides things you should really know about.

BufferUtils doesn't hide anything. It uses ByteBuffer.allocateDirect and sets the byte order to ByteOrder.nativeOrder(). Unless you're doing something very specialized (e.g. low-level networking), using the native byte order is exactly what you want. Actually, not setting the byte order has always been one of the most common issues new LWJGL users face.

As for allocateDirect itself, the post explains why avoiding it is a good idea. In LWJGL code I write, this is my decision process (from most-to-least preferred):

1) Is it a short buffer/struct that is created, used and discarded locally*? Use MemoryStack for stack allocations.
2) Is it trivial to manually free the buffer/struct? Or, is the allocation in a performance sensitive path? Use MemoryUtil for the explicit alloc/free functionality.
3) Use BufferUtils.
...
32767) Use ByteBuffer.allocateDirect() directly.

* "Local" could apply to any allocation with a lifetime of a single method up to a single frame (e.g. in the scope of the main loop).

 46 
 on: 2016-07-20 13:47:26 
Started by matt_p - Last post by ziozio
You don't necessarily need to use BufferUtils, just use BytrBuffer.allocateDirect then use the put method of the ByteBuffer to load the array data in to the buffer. BufferUtils is a useful utility method but it hides things you should really know about.

 47 
 on: 2016-07-20 13:01:11 
Started by BurntPizza - Last post by EgonOlsen
I'm on holiday. So I made a C64 out of sand.


 48 
 on: 2016-07-20 11:19:22 
Started by BurntPizza - Last post by ziozio
Philfrei is correct, for vorbis the entire decoding is done using floats and is then converted to bytes when creating the byte buffer for openal

The float buffer is structured so that channel data is sequential so it would be channel1, channel2....channel,channel1, channel2...channel etc

As the float array is created during decoding you aren't  losing much and you aren't using more memory. I do agree that a pojo is a good way to collate all the raw pcm data in to a separate object

 49 
 on: 2016-07-20 09:27:15 
Started by printer - Last post by printer
Well i think i'm on the right way. I'm using a second camera and font gets drawn right. But problem is that, if player moves, the text moves with him and do not stand still above monster head.

 50 
 on: 2016-07-20 09:18:15 
Started by purenickery - Last post by J0
MS paint? Shocked

(Also, not going to write about the fact that it looks more and more amazing... Oh wait...)

Pages: 1 ... 3 4 [5] 6 7 ... 10
 
orrenravid (136 views)
2016-07-16 03:57:23

theagentd (205 views)
2016-07-11 14:28:54

Hydroque (288 views)
2016-07-06 05:56:57

Hydroque (436 views)
2016-07-03 08:52:54

GrandCastle (320 views)
2016-07-01 09:13:47

GrandCastle (315 views)
2016-07-01 09:09:45

CopyableCougar4 (370 views)
2016-06-25 16:56:52

Hydroque (358 views)
2016-06-22 02:17:53

SwampChicken (328 views)
2016-06-20 13:22:57

SwampChicken (281 views)
2016-06-20 13:22:49
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!