2.2.9 Cycle 9 - Twines
Design:
Objectives
In the ninth cycle, my objectives are to implement the second type of hostile enemy into the game. As with the previous enemy, the Twines don't need to be too detailed, a simple shape or image will do.
Usability Features
The Player will have to avoid the Twine since they will cause the Player to die and the game to end. This will add excitement to the game since there is now a larger risk factor.
Key Variables
ENEMY_SPEED
Used to control the speed of the Twines if I wish to make them move in the future.
BULLET_SPEED
Used to control the speed of the bullets that the Twine shoots.
Pseudocode
The pseudocode for the hostile Twine is shown below:
// Twine
const ENEMY_SPEED = 0
const BULLET_SPEED = 800
let twine
On collision with "enemy":
if not colliding from the bottom:
Go to "lose" scene
End on collision
twine = add entity with:
- sprite "Twine"
- position (2688, -60)
- anchor "center"
- initial state "move" with possible states: "idle", "attack", "move"
On entering state "idle":
Wait for 0.5 seconds
Change twine state to "attack"
End on entering state "idle"
On entering state "attack":
if player exists:
Calculate direction as unit vector from twine position to player position
add bullet entity with:
- position twine position
- move in direction with speed BULLET_SPEED
- rectangle shape (12, 12)
- area
- offscreen behavior with destruction
- anchor "center"
- color BLUE
- "bullet" component
Wait for 1 second
Change twine state to "move"
End on entering state "attack"
On entering state "move":
Wait for 2 seconds
Change twine state to "idle"
End on entering state "move"
During state "move":
if player exists:
Calculate direction as unit vector from twine position to player position
Move twine in the direction scaled by ENEMY_SPEED
End during state "move"
On collision with "bullet":
Go to the "lose" scene
End on collisionDevelopment:
Outcome
The player is now faced with the Twine opponent later on in the game, the code for this can be viewed below:
Challenges
Some challenges I faced during this cycle:
The positioning of the Twine was difficult to implement because they wouldn't comply with the array-level format.
The Twine wouldn't shoot consistently or in the correct direction.
Testing:
Tests performed in this cycle are evidenced below, they were a crucial aspect of my development.
Tests
1
Run code.
The game to start, Twine placed.
As expected
Pass
2
Collide the Player's character with the Twine's bullets.
The Player loses the game and the game is reset.
As expected
Pass
Evidence
The screen recording below shows the Player being defeated by the hostile Twine, it completes the following tasks for this cycle:
Last updated