This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

JackVolp5
JackVolp5 presents ...

2019/3/4

Wild West Showdown, no clipping

Jack Volponi GeniusHour Project, that is more fun

1484 views / 577 in the last 7 days

1 vote | 0 in the last 7 days

Tags: game

Your browser does not support the canvas tag.
Can you share the code for the enemies health going down after every bullet is fired? Also, can you share the code that makes the bullet appear off the screen after it passes the edge of the screen.
JackVolp5JackVolp5

2019/3/6

Yea for sure! So in each of the player classes I have a instance health variable inside a zero-arg constructor. [code] public static int healthP1=100; public player() { healthP1 = 100; } [/code] And every time the bullet intersects with an object of bullet2.class, the yellow bullet, thirty is subtracted from the variable healthP1. [code] public void hitDetection() { Actor d = getOneIntersectingObject(player.class); Actor e = getOneIntersectingObject(Rock.class); Actor f = getOneIntersectingObject(Wagon.class); if(this != null && isAtEdge()) { getWorld().removeObject(this); } else if(d != null) { player.healthP1-=30; getWorld().removeObject(this); } else if(e != null || f != null) { getWorld().removeObject(this); } } [/code] To delete the bullet when it hits the edge, as you can see above, I made a large if/else statement and made sure that if noting else happened to it, it was deleted. If you remove it and then another method or class tries to use it, you will get a null error because it won't exist anymore
JackVolp5JackVolp5

2019/3/6

Damn I guess I can't do code boxes in comments. RIP.
Thank you so much for sharing.

Want to leave a comment? You must first log in.

Who likes this?

rb6333