Android Question 3D shooter game (fps)

MasterGy

Member
Licensed User
Hello Everyone!


I want to create a game. I don't understand many things, I've recently started working with B4A. I have a lot of questions, and I thought instead of cluttering up the forum, I'd post my questions under this post. In the future, these would cover different topics. I think it's a good solution to ask questions about various topics here, under one post, so those who want to create a game in a similar way would get help in one place. Plus, I'm happy to answer anything myself.

I didn't make an internal recording so you can see the controls. I hope it's an ideal, easy solution, and I'd like feedback on this as well. I want to make it as ergonomic as possible. I admit, I'm not good at it in any way, even though I've tried many control layouts. The latter seems to be the most ideal for us. There's nothing better than 'wasd+mouse' on PC! :) But life is limited on mobile.

I'd especially like to ask about OpenGL. Let's start:

  1. How can I draw over OpenGL? Can I use 'canvas, b4xcanvas'? I couldn't make it work.
  2. How can I place a 2D texture over OpenGL graphics? I want a solution that would show crosshairs, energy, and other information with semi-transparent textures. I don't want to place separate panels, which would decrease the size of the 3D window. It's funny because I managed to implement 3D rendering (because I found a sample program and understood it), but I can't do 2D rendering (how to put a simple image over OpenGL). So overall, what I want is very simple. I want to draw and write over the graphics.
  3. How do I know in the program how fast rendering is happening? The actual redrawing.
  4. How can I make the background of the loaded image disappear? For example, if the background is rgb(255,0,0) red, then make it completely transparent (alpha=0). From line 524, you can see that I tried. I left the code in. It doesn't work. No matter how I try, it gives color to the background instead of making it disappear. This is the texture of the bullet I shoot. So for now, I'm left with a triangle-bullet.
  5. I'm uncertain. There are elements that don't move. But there are those that do. My knowledge extends to the point where I reload all the vertices every render. Since I don't know OpenGL, I'm afraid I've also calculated those vertices unnecessarily, which don't change. The thing works like this, but I'm not sure if I'm unnecessarily burdening the CPU. The drawings that don't change are in lines 614-623. Those that always change are in lines 624-637. Would it be faster if I only load the parts that don't change once? Or is it insignificant? Unfortunately, I'm not clear on this, so I welcome any thoughts.
I attached the game. Only one external library is needed, 'OPENGL'. The package contains it.
(pack is too large here)
 

ilan

Expert
Licensed User
Longtime User
maybe this can help you:

(just used the search function of the forum)
 
Upvote 0

MasterGy

Member
Licensed User
maybe this can help you:

(just used the search function of the forum)
Thanks ! The link you provided is very good. I took the GL commands needed for 3D rendering of my game from the rotating cube program, and I learned a lot from it. It was started by the spin-cube program. But I don't see a 2D display. How do I render an image in opengl to the x1y1x2y2 area on the screen? There should be a solution as simple as B4XCanvas' 'drawbitmap'. Unfortunately, I cannot draw B4XCanvas over an opengl window. That's why I have to solve this otherwise simple problem in opengl.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
I think it's a good solution to ask questions about various topics here, under one post
I think that instead this would make everything to get lost if/when the thread will become longer and longer.
Who would read a 60 pages thread not knowing what could be inside?
It could be better to have all the threads about this starting with the same prefix:
Example:
[3D FPS] How to create the maze
[3D FPS] How to apply textures
[3D FPS] How to detect collisions
I wish you all the best with your great project!
I will follow curious.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
But I don't see a 2D display. How do I render an image in opengl to the x1y1x2y2 area on the screen?
i am not familiar with opengl but is it drawn on a panel?
if yes you may add another panel with a simple b4xcanvas over it and draw the 2d image you like. i guess you want to draw the controls right?
the background can be transparent and like this you could have 2 separate panels. 1 for opengl rendering and 1 for canvas (2d)
but again i am not familiar with opengl :oops:
 
Upvote 0

MasterGy

Member
Licensed User
Hello everyone!



I've made progress with the game. Thanks to Ilan for the detailed comment. I managed to overlay a transparent texture over OpenGL graphics using b4xcanvas. The order was crucial, and I understand it better now.

I succeeded in removing the background and adjusting the alpha value of a texture, named 'remove_background' and 'setalpha' in the program. I have a better understanding of object-oriented programming now, and I've been progressing a bit faster since then.

The game runs at 60fps (Samsung A13). I'm curious about feedback regarding how it runs on different phones, different models, and years, whether it runs smoothly or stutters. Feedback is essential for me to understand how far I can push the load.

ChatGPT is also helpful, but I find the questions/answers here most useful. I'm glad I found B4A and this community.

For now, the game can be played in 'god mode', intentionally in 'full action' mode to see how much load the phone can handle. There will be strategy involved later, but that's where I've reached so far.

I have another question related to OpenGL that I can't find anywhere. I managed to prevent drawing color where a texture has an alpha=0 point. However, if the texture is drawn, it also writes to the z-buffer, so even though the image is transparent, it doesn't draw behind it. The drawing order is justified for semi-transparent textures, but not for 0-alpha, and I'm sure there must be a way to change this.

The gameplay is slower due to the recording.

 
Upvote 0

ilan

Expert
Licensed User
Longtime User
wow, this looks really awesome. very well done!!
i am very impressed what you have done here. amazing!!!
 
Upvote 0

MasterGy

Member
Licensed User
Hello everyone!

I've added a lot of things.
We need to gather the falling letters to put the sentence together.

I've integrated the ability to adjust rendering speed, so theoretically it should be playable even on weaker phones.

After 'process_globals', you can set:
extreme_mode_on = true/false (those who don't like flashing, loud noises can turn it off)
mycoordinates_fps = here you specify how many times per second the graphics should be drawn, depending on the phone's performance (the magnitude of movements doesn't change, the program calculates it - deltatime)
txt_kirak = the word that needs to be put together. You can only use letters and spaces, no numbers or other characters.

The recording is very dull, it doesn't capture the various sound effects.

I don't have any questions for now. I didn't receive help regarding OpenGL, but I managed to solve everything. Once I'm done with this, I'd like to create a simplified OpenGL-based engine so that anyone can easily create 3D applications.


 
Upvote 0

MasterGy

Member
Licensed User
"..sok mindent nem értek..."
nem úgy tűnik ?
Köszönöm a megtekintést ! :) Körülbelül egy hónapja kezdtem el tanulni a B4A-val, és először tényleg nem sokat értettem. Ez a játék nem 1 hónap alatt készült. Csináltam hasonló játékokat qbasicben (dos), majd QB64-ben (tehát az ember már adott volt, ahogy a fegyver is, amit papírra készítettem, vetítési diagram, processzor). Azonban sok mindent át kellett írni, mert kevés a megfelelés a QB64 és a B4A között.
"..I don't understand many things.."
it does not seem ?
Thanks for watching ! :) I started learning about B4A about a month ago and I really didn't understand much at first. This game was not created in 1 month. I made similar games in qbasic (dos), and then in QB64 (so the person was already a given, as was the weapon, which I made on paper, a projection diagram, and a processor). However, many things had to be rewritten because there is little correspondence between QB64 and B4A.
 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
Hi @MasterGy
sorry if off topic but I have a question, just out of curiosity, having been a 3D game player (mmorpg) for many years
usually games are programmed with both code and a editor to create the levels, see the 2d ones with tiled, or other dated games like wolfenstein, serious sam etc...
they all have an editor. Your 3d game uses only code, I wanted to know if it's normal, if it's not too difficult to make the levels with only code.
Thank you
 
Upvote 0

MasterGy

Member
Licensed User
Hi @MasterGy
sorry if off topic but I have a question, just out of curiosity, having been a 3D game player (mmorpg) for many years
usually games are programmed with both code and a editor to create the levels, see the 2d ones with tiled, or other dated games like wolfenstein, serious sam etc...
they all have an editor. Your 3d game uses only code, I wanted to know if it's normal, if it's not too difficult to make the levels with only code.
Thank you
Good question. I'm too lazy to edit. If I create a course with some algorithm that generates random values, it will also provide me with entertainment, I will never get the same. I never edited it. I don't think that a game that is fully developed will be a good game. In the event that there is a team and the goal is to sell, then it is reasonable to spend a lot of time on the details and elaboration of the pitches.

So far, four more 'serious' programs where an algorithm builds the track. I think it's worth approaching it this way.

In this game, you build a 3-dimensional cave system. He also creates interoperability. It can be traversed linearly. With an infinite number of variations. After the 10th second of the video, you can see how he creates the cave system.

In this game, Perlin noise creates the terrain in real time, and you can go in infinite directions.

In it, you generate a 3D maze, randomly placing the cubes hiding the keys.

Unfortunately, this did not become a game, it was not completed, even though I spent a lot of time with the track generation algorithm. A linear labyrinth. So in order to find the final destination, you have to walk through it all. Towers with random floors that are connected to each other, a random but still orderly 'garden', flowers, plants.

With these examples, I would like to answer that I think it is a good idea to spend time on random track generation.
 
Upvote 0

MasterGy

Member
Licensed User
Hello !

I will show you how the game has developed.

-New enemy, spider. All 8 legs are animated.
-Menu. The state of the menu is recorded in a file, so when we open the program again, it will be where we left it. I built the menu in such a way that I didn't use any 'event-oriented' solutions, I only query the touch. I derive the layout of the content from the X-Y dimension. So I couldn't test it with a display with a different aspect ratio. It would be great if I could get some feedback.

-The system's 'back button' returns to the menu if pressed during the game.

-I intend to have the option of several control schemes. For example, including a compass. If we turn physical and could play like that, it would be mature. Unfortunately, my phone is of the lowest category and its compass is not accurate. It's hard for me to test.

-I would like surround sound, if someone plays on headphones, they can enjoy it. Not only left and right, but I came up with a solution to distinguish forward and backward sounds as well.

It would be great if I could get some feedback.
Thank you if you try it, and I will thank you even more if you write about it. I appreciate any feedback.


I have currently built 5 tracks. When you play, it randomly gives you one. There is still a lot of work to be done on the colors, so that the animation can prevail on every level, and the background does not overwhelm the important content.

 
Upvote 0

MasterGy

Member
Licensed User
Hi everyone!
I feel like I've completed the game. After expanding it with animations, my main goal was to make it compatible with as many phones as possible.
Work done:
  • 10 different tracks with harmoniously selected colors.
  • Added distance-based coloring with OpenGL fog, known as 'opengl-fog'.
  • Animations for mission completion and death.
  • Optional controls: 'sliding' mode where rotation is done by swiping, and '360 VR' mode where you see in the direction you turn the phone.
  • Avoiding the 'orientation' function. The game detects if the phone has a gyroscope sensor. If so, 360 VR will work. If not, it calculates the phone's orientation using magnetic/accelerometer sensors with smoothing.
  • Playability: The game is divided into 40 levels. You start with no attacks. As you progress, the levels get harder. Enemies become faster and more aggressive.
I tested it on three different phones: Samsung A13/2021, Samsung A14/2023, and Xiaomi Redmi Note 12/2023. Different sensors, different sensitivities, different environments. The game is playable on all three phones.
The recording was made with the Xiaomi phone, and I noticed that the OpenGL rendering is poor, and the sound is delayed, which is terrible. Unfortunately, I can't do anything about it. I would like to ask for advice regarding this issue. The recording seen in the YouTube video is very bad. I assume it will be good when played in real-time.
I look forward to all kinds of feedback. I can't buy 10 different phones for testing, though I would like the game to work well on 10 out of 10 phones. I have to admit, the direction I started is not efficient in B4A :((((( Games like this and similar ones are better started in Godot or Unity.




 
Upvote 0
Top