Robertvokac (talk | contribs) No edit summary |
Robertvokac (talk | contribs) No edit summary |
||
Line 166: | Line 166: | ||
== Java annotations == | == Java annotations == | ||
Open Eggbert uses subset of Java 11 to reach the ability to be multiplatform (Desktop, GWT, Android) | Open Eggbert uses subset of Java 11 to reach the ability to be multiplatform (Desktop, GWT, Android) | ||
== Implementing jumping without Box2D == | |||
To implement a jump mechanic in LibGDX without using Box2D, you can follow these steps: | |||
1. **Define Variables:** | |||
- Create variables for the player's velocity, gravity, and whether the player is on the ground. | |||
```java | |||
float velocityY = 0; | |||
final float gravity = -0.5f; | |||
boolean onGround = true; | |||
``` | |||
2. **Jump Logic:** | |||
- Implement the jump by applying an upward velocity when the jump key is pressed and the player is on the ground. | |||
```java | |||
if (Gdx.input.isKeyPressed(Input.Keys.SPACE) && onGround) { | |||
velocityY = 10; // Jump strength | |||
onGround = false; | |||
} | |||
``` | |||
3. **Apply Gravity:** | |||
- Continuously apply gravity to the player's vertical velocity. | |||
```java | |||
velocityY += gravity; | |||
``` | |||
4. **Update Player Position:** | |||
- Update the player's Y position using the current velocity. | |||
```java | |||
player.y += velocityY; | |||
``` | |||
5. **Ground Detection:** | |||
- Check if the player has landed back on the ground to reset the jump. | |||
```java | |||
if (player.y <= groundLevel) { | |||
player.y = groundLevel; | |||
velocityY = 0; | |||
onGround = true; | |||
} | |||
``` | |||
By following these steps, you create a basic jumping mechanic where the player can jump when on the ground, and gravity pulls them back down. This can be expanded with more complex mechanics like double jumps or variable jump heights. | |||
== Discussion == | == Discussion == |
Revision as of 16:15, 31 August 2024
Multiplatform
Open Eggbert is multiplatform (desktop, Android, web).
- We should assure continuously, that the latest version (snapshot) runs correctly on all the 3 supported platforms.
This means some limitations: Only feature of Java 11 source code level are supported, but even some Java 11 features are not supported in GWT.
- Method String.lines(String string) is not present in GWT.
- How to fix: Use method OpenEggbertUtils.lines(String string)
- Method Stream.toList() is not present in GWT
- How to fix: Use Stream.collect(Collectors.toList())
Inspiration
https://github.com/libgdx/libgdx-demo-cuboc
Requirements for Development
Java 17 must be installed. Newer versions may work only for the desktop.
Java 11
Targeting Java 11 and GWT. GTW contains a subset of the Java standard library.
Sound + Midi support
https://github.com/mgsx-dev/gdx-pd
Graphics
How to scale graphics - ?
https://github.com/leonbloy/pngj
https://www.nayuki.io/page/png-library
https://github.com/nayuki/BMP-IO?tab=readme-ov-file
https://www.nayuki.io/page/bmp-io-library-java
https://github.com/PyroSamurai/JBL
https://github.com/nayuki/PNG-library
https://image4j.sourceforge.net/
https://libgdxinfo.wordpress.com/basic_image/
Animation
https://github.com/WinterAlexander/gdx-animation
https://libgdx.com/wiki/graphics/2d/2d-animation
https://gamefromscratch.com/libgdx-tutorial-3b-simple-animation/
https://gamefromscratch.com/libgdx-video-tutorial-sprite-animation/
https://www.pixnbgames.com/blog/libgdx/frame-by-frame-animations-in-libgdx/
https://www.codeandweb.com/texturepacker/tutorials/libgdx-sprite-sheet-tutorial
https://www.reddit.com/r/libgdx/comments/18bghen/how_can_i_get_an_animation_to_be_timed_correctly/
https://gamedev.stackexchange.com/questions/138324/libgdx-animation-sequence
boxes = new Texture(Gdx.files.internal("boxes.png")); //** loading boxes **//
box1 = new TextureRegion(boxes,0,0,180,320);
box2 = new TextureRegion(boxes,200,0,480-200,320);
box3 = new TextureRegion(boxes,0,330,127,511-330);
box4 = new TextureRegion(boxes,180,325,511-180,511-320);
Generating GIFs in Open Eggbert
https://github.com/Anuken/GDXGifRecorder
Videos
https://github.com/libgdx/gdx-video
Sprite Tools
Generating sprite animations to gifs
https://genuinecoder.com/how-to-create-gif-from-multiple-images-in-java/
Detection of sprite positions.
https://github.com/mapeditor/tiled/tree/master/util/java/libtiled-java
Support for web and mobile platforms (Android, iPhone)
It is a good idea to ensure, that Open Eggbert is runnable on web and mobile platforms.
https://stackoverflow.com/questions/2590850/threading-in-gwt-client
https://stackoverflow.com/questions/28267316/libgdx-not-work-on-android-api-21
Networking
https://www.reddit.com/r/libgdx/comments/4rtdph/what_are_some_networking_options_for_libgdx/
Screens
https://www.gamedevelopment.blog/full-libgdx-game-tutorial-loading-screen/
https://www.slideshare.net/slideshow/libgdx-screens-fonts-and-preferences/44430118
Controls
Mouse
Keyboard
Touch screen
Gamepad
https://github.com/libgdx/Jamepad
2D physics engines
https://github.com/erincatto/box2d-lite
https://github.com/jbox2d/jbox2d
https://box2d.org/documentation/
https://github.com/dyn4j/dyn4j
https://github.com/jwvhewitt/Slick2d-Game-Engine
https://github.com/implicit-invocation/jbump
How to create a Java Platformer game
https://longbaonguyen.github.io/courses/platformer/platformer.html
Design patterns
https://gameprogrammingpatterns.com/command.html
Books
https://gameprogrammingpatterns.com/contents.html
Wikipedia
Video game development - Wikipedia
Platforms
Desktop
Android
Web
https://libgdx.com/wiki/html5-backend-and-gwt-specifics
Java annotations
Open Eggbert uses subset of Java 11 to reach the ability to be multiplatform (Desktop, GWT, Android)
Implementing jumping without Box2D
To implement a jump mechanic in LibGDX without using Box2D, you can follow these steps:
1. **Define Variables:**
- Create variables for the player's velocity, gravity, and whether the player is on the ground.
```java
float velocityY = 0;
final float gravity = -0.5f;
boolean onGround = true;
```
2. **Jump Logic:**
- Implement the jump by applying an upward velocity when the jump key is pressed and the player is on the ground.
```java
if (Gdx.input.isKeyPressed(Input.Keys.SPACE) && onGround) {
velocityY = 10; // Jump strength
onGround = false;
}
```
3. **Apply Gravity:**
- Continuously apply gravity to the player's vertical velocity.
```java
velocityY += gravity;
```
4. **Update Player Position:**
- Update the player's Y position using the current velocity.
```java
player.y += velocityY;
```
5. **Ground Detection:**
- Check if the player has landed back on the ground to reset the jump.
```java
if (player.y <= groundLevel) {
player.y = groundLevel;
velocityY = 0;
onGround = true;
}
```
By following these steps, you create a basic jumping mechanic where the player can jump when on the ground, and gravity pulls them back down. This can be expanded with more complex mechanics like double jumps or variable jump heights.
Discussion
Reimplementing a computer game such that it produces the same output for the same set of keyboard inputs involves several key steps to ensure that the behavior and output of the new implementation match the original as closely as possible. Here's a general guide on how to approach this task:
1. Understand the Original Game
- Play and Analyze: Thoroughly play the original game and understand its mechanics, behavior, and response to different inputs.
- Document Behavior: Document how the game responds to different inputs, including edge cases and specific sequences of events.
- Reverse Engineering: If you have access to the game's source code or documentation, review it to understand the logic and algorithms used.
2. Define Specifications
- Input Mapping: Clearly define how keyboard inputs map to actions within the game. This includes key bindings and the timing of inputs.
- Output Requirements: Specify what constitutes the "output" of the game. This could include graphics, sound, game state, or specific responses to inputs.
3. Choose Development Tools
- Programming Language: Choose a language and development environment that you're comfortable with and that is suited for game development.
- Game Engine: Decide whether to use a game engine (like Unity, Unreal Engine, or Godot) or build from scratch. An engine may simplify development but could introduce differences in behavior.
4. Implement Core Mechanics
- Input Handling: Implement keyboard input handling to match the original game's input system. Ensure that inputs are processed in the same way.
- Game Logic: Develop the core game logic according to the documented behavior. Pay close attention to algorithms and state management.
- Rendering: If the game involves graphics, ensure that the rendering matches the original in terms of visuals and timing.
5. Testing and Debugging
- Unit Testing: Create unit tests for individual components to verify that each part behaves as expected.
- Playtesting: Test the game with a variety of input sequences to ensure that the output matches the original game. This might involve comparing screenshots, audio, and game states.
- Debugging: Identify and fix any discrepancies between the original game and your implementation.
6. Refinement
- Performance Optimization: Ensure that the game runs smoothly and efficiently. Optimize performance if necessary.
- Consistency Checks: Continuously check that the output remains consistent with the original game for the same inputs.
7. Documentation and Final Testing
- Document Differences: If there are any intentional or unintentional differences, document them clearly.
- Final Testing: Conduct a thorough round of testing to ensure that the reimplementation meets all the specifications and requirements.
Additional Considerations
- Legal and Ethical Issues: Make sure you are legally permitted to reimplement the game. If the original game is copyrighted, ensure that your work complies with relevant laws and intellectual property rights.
- Community Feedback: Engage with communities or players familiar with the original game to get feedback on your implementation.
By following these steps, we can reimplement a computer game to produce the same output for the same set of keyboard presses, provided that you account for all aspects of the original game's behavior and mechanics.
External links
https://gamedev.stackexchange.com/questions/109047/how-to-close-an-app-correctly-on-desktop
https://gamefromscratch.com/speeding-up-gwt-compilation-speeds-in-a-libgdx-project/