I'm currently working on a game that's similar to this one: https://www.youtube.com/watch?v=l8cYYPpRboo However, I don't know how I'd be able to create a main character like this (mouse aiming + rotating body). Any chance someone here could help?


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public void act(){ gif(); } private void gif(){ int SIZE = 100 ; int COUNTER = 0 ; COUNTER++; GreenfootImage imageOne = new GreenfootImage (SIZE,SIZE); GreenfootImage imageTwo = new GreenfootImage (SIZE,SIZE); if (COUNTER== 1 ){ setImage (imageOne); } else if (COUNTER== 2 ){ setImage (imageTwo); } else { COUNTER = 0 ; setImage (imageOne); } } |
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 46 47 48 49 50 51 52 | import greenfoot.GreenfootImage; public class Animator { private String folder; private String action; private int index = 0 ; private int frames; /** * This class requires you to put your animation frames in folders. The animation frames need to be named in * the following format: "action_index" where action is the sprites current action and index is the frames * index. * * @param folder * The name of the sprites folder * * @param action * The name of the animaton sequence * * @param frames * The number of frames in the animation sequence */ public Animator(String folder, String action, int frames) { this .folder = folder; this .action = action; this .frames = frames; } public int getIndex() { return index; } public void setIndex( int index) { this .index = index; } public String getAction() { return action; } public void setAction(String action, int frames) { this .action = action; this .frames = frames; } public GreenfootImage getFrame() { GreenfootImage img = new GreenfootImage(folder + "/" + action + "_" + index); index++; index %= frames; return img; } } |