Let's make
DroidBlaster
more interactive with some graphics and game components.
Edit
jni/Types.hpp
and create a new structureLocation
to hold entity positions. Also, define a macro to generate a random value in the requested range as follows:#ifndef _PACKT_TYPES_HPP_ #define _PACKT_TYPES_HPP_ ... struct Location { Location(): x(0.0f), y(0.0f) {}; float x; float y; }; #define RAND(pMax) (float(pMax) * float(rand()) / float(RAND_MAX)) #endif
Create a new file,
jni/GraphicsManager.hpp
. Define a structureGraphicsElement
, which contains the location and dimensions of the graphical element to display:#ifndef _PACKT_GRAPHICSMANAGER_HPP_ #define _PACKT_GRAPHICSMANAGER_HPP_ #include "Types.hpp" #include <android_native_app_glue.h> struct GraphicsElement { GraphicsElement(int32_t pWidth, int32_t pHeight): location(), width(pWidth), height(pHeight) { } Location location; int32_t width; int32_t height; ...