Created
October 27, 2020 04:08
-
-
Save gretaf007/99913aa4e367616977cc12b4e4f9ffb7 to your computer and use it in GitHub Desktop.
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
| fishX = 1 | |
| fishC = 1 | |
| fishY = 1 | |
| fishDirection = 1 | |
| def setupObstacles(): | |
| global photo | |
| photo = loadImage("swordfish2_smally.png") | |
| def drawObstacles(): | |
| global fishX | |
| global fishDirection | |
| global fishC | |
| global fishY | |
| #fish bottom | |
| image(photo, fishX, 500) | |
| fishX = fishX + fishDirection | |
| if fishX > 600: | |
| fishDirection = -3 | |
| if fishX < 0: | |
| fishDirection = 3 | |
| #fish top | |
| # image(photo, fishX + 400, 50) | |
| #fishX = fishX + fishDirection | |
| if fishX > width: | |
| fishDirection = -3 | |
| if fishX < 0: | |
| fishDirection = 3 | |
| #fish top | |
| image(photo, fishC + 14, 40) | |
| fishC = fishC + fishDirection | |
| if fishC > width: | |
| fishDirection = -3 | |
| if fishC < 0: | |
| fishDirection = 3 | |
| #fishhorizantal | |
| image(photo, 100, fishY + 100) | |
| fishY = fishY + fishDirection | |
| if fishY > width: | |
| fishDirection = -3 | |
| if fishY < 0: | |
| fishDirection = 3 | |
| image(photo, 500, fishY + 157) | |
| fishY = fishY + fishDirection | |
| if fishY > width: | |
| fishDirection = -3 | |
| if fishY < 0: | |
| fishDirection = 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Greta,
I think the main issue that you're grappling with at this point is that you one variable (
fishDirection) which is controlling the movement of all your sharks. All of yourifstatements are checking conditions based on the location of the different sharks, but all are ultimately updating that same onefishDirectionvariable, meaning they will all be moving in an identical way (same timing, same direction value: either up/right together, or down/left together). Here's what I think you should do:First of all, rename your variables so they more clearly indicate what they are doing. What I would suggest:
fishXbecomesfishTopXfishCbecomesfishBottomXfishYbecomesfishLeftYAlso add a new variable called
fishRightY(you were usingfishYas the location for both of the up/down fish) and use this one instead offishYin the lastifstatement on lines 54-59Now, make four separate variables for direction, renaming the one you have now and adding there new ones:
fishDirectionbecomesfishTopDirectionfishBottomDirectionfishLeftDirectionfishRightDirectionModify your
ifstatements so that each one is adjusting a different direction variable. It looks like you have fiveifstatements right now, so you can probably delete one. I'd suggest lines 30-36 since you've already commented out theimage()command in that chunk of code.After you have all that in place, you can adjust the numbers in your
ifstatements so that the various "greater than" and "less than" checks are asking questions about the movement patterns of each of the different sharks, and since they are each changing different direction variables, you should be able to tweak the behavior as you described above.Give that a try and if you get stuck let me know.