Beginning Java Game Development with LibGDX by Lee Stemkoski
Author:Lee Stemkoski
Language: eng
Format: epub, pdf
Publisher: Apress, Berkeley, CA
Rocks and Explosions
Next, it is time to move on to the rocks of the Space Rocks game. There does not need to be a base version of the object to clone later, since rocks are destroyed when hit by lasers, and no new rocks spawn at a later time.1 For simplicity, you could still create a base version and clone it repeatedly to produce the set of rocks drifting around the screen at the start of the game. However, you will instead attempt to make the individual rocks appear and act differently to add interest to the game. In particular, the rocks will use different images (the file names are rock0.png, rock1.png, rock2.png, and rock3.png), the initial positions will be random, and they will have different speeds and rates of rotation. Here, you must also initialize the ArrayList being used to keep track of the rocks for collision detection. The code that accomplishes this is given here:
rockList = new ArrayList<PhysicsActor>();
int numRocks = 6;
for (int n = 0; n < numRocks; n++)
{
PhysicsActor rock = new PhysicsActor();
String fileName = "assets/rock" + (n%4) + ".png";
Texture rockTex = new Texture(Gdx.files.internal(fileName));
rockTex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
rock.storeAnimation( "default", rockTex );
rock.setPosition(800 * MathUtils.random(), 600 * MathUtils.random() );
rock.setOriginCenter();
rock.setEllipseBoundary();
rock.setAutoAngle(false);
float speedUp = MathUtils.random(0.0f, 1.0f);
rock.setVelocityAS( 360 * MathUtils.random(), 75 + 50*speedUp );
rock.addAction( Actions.forever( Actions.rotateBy(360, 2 - speedUp) ) );
mainStage.addActor(rock);
rockList.add(rock);
rock.setParentList(rockList);
}
In the update method of the GameScreen class, some code must be added that causes the rocks to wrap around the screen in the same style as the spaceship:
for ( PhysicsActor rock : rockList )
{
wraparound( rock );
}
This is another good point to compile your project and run the game to make sure that the rock objects are behaving as expected.
Next, you’ll set up the AnimatedActor that stores an animated explosion that will appear when lasers collide with rocks. For animation sequences consisting of many images, it is common practice to combine all these images into a single image file called a sprite sheet, and this is the case for the image you will use, pictured in Figure 6-5.
Figure 6-5.A sprite sheet consisting of images for an animation of an explosion
Download
Beginning Java Game Development with LibGDX by Lee Stemkoski.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12568)
Hello! Python by Anthony Briggs(9913)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9795)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Dependency Injection in .NET by Mark Seemann(9337)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8295)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7056)
Microservices with Go by Alexander Shuiskov(6819)
Practical Design Patterns for Java Developers by Miroslav Wengner(6736)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6677)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Angular Projects - Third Edition by Aristeidis Bampakos(6083)
The Art of Crafting User Stories by The Art of Crafting User Stories(5609)
NetSuite for Consultants - Second Edition by Peter Ries(5549)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5350)
Kotlin in Action by Dmitry Jemerov(5062)
