Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
11.3 Add a simple pattern for the Boss' movements
' 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