Games [XUI2D] Space Invaders #2

Erel

B4X founder
Staff member
Licensed User
Longtime User

Resources are based on: https://github.com/leerob/Space_Invaders/

Previous example: https://www.b4x.com/android/forum/threads/xui2d-space-invaders-1.96263/

New features in this example:

- shields
- mystery enemy (red enemy)
- high scores
- explosion graphics
- and some other small improvements.

If we run the game with debug drawing then we can see that the shields are made of many small fixtures:

SS-2018-08-19_16.58.47.jpg


This allows us to destroy small parts of the shields. See the code in the Shield class.

There are three new methods in X2Utils:

- AddFutureTask2 - Similar to AddFutureTask. Allows to add duplicate future tasks. Duplicate means FutureTasks with the same Callback, SubName and Time.

- GetBodyWrapper - Returns a X2BodyWrapper based on the Id. The Id field is a new field that is set from the tile map object id. You can also set programmatically.
- GetBodiesWrappers - Returns a list with all bodies with ids listed in the ListOfIds parameter.

I'm using GetBodiesWrappers instead of the Enemies list that was maintained in the previous example. The advantage is that we don't need to worry about the list not being synchronized and we let XUI2D maintain it for us.


Example projects included in the examples pack: https://www.b4x.com/android/forum/threads/xui2d-example-pack.96454/
 
Last edited:

AHilton

Active Member
Licensed User
Longtime User
What, or what version of it, am I missing with this compile-time error?

B4X:
B4J Version: 6.30
Parsing code.    (0.04s)
Compiling code.    (0.33s)
Compiling layouts code.    (0.02s)
Organizing libraries.    (0.00s)
Compiling generated Java code.    Error
B4J line: 184
MainBC.FillRect(xui.Color_Transparent, MainBC.Tar
javac 1.8.0_171
src\b4j\example\x2utils.java:335: error: cannot access B4XCanvas
__ref._mainbc._fillrect(__ref._xui.Color_Transparent,__ref._mainbc._targetrect);
                                                                  ^
  class file for anywheresoftware.b4a.objects.B4XCanvas not found
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
SS-2018-08-20_17.02.51.jpg


A small update with three changes:

- X2TileMap now respects the rotation property.
- The ship rotates based on its X position.
- The lasers are fired based on the ship angle. This is done with a new method in B2Transform named MultiplyRot. It multiplies the vector with the transform rotation matrix. The result is a rotated vector:
B4X:
template.BodyDef.Angle = bw.Body.Angle
template.BodyDef.LinearVelocity = bw.Body.Transform.MultiplyRot(x2.CreateVec2(0, 5))

Note that it depends on XUI2D v0.95 which was not yet released.
 

Attachments

  • B4J SpaceInvaders.zip
    445.5 KB · Views: 290
Top