This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| ... | |
| // Update the players playerBullet if active | |
| if (playerBullet.isActive) { | |
| playerBullet.update(fps) | |
| } | |
| // Update all the invaders bullets if active | |
| for (bullet in invadersBullets) { | |
| if (bullet.isActive) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| ... | |
| // Initialize the invadersBullets array | |
| for (i in 0 until maxInvaderBullets) { | |
| invadersBullets.add(Bullet(size.y)) | |
| } | |
| ... | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| ... | |
| // The player's shelters are built from bricks | |
| private val bricks = ArrayList<DefenceBrick>() | |
| private var numBricks: Int = 0 | |
| // The player's playerBullet | |
| // much faster and half the length | |
| // compared to invader's bullet | |
| private var playerBullet = Bullet(size.y, 1200f, 40f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.gamecodeschool.kotlininvaders | |
| import android.graphics.RectF | |
| class Bullet(screenY: Int, | |
| private val speed: Float = 350f, | |
| heightModifier: Float = 20f) { | |
| val position = RectF() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Draw the bricks if visible | |
| for (brick in bricks) { | |
| if (brick.isVisible) { | |
| canvas.drawRect(brick.position, paint) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Build the shelters | |
| numBricks = 0 | |
| for (shelterNumber in 0..4) { | |
| for (column in 0..18) { | |
| for (row in 0..8) { | |
| bricks.add(DefenceBrick(row, | |
| column, | |
| shelterNumber, | |
| size.x, | |
| size.y)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| ... | |
| // Some Invaders | |
| private val invaders = ArrayList<Invader>() | |
| private var numInvaders = 0 | |
| // The player's shelters are built from bricks | |
| private val bricks = ArrayList<DefenceBrick>() | |
| private var numBricks: Int = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.gamecodeschool.kotlininvaders | |
| import android.graphics.RectF | |
| class DefenceBrick(row: Int, column: Int, shelterNumber: Int, screenX: Int, screenY: Int) { | |
| var isVisible = true | |
| private val width = screenX / 180 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| package="com.gamecodeschool.kotlininvaders"> | |
| <application | |
| android:allowBackup="true" | |
| android:icon="@mipmap/ic_launcher" | |
| android:label="@string/app_name" | |
| android:roundIcon="@mipmap/ic_launcher_round" | |
| android:supportsRtl="true" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| android:theme="@android:style/Theme.NoTitleBar.Fullscreen" | |
| android:screenOrientation="landscape" |