Jump to content

Star Fighter


jerome
 Share

Recommended Posts

Well it's not the cleanest code ever, but it runs and it runs fast (60 fps with Chrome even on my 10 yo laptop) ...

So I'm proud to introduce you to my first full playable demo PG : http://www.babylonjs-playground.com/#1UYHW4

The code is commented if you want to hack it or tweak it.

FIRE = SHIFT or Left mouse button

The rules are quite complex but I'm sure you'll understand them : Destroy the baddies (unless YOU are the baddy, I don't know) and keep in life !

If the baddies aren't visible, search them around, they are never far from you.

Have fun :P

Link to comment
Share on other sites

Just some extra info for the most curious of you :

This is a low-cost demo, this means there are very few assets.

Actually, the stars, the enemy laser crosses, the laser impact on the enemies, the enemy explosion and the laser lights in the distance are all in single SPS using a single quad particle with a single texture (different sizes, colors, behavior).

The cannon lasers are also one SPS with a simple triangular shape for particle model.

Each enemy is a ... SPS (surprising, isn't it), what has just digested a T-fighter-like model. This model is simply computed from 3 cylinders and sphere merged together.

The cockpit is a merged mesh designed from two tubes and a curved ribbon. The shield indicator is an updatable ribbon. And the sight is a simple texture plane.

The camera is fixed, looks towards the Z axis, everything is animated according to the current pointer position.

Link to comment
Share on other sites

ok, thank you :)

The PG is here in learning/hacking purposes... and to share this tribute with any interested other BJS lover

 

[EDIT] I just checked, it seems the better way with the PG is to play in EDITOR-less mode only

Link to comment
Share on other sites

Odd - The scene does play much better in "editorless" mode - however, even then if I switch to fullscreen, pointer locks up on the right side of the screen unable to move. Otherwise, it's a great game, and I hope you adapt it to the GearVR or Vive or both - or perhaps give me permission to do so?

Fun to play.:D

DB

Link to comment
Share on other sites

@dbawel sure, you can get the code and improve it for your own ideas. Just share it with us when you achieve to do something nice :)

about the pointer locked in some corner, it really seems to be related to the PG behavior, because it doesn't happen when the game is run off the PG

@Milton well, you find the turrets like ... what it comes to your mind :D

Game note : the enemy hits you when its laser hits the center of the cockpit glass, well in the center of the screen

Game and code note : I tried to put all the game setting variables at the begining of the code so that people that don't want to read all the code lines can fix them to other better values to their own needs

from the line 6 to 25

You can, for instance, increase the game difficulty by reducing the maxShield value (your ship resistance) or increasing the number of enemies, or their speed, or their laser speed, or their shield, or their fire frequency. Just set different, but to far, values than the current ones. If you set radically different values, you'll notice that the game still runs but quickly becomes unplayable. I discovered that "playability" is an art of refinement of a a given working program :D

example : this version could be an expert level http://www.babylonjs-playground.com/#1UYHW4#1

ace level : http://www.babylonjs-playground.com/#1UYHW4#2

jedi level : http://www.babylonjs-playground.com/#1UYHW4#3   (try to score just 300, so only 3 enemies :P)

Code note2 : I choosed to set and type early every variable for two reasons : to help the js compiler to optimize the code and to help the coder to understand what kind of value he's dealing with. Therefore, if you have a look at the code, you'll see that every numeric value has either a dot (ex : 0.0) or a pipe (ex : 0|0) : this is the JS way to explicitely declare either a float, either a signed integer.

You'll also notice that the code is not fully object oriented. Plenty of variables are used with a large scope... Well, although it may be not as clean or readable as better embedded code, it's still legal and efficient javascript in terms of syntax, compilation and execution javascript. So sometimes I use objects, sometimes simply arrays. I just usually do the most straight forward possible to what I intend (all this could be refactored). I just keep the constraints to not allocate anything once the render loop has started and to never modify an object once it is created, neither a variable type once it is set.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...