# See the License for the specific language governing permissions and
# limitations under the License.
-module action_nitro
+module action_nitro is
+ app_name "Action Nitro"
+ app_namespace "net.xymus.action_nitro"
+ app_version(1, 0, git_revision)
+
+ android_manifest_activity """android:screenOrientation="sensorLandscape""""
+ android_api_target 10
+end
import gamnit::depth
import gamnit::keys
# Game world assets
# Textures of the biplane, jet, helicopter, parachute and powerups
- private var planes_sheet = new PlanesImages
+ var planes_sheet = new PlanesImages
# Animation for the player movement
private var player_textures: Array[Texture] =
# ---
# Background
- private var city_texture = new Texture("textures/city_background_clean.png")
+ private var city_texture = new TextureAsset("textures/city_background_clean.png")
private var stars_texture = new Texture("textures/stars.jpg")
private var stars = new Sprite(stars_texture, new Point3d[Float](0.0, 1100.0, -600.0)) is lazy
private var altitude_counter = new CounterSprites(texts_sheet.n,
new Point3d[Float](1400.0, -64.0, 0.0))
+ # Did the player asked to skip the intro animation?
+ private var skip_intro = false
+
redef fun on_create
do
super
# Load 3d models
iss_model.load
+ if iss_model.errors.not_empty then print_error iss_model.errors.join("\n")
# Setup cameras
world_camera.reset_height 60.0
stars.scale = 2.1
# City background
+ city_texture.pixelated = true
var city_sprite = new Sprite(city_texture, new Point3d[Float](0.0, 370.0, -600.0))
city_sprite.scale = 0.8
sprites.add city_sprite
actors.add ground
# Trees
- for i in 1000.times do
+ for i in 2000.times do
var s = 0.1 + 0.1.rand
var h = tree_texture.height * s
var sprite = new Sprite(tree_texture,
new Point3d[Float](0.0 & 1500.0, h/2.0 - 10.0*s, 10.0 - 609.0.rand))
+ sprite.static = true
sprite.scale = s
sprites.add sprite
# Cinematic?
var t = world.t
var intro_duration = 8.0
- if t < intro_duration then
+ if t < intro_duration and not skip_intro then
var pitch = t/intro_duration
pitch = (pitch*pi).sin
world_camera.pitch = pitch
end
if world.player == null then
- # Game is starting!
- world.spawn_player
- world.planes.add new Airplane(new Point3d[Float](0.0, world.player.center.y - 10.0, 0.0), 16.0, 4.0)
-
- # Setup tutorial
- ui_sprites.clear
- ui_sprites.add_all([tutorial_wasd, tutorial_arrows, tutorial_chute])
-
world_camera.pitch = 0.0
world_camera.far = 700.0
+
+ begin_play true
end
# Update counters
player.moving = 0.0
if pressed_keys.has("left") then player.moving -= 1.0
if pressed_keys.has("right") then player.moving += 1.0
+ player.sprite.as(PlayerSprite).update
end
# Try to fire as long as a key is pressed
end
end
+ # Begin playing, after intro if `initial`, otherwise after death
+ fun begin_play(initial: Bool)
+ do
+ ui_sprites.clear
+
+ world.spawn_player
+ world.planes.add new Airplane(new Point3d[Float](0.0, world.player.center.y - 10.0, 0.0), 16.0, 4.0)
+
+ if initial then
+ # Setup tutorial
+ ui_sprites.add_all([tutorial_wasd, tutorial_arrows, tutorial_chute])
+ end
+ end
+
# Seconds at which the game was won, using `world.t` as reference
private var won_at: nullable Float = null
redef fun accept_event(event)
do
- var s = super
+ if super then return true
if event isa QuitEvent then
+ print perfs
exit 0
else if event isa KeyEvent then
if event.name == "escape" and event.is_down then
+ print perfs
exit 0
end
else player.sprite.as(PlayerSprite).start_running
end
end
+ end
- # When player is dead, respawn on spacebar
- if player != null and not player.is_alive then
- if event.name == "space" then
- ui_sprites.clear
- world.spawn_player
- end
+ # When player is dead, respawn on spacebar or pointer depressed
+ if (event isa KeyEvent and event.name == "space") or
+ (event isa PointerEvent and not event.is_move and event.depressed) then
+ var player = world.player
+ if player == null then
+ skip_intro = true
+ else if not player.is_alive then
+ begin_play false
end
end
- return s
+ return false
end
end
redef class Boss
redef var actor is lazy do
var actor = new Actor(app.iss_model, center)
- actor.rotation = pi/2.0
+ actor.yaw = pi/2.0
return actor
end
var splatter = new Actor(app.splatter_model,
new Point3d[Float](center.x, 0.05 & 0.04, center.y))
splatter.scale = 32.0
- splatter.rotation = 2.0 * pi.rand
+ splatter.yaw = 2.0*pi.rand
app.actors.add splatter
end
# Stop the running animation
fun stop_running do current_animation = null
- redef fun texture
+ # Update `texture` from `current_animation`
+ fun update
do
var anim = current_animation
if anim != null then
var dt = app.world.t - anim_ot
var i = (dt / time_per_frame).to_i+2
- return anim.modulo(i)
+ texture = anim.modulo(i)
end
-
- return super
end
end