Computer Science Canada Player Attack Mechanics In Turing |
Author: | programmer_needs_help [ Tue Jun 06, 2017 11:07 am ] |
Post subject: | Player Attack Mechanics In Turing |
So I'm making a game involving sword fighting, and i want the enemy to attack the player sometimes, so i made the following code to simulate the atttack chance. Unfortunately, the enemy either attacks, or doesn't attack throughout the whole game. Here's a portion of the code: % Enemy AI process enemyOneAttack for repeatChance : 1 .. 1 randint (attackChance, 1, 4) put attackChance end for loop enemyOnePlayerDistance := Math.Distance (playerXValue, playerYValue, enemyOneXValue, enemyOneYValue) if enemyOnePlayerDistance > 0 and playerXValue < enemyOneXValue then enemyOneXValue := enemyOneXValue - 1 Sprite.SetPosition (enemyOneSprite, enemyOneXValue, enemyOneYValue, true) delay (7) elsif enemyOnePlayerDistance > 0 and playerXValue > enemyOneXValue then enemyOneXValue := enemyOneXValue + 1 Sprite.SetPosition (enemyOneSprite, enemyOneXValue, enemyOneYValue, true) elsif enemyOnePlayerDistance < 10 then if attackChance = 1 then Sprite.Hide (enemyOneSprite) enemyOne := Pic.FileNew ("enemyOneSword.bmp") enemyOne := Pic.Scale (enemyOne, 152, 165) enemyOneSprite := Sprite.New (enemyOne) Sprite.Show (enemyOneSprite) Sprite.SetPosition (enemyOneSprite, enemyOneXValue, enemyOneYValue, true) delay (20) View.Update Sprite.Hide (enemyOneSprite) enemyOne := Pic.FileNew ("enemyOne.bmp") enemyOne := Pic.Scale (enemyOne, 155, 165) enemyOneSprite := Sprite.New (enemyOne) Sprite.Show (enemyOneSprite) Sprite.SetPosition (enemyOneSprite, enemyOneXValue, enemyOneYValue, true) end if end if delay (7) end loop end enemyOneAttack fork enemyOneAttack Pretty much when the "attakChance" is 1, I want the enemy to attack the player when they are close together. I appreciate any help! ![]() |