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..
// field private Shield shield = new Shield(); // at end of act method (to have shield follow spaceship) if (shield.getWorld() != null) shield.setLocation(getX(), getY()); }
getWorld().addObject(shield, 0, 0);
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() { } }
if (shield.getWorld() == null && Greenfoot.isKeyDown("g")) getWorld.addObject(shield, 0, 0);