This site requires JavaScript, please enable it in your browser!
Greenfoot
Username
Password
Remember Me?
Sign Up, Lost Password
Activity
About
Documentation
Download
Discuss
Scenarios
Discussions
You need to login to take part
Current Discussions
JDK 8
By bernmex, with 1 reply.
Replied to by davmac, over 11 years ago:
blocked the application because the java application has an old version
Are you sure it's not saying that the Java runtime is out-of-date? Do you have the latest update of JDK 8, or just the first release?
new game coming soon: Revenge Angel
By lildiddyk, with no replies.
this game will be a side scroller horror game your main character seeks revenge because when he was little he had a nightmare and he woke up went to his parents bedroom and they were lying on their bed dead he goes to leave the room but in the doorway is a portal to the nightmare dimension he turns around and finds himself in this dimension he follows the killers tracks and meets many enemies who after you defeat will put you in the real world to collect items for the next time you enter a portal to the nightmare world, you get 1 life how will you use it?
Doing a health code.
By Diahard1000, with no replies.
Hey you guys. I was wondering how do i use a health code in another actor Add Exp in my main one. For source here are the two actors Main Actor (Protag) import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Font; import java.awt.Color; import java.util.List; /** * Write a description of class Protag here. * * @author (your name) * @version (V1 - No working Exp System) */ public class Protag extends Actor { private Wolf Wolf; private int WolfHP = 0; public int ExpCount_; public int Lvl; public int HP; private GreenfootImage image1; private GreenfootImage image2; private GreenfootImage image3; private int animationcount = 0; int FireDelay = 10; int soundPlay = 0; int InvFrames = 30; public Protag() { super(); ExpCount_ = 0; image1 = new GreenfootImage("Hero2.png"); image2 = new GreenfootImage("Hero3.png"); image3 = new GreenfootImage("Hero.png"); setImage(image3); } /** * Act - do whatever the Protag wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { keyboard(); animaion(); checkFire(); LevelUp(); getWolfHP(); Health(); } public void keyboard() { int y = getY(); int x = getX(); if (Greenfoot.isKeyDown("d")) { setLocation(x+4,y); animationcount ++; setRotation(0); } if (Greenfoot.isKeyDown("a")) { setLocation(x-4,y); animationcount ++; setRotation(180); } if (Greenfoot.isKeyDown("s")) { setLocation(x,y+4); animationcount ++; setRotation(90); } if (Greenfoot.isKeyDown("w")) { setLocation(x,y-4); animationcount ++; setRotation(270); } } public void animaion() { if(animationcount >= 20) { setImage("Hero2.png"); } if(animationcount >= 40) { setImage("Hero3.png"); animationcount = 0; } } public void checkFire() { if(Greenfoot.isKeyDown("x")){ ExpCount_ ++; } if(Greenfoot.isKeyDown("space")) { FireDelay ++; } if(FireDelay >= 35) { getWorld().addObject(new Sword(getRotation()), getX(), getY()); FireDelay = 0; } } public void Health() { Actor a = getOneIntersectingObject(Wolf.class); if(a!= null) { InvFrames--; } if(InvFrames <= 0) { HP = HP - 4; InvFrames = 30; } } public int getExpCount() { return ExpCount_; } public int getLvl() { return Lvl; } public int getHP() { return HP; } public void LevelUp() { if(ExpCount_ >= 0) { Lvl = 1; } if(ExpCount_ >= 100){ Lvl = 2; } if(ExpCount_ >= 200){ Lvl = 3; } if(ExpCount_ >= 300){ Lvl = 4; } if(ExpCount_ >= 400){ Lvl = 5; } if(ExpCount_ >= 500){ Lvl = 6; } } public void level() { if(Lvl == 2 && ExpCount_ == 100) { HP = 20; } if(Lvl == 3 && ExpCount_ == 200) { HP = 30; } if(Lvl == 4 && ExpCount_ == 300) { HP = 40; } if(Lvl == 5 && ExpCount_ == 400) { HP = 50; } if(Lvl == 6 && ExpCount_ == 500) { HP = 60; } } public int getWolfHP() { int WolfHP = ((getWolf()).getWorld().getObjects(Wolf.class).get(0)).getWolf; /*if(WolfHP <= 0) { XP = XP + 100; }*/ } } Wolf import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.util.List; /** * Write a description of class Wolf here. * * @author (your name) * @version (a version number or a date) */ public class Wolf extends Actor { public int Wolf = 4; int InvFrames = 3; int spawn = 0; public void act() { Dmg(); move(2); } public void Dmg() { Actor Sword = getOneIntersectingObject(Sword.class); if(Sword!= null){ InvFrames --; } if (InvFrames <= 0){ Wolf = Wolf - Greenfoot.getRandomNumber(2)-4; InvFrames = 3; } if(Wolf <= 0){ getWorld().removeObject(this); } } public int getWolf() { return Wolf; } } Oh also have 3 working counters in Protag and the world Thanks any help would be appreciated this is giving me a headache.
Moving object up and down
By haz9999, with 1 reply.
Replied to by danpost, over 11 years ago:
You just need a direction field that alternates between +1 and -1 that gives the speed value direction when multiplied by it.. You will need checks in your act method (or a method it calls) for the conditions required to changed direction and when the conditions are met, multiply the direction field by -1 (which changes it to the other number; -1 to 1 and 1 to -1). The conditions for changing directions at the top or the bottom are two parters. For example, if the direction is currently up and the upper limit is reached, change directions; and similar for the lower limit. Actually, you d
How to make a car move either left or right when it is created?
By Tommy99, with 2 replies.
Last reply by danpost, over 11 years ago:
You should also move line 44 to after line 45 (call 'removeThis' last from the act method) or you will end up throwing IllegalStateException errors.
Buttons
By BeYouself, with 14 replies.
Last reply by danpost, over 11 years ago:
Can you drag the object around before clicking on 'Run'?
Hangman
By Peach, with 1 reply.
Replied to by danpost, over 11 years ago:
Not enough information and no apparent code attempt. Only thing I can say with what is given is "use either 'setLocation' or 'addObject'". I guess that 'drawString' or 'drawImage' would work also.
Long Strings
By cobarr, with 2 replies.
Last reply by cobarr, over 11 years ago:
Ah! Great, thanks for introducing me to the 'new line' escape sequence ('\n')!
Making a string disappear from screen
By cobarr, with 4 replies.
Last reply by cobarr, over 11 years ago:
Thank you! It works :)
Actor returning null
By dan11, with 2 replies.
Last reply by dan11, over 11 years ago:
Thank you very much, I even did it right in my other scenarios, don't know why I did that here.
Spam
By JetLennit, with 1 reply.
Replied to by davmac, over 11 years ago:
It's spam, plain and simple. As you can see it has been dealt with.
Create a String that disappears when RUN is clicked
By cobarr, with 1 reply.
Replied to by danpost, over 11 years ago:
There is a World class method called 'started'. It is by default an empty method; but is called when the project goes from a stopped state to a running state when that world is the active world. You can override the method in your world class an have it either remove the instruction actor or clear its image. <Code Omitted>
While loop in a world subclass crashes Greenfoot
By sp99, with 3 replies.
Last reply by Super_Hippo, over 11 years ago:
It is infinite since the program will never leave this loop. The 'loop' you want is probably the 'act' method. This is executed every act-cycle.
Choosing file frame
By Kartoffelbrot, with 2 replies.
Last reply by Kartoffelbrot, over 11 years ago:
Thank you!
Dragging desktop icons into a JFrame/Component
By Kartoffelbrot, with 5 replies.
Last reply by Kartoffelbrot, over 11 years ago:
Thank you
682
683
684
685
686
687
688
X