Created
January 5, 2017 13:55
-
-
Save codetravis/96e144e30f51dc47a96e69890210b624 to your computer and use it in GitHub Desktop.
11.3 Add a simple pattern for the Boss' movements
This file contains 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
' Character Class | |
Method Update(game_width:Float, game_height:Float) | |
Local x_speed:Float = Self.box.GetSpeedX() | |
Local y_speed:Float = Self.box.GetSpeedY() | |
If (Self.is_player) | |
If (KeyDown(KEY_LEFT)) | |
Self.box.SetSpeedX(x_speed - 1.0) | |
Else If (KeyDown(KEY_RIGHT)) | |
Self.box.SetSpeedX(x_speed + 1.0) | |
End | |
If (KeyDown(KEY_UP)) | |
Self.box.SetSpeedY(y_speed - 1.0) | |
Else If (KeyDown(KEY_DOWN)) | |
Self.box.SetSpeedY(y_speed + 1.0) | |
End | |
If (Self.box.GetPosX() > game_width) | |
Self.box.SetPosX(game_width-1) | |
Self.box.SetSpeedX(0) | |
Else If (Self.box.GetPosX() < 0) | |
Self.box.SetPosX(1) | |
Self.box.SetSpeedX(0) | |
End | |
If (Self.box.GetPosY() > game_height) | |
Self.box.SetPosY(game_height-1) | |
Self.box.SetSpeedY(0) | |
Else If (Self.box.GetPosY() < 0) | |
Self.box.SetPosY(1) | |
Self.box.SetSpeedY(0) | |
End | |
' Add some AI patterned movement to the Boss update | |
Else If (Self.box.GetText() = "FINALBOSS") | |
SimpleBossPattern(game_width, game_height) | |
End | |
If (Self.box.GetText() = "DAMAGED") | |
Self.TakeDamage(1) | |
End | |
End | |
' .............. | |
' Very simple pattern for the Boss to follow | |
Method SimpleBossPattern(game_width:Float, game_height:Float) | |
Local y_speed:Float = Self.box.GetSpeedY() | |
Local x_speed:Float = Self.box.GetSpeedX() | |
If (Self.box.GetPosY() < 0) | |
Self.box.SetSpeedY(y_speed + 0.5) | |
Else If (Self.box.GetPosY() > game_height) | |
Self.box.SetSpeedY(y_speed - 0.5) | |
Else If (y_speed > 0) | |
Self.box.SetSpeedY(y_speed + 0.5) | |
Else If (y_speed < 0) | |
Self.box.SetSpeedY(y_speed - 0.5) | |
Else If (y_speed = 0) | |
Self.box.SetSpeedY(y_speed + 0.5) | |
End | |
End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment