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
Making objects move different directions, and different speeds
By kayuhnjayuhn, with 13 replies.
Last reply by kayuhnjayuhn, over 11 years ago:
Okay that first one worked, thanks!
Sound Not Working
By mandyg233, with 23 replies.
Last reply by lordhershey, over 11 years ago:
--
Changing text
By mandyg233, with 16 replies.
Last reply by danpost, over 11 years ago:
Usually, the heap space error will occur when you are creating an abundance of actors or objects. Check your logic in your act methods and your loops.
Objects getting stuck at walls and edges?
By Tommy99, with 4 replies.
Last reply by danpost, over 11 years ago:
You may get some weird facing actions with the way the movement is coded. You could end up moving one way while facing another if two direction keys are pressed simultaneously. Putting 'else's between the different direction checks may help; but then, if the first direction is not a valid one, the second one will not be checked..\ I would do the facing part first, before the moving part.
Oxygen Bar
By docinkc, with 1 reply.
Replied to by danpost, over 11 years ago:
A Bar is basically a Counter. A Counter changes its image to reflect a change in the value that it represents; a Bar is exactly the same. The only difference is what those changes in its images are. A Counter will always show a the current value in text form; a bar may also do this. But, the bar will update its image by adjusting the length of the bar itself; that is the only significant difference between the two. Although, in order to do this, it would need to know the maximum value allowed (and the minimum, if not assumed to be zero).
Platform problem
By VideoGame, with 6 replies.
Last reply by danpost, over 11 years ago:
danpost wrote...
If you code the horizontal movement first and keep the actor off the platform that way, it will not teleport anywhere (or go behind, of course).
What I meant by this was * move horizontally * check for left/right obstacles and move back if necessary * move vertically * check for above/below obstacles and move back if necessary Your 'move' method right now is doing both movements together before the checking.
Problems with a grid?
By Tommy99, with 5 replies.
Last reply by danpost, over 11 years ago:
For one thing, I am not sure if you intended this: but, your world cell-size is 20 and yet you are using 40 for a grid size. Maybe you meant to set CELL_SIZE to 20 (but I could be mistaken). Then, your wall would also need to be sized at 20.
Killing an enemy with multiple hits
By Svek, with 2 replies.
Last reply by lordhershey, over 11 years ago:
I would just put a member in each alien type, have the hit take one away, when it is less than 1 then do the removeObject call on the alien.
SmootheMover
By Master79, with 1 reply.
Replied to by danpost, over 11 years ago:
Looks like you cut part of the PepperJackCheese class code from the post. Also, the Cheese class might be important. It would be best to copy/paste the entire code of each class into individual 'code' embedding windows.
Connecting Pictures to Numbers
By Schoolboy123, with 1 reply.
Replied to by danpost, over 11 years ago:
Use an array of images. <Code Omitted>or <Code Omitted> The index (number) refers to each image. There is no need to work with the strings for the colors.
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.
682
683
684
685
686
687
688
X