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

2020/5/8

RED & BLUE TEAMS

genju genju

2020/5/8

#
I am creating a war game that pits two teams (hopefully) red and blue against eachother, the teams come in and spawn troops from towers based on either side of the screen. the only problem is that i have gathered sprites for the troops but cant differentiate them except for the direction they are facing, i would like to be able to tint them to fit their team colours ( red tint on unit for red team, vice versa for blue) but dont know where i would even begin or if that is even possible) here is my code: **KEEP IN MIND THIS IS INCOMPLETE** Soldier Superclass
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Soldier here.
 * 
 * @author (Prayan Jegathees) 
 * @version (0.1)
 */
public abstract class Soldier extends Actor
{
    /**
     * Private variables used for all soldier subclasses
     *      stats needed to determine the overall stats 
     *      of the character
     *      
     * LIFE is a boolean meant to change & detect the actors "death" 
     * TEAM is a string meant to choose which alliance the actor belongs to 
     */
    private int health;
    private int speed;
    private int atkPower;
    private int atkRate;
    
    private boolean life;
    private String team;
          
    /**
     * Constructor for all Soldiers
     */
    public Soldier(int hp, int spd, int aPwr, int aRt, String alliance)
    {
        health = hp;
        speed = spd;
        atkPower = aPwr;
        atkRate = aRt;
        alliance = team;
        life = true;
    }
    
    /**
     * Attack - To deal damage to an enemy soldier unit
     */
    public abstract void attack();
        
    /**
     * takeDamage - When soldier subunits are hit by projectiles and lose health
     *              (amount taken varies based on the type of projectile)
     */
    public void takeDamage()
    {
        /*
        if (isTouching(PROJECTILE_ARROW.class))
        {
            health -= 2;
        }
        if (isTouching(PROJECTILE_FIREBL.class))
        {
            health -= 5;
        }
        */
        if (health == 0)
        {
            life = false;
        }
    }
    
    public void die()
    {
        if (!life)
        {
            move(0);
            getImage().setTransparency(50);
            setRotation(90);
        }
    }
}
Sub-units so far
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Heavy here.
 * 
 * @author (Prayan Jegathees) 
 * @version (0.1)
 */
public class Archer extends Soldier
{
    public Archer(int hp, int spd, int aPwr, int aRt, String alliance)
    {
        super(hp, spd, aPwr, aRt, alliance);
    }

    /**
     * Act - do whatever the Archer wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
    
    public void attack()
    {
        
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Knight here.
 * 
 * @author (Prayan Jegathees) 
 * @version (0.1)
 */
public class Fighter extends Soldier
{
    public Fighter(int hp, int spd, int aPwr, int aRt, String alliance)
    {
        super(hp, spd, aPwr, aRt, alliance); 
    }
    
    /**
     * Act - do whatever the Assassin wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
    
    public void attack()
    {
        
    }
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Knight here.
 * 
 * @author (Prayan Jegathees) 
 * @version (0.1)
 */
public class Minotaur extends Soldier
{
    public Minotaur(int hp, int spd, int aPwr, int aRt, String alliance)
    {
        super(hp, spd, aPwr, aRt, alliance);
    }
    
    /**
     * Act - do whatever the Minotaur wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
    
    public void attack()
    {
        
    }
}
Thanks for any assistance in advance
danpost danpost

2020/5/8

#
One idea is to use a program like Paint to add the coloring to the sprites. You know, have all the needed images already in your images folder for use in the scenario.
genju genju

2020/5/8

#
danpost wrote...
One idea is to use a program like Paint to add the coloring to the sprites. You know, have all the needed images already in your images folder for use in the scenario.
but would i not have to have separate files for both teams?
danpost danpost

2020/5/8

#
genju wrote...
danpost wrote...
One idea is to use a program like Paint to add the coloring to the sprites. You know, have all the needed images already in your images folder for use in the scenario.
but would i not have to have separate files for both teams?
Yes. How would that be a problem?
You need to login to post a reply.