Im new to coding and im making a "game" and i want to have a shield follow around my spaceship for a period of time and absorb damage. any tips on where and how i should start..


1 2 3 4 5 6 | // field private Shield shield = new Shield(); // at end of act method (to have shield follow spaceship) if (shield.getWorld() != null ) shield.setLocation(getX(), getY()); } |
1 | getWorld().addObject(shield, 0 , 0 ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Shield here. * * @author (your name) * @version (a version number or a date) */ public class Shield extends Actor { /** * Act - do whatever the Shield wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { shieldUp(); followHero(); mortality(); absorbDamage(); } public void shieldUp() { if (Greenfoot.isKeyDown( "g" )) { } } public void followHero() { } public void mortality() { } public void absorbDamage() { } } |
1 | if (shield.getWorld() == null && Greenfoot.isKeyDown( "g" )) getWorld.addObject(shield, 0 , 0 ); |