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
Spawn actor a certain distance from other actor
By Prox276, with 5 replies.
Last reply by Prox276, over 8 years ago:
Oh, I've already found it out myself. Thanks
How to change the music with a button?
By Recorsi, with 4 replies.
Last reply by Recorsi, over 8 years ago:
Thanks for your help
How to a character can move down??
By squad3007, with 1 reply.
Replied to by danpost, over 8 years ago:
squad3007 wrote...
how a character can move down??
You can use this: <Code Omitted>or this: <Code Omitted>
Greenfoot.stop() not working
By GreenFootTeachet70, with 5 replies.
Last reply by danpost, over 8 years ago:
GreenFootTeachet70 wrote...
So the program now stops when the lobster touches the crab. I guess I will keep plodding on in my tutorial. Eventually, it must tell us how to have a collision and remove the object and replace it with another object.
I am not sure that it will give both at the same time, but certainly it will at some point show adding an actor from within an Actor subclass (smoke for bouncy balls in Joy of Code videos).
Publishing a scenario on html5
By basar1, with 2 replies.
Last reply by basar1, over 8 years ago:
How can I run my game in the internet on my own?
How would i swtich worlds if I want two actors touching each other?
By applecider124, with 1 reply.
Replied to by danpost, over 8 years ago:
Line 44 is troublesome. You cannot assume that there is a first element in a list you do not create yourself (it is created through code you yourself did not create). If no Shark object is in the world, you will get an IndexOutOfBoundsException error. As long as a Shark object is in the world (the error is not thrown), line 45 will always be true. That is, you will never have
null
as the value of the actor,
a
. A more precise gameOver method might be this:
Timer
By Heet_Patel, with 32 replies.
Last reply by davmac, over 8 years ago:
If you want everything else to stop but one actor (the health bar) to continue, you need to have all the other actors check some global state to determine whether they should act or not. For example, add a boolean variable into the world, read it from each actor - except the health bar - and act only if it is true. Set it to false when you want all the actors other than the health bar to stop.
Remove Objects
By codecodecode, with 2 replies.
Last reply by danpost, over 8 years ago:
You were probably getting the error when the first one reached the left edge of the world (and after a small number of them were spawned behind it). The fix suggested by
jamesN616
will probably stop the error from happening. More simply might be this: <Code Omitted>However, don't you have more issues here? like non-removal while collisions are occurring while crossing the map? or, sometimes too many objects being spawned and sometimes spawning ceases to occur?
Actor gets randomly stuck in ground / Spielfigur steckt im Boden fest
By Chrizzi, with no replies.
Hello, I have a Little Problem with my Scenario, I made a Little Jump 'n' run game, but the actor randomly gets stuck in the ground a bit, so if I want to jump, I Need to press the key many times, until the actor gets above the ground. Here is the Code of the actor: Hallo, ich habe ein kleines Problem mit meinem Szenario, es ist ein kleines Jump 'n' Run Spiel und das Problem ist, dass die Spielfigur manchmal im Boden feststeckt, z.B. wenn ich springe, muss ich die Sprungtaste sehr oft drücken, bis der Charakter aus dem Boden rauskommt. Hier ist das Programm für den Charaker: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.io.*; /** * Write a description of class Marcel here. * * @author (your name) * @version (a version number or a date) */ public class Marcel extends Actor { long timer = System.currentTimeMillis(); Writer writer = null; int speed = 2; int jumpHeight = 200; static boolean schuss = false; static int leben; boolean start = true; boolean gedrueckt; static boolean losgelassen = false; int fallSpeed = 5; int direction = 0; static boolean spawnItem; static int MarcelX; static int MarcelY; static int lf; static int euro; static boolean right; static boolean left; static int px; static int py; static int lvl; boolean tot; public Marcel(){ this.setImage(read("SOOS/char_texture/0x00_texture1.txt")); tot = false; leben = 1; spawnItem = false; lf = 3; right = true; left = true; } /** * Act - do whatever the Marcel 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. if(!tot){ move("left","right","space"); schuss("enter"); } kys(); crrds(); px = getX(); py = getY(); stuck(); pressSwitch(); } boolean collisionDetection(java.lang.Class thing){ Actor stuff = getOneIntersectingObject(thing); return stuff != null; } void move(String keyLeft, String keyRight, String keyJump){ if(Greenfoot.isKeyDown(keyLeft)==true&&left==true){ moveLeft(); direction = -1; if(schuss == false){ Bullet.dir = Bullet.bulletSpeed * -1; } } if(Greenfoot.isKeyDown(keyRight)==true&&right==true){ moveRight(); direction = 1; if(schuss == false){ Bullet.dir = Bullet.bulletSpeed; } } /*if(Greenfoot.isKeyDown(keyJump)){ jump(); } else { fall(); }*/ if(onGround(Jump.class)==false){ jump("space"); } if(onGround(Jump.class)==true){ spring(); } if(jump("space")==false){ fall(); } } void moveLeft(){ this.setLocation(getX() - speed, getY()); } void moveRight(){ this.setLocation(getX() + speed, getY()); } boolean jump(String jumpKey){ boolean jumping = false; if(Greenfoot.isKeyDown(jumpKey) && (onGround(Ground.class)==true||onGround(Ground_half.class)==true||onGround(Block.class)==true)){ gedrueckt = true; } else { gedrueckt = false; } if(Greenfoot.isKeyDown(jumpKey) && (onGround(Ground.class)==true||onGround(Ground_half.class)==true||onGround(Block.class)==true)){ losgelassen = true; jumping = true; return jumping; } if(!gedrueckt && losgelassen == true){ int i; for(i=0;i<jumpHeight;i++){ this.setLocation(getX(), getY() - 1); if(collisionDetection(Block.class)){ i = jumpHeight; spawnItem = true; } if(collisionDetection(Ground.class)){ i = jumpHeight; } } losgelassen = false; jumping = false; return jumping; } return jumping; } void fall(){ if(onGround(Ground.class)||onGround(Block.class)||onGround(Door.class)||onGround(Ground_half.class)){ } else { this.setLocation(getX(), getY() + fallSpeed); } } boolean onGround(java.lang.Class grnd_type){ Actor under = getOneObjectAtOffset(0, (this.getImage().getHeight() / 2)+1, grnd_type); return under != null; } void schuss(String keyShot){ Bullet.mx = getX(); Bullet.my = getY(); if(Greenfoot.isKeyDown(keyShot)){ schuss = true; } else { schuss = false; } } void kys(){ if(this.getY() >= 599){ leben--; } if(collisionDetection(Gegner1.class)){ leben--; Gegner1.gegnerleben = 0; } if(collisionDetection(Gegner2.class)){ leben--; Gegner2.gegnerleben2 = 0; } if(collisionDetection(Gegner3.class)){ leben--; Gegner3.gegnerleben3 = 0; } if(collisionDetection(Gegner4.class)){ leben--; Gegner4.gegnerleben4 = 0; } if(leben <= 0){ lf--; leben = 1; if(Checkpoint.added && Checkpoint.reX != 0 && Checkpoint.reY != 0){ this.setLocation(convertStr("SOOS/0xFF_ReX.txt"), convertStr("SOOS/0yFF_ReY.txt")); } if(!Checkpoint.added){ this.setLocation(100, 423); } } if(lf <= 0){ write("SOOS/0xFF_ReX.txt","100"); write("SOOS/0yFF_ReY.txt","423"); write("SOOS/0xAB_Leben.txt","1"); write("SOOS/0xA0_Life.txt","3"); write("SOOS/0yAA_Lvl.txt","1"); write("SOOS/0y0C_Geld.txt","0"); Greenfoot.delay(50); drawGameover(); } } void drawGameover(){ getWorld().addObject(new Gameover1(), 500, 300); getWorld().addObject(new Gameover2(), 500, 500); tot = true; this.getImage().clear(); } void crrds(){ MarcelX = getX(); MarcelY = getY(); } void setCoins(int cs){ euro = cs; } void stuck(){ if(!left&&!right){ this.setLocation(getX(), getY()-20); } } void spring(){ if(collisionDetection(Jump.class)==true&&jump("Space")==true){ for(int i=0;i<150;i++){ this.setLocation(getX(), getY() - 1); if(collisionDetection(Block.class)){ i = 100; spawnItem = true; } } } } void pressSwitch(){ if(onGround(Switch.class)){ Switch.pressed = true; Door.open = true; } } void write(String dir, String txt) { String fileName = dir; try { FileWriter fileWriter = new FileWriter(fileName); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(txt); bufferedWriter.close(); } catch(IOException ex) { System.out.println( "Error writing to file '" + fileName + "'"); } } String read(String dir) { String fileName = dir; String line = null; try { FileReader fileReader = new FileReader(fileName); BufferedReader bufferedReader = new BufferedReader(fileReader); while((line = bufferedReader.readLine()) != null) { return line; } bufferedReader.close(); } catch(FileNotFoundException ex) { System.out.println( "Unable to open file '" + fileName + "'"); } catch(IOException ex) { System.out.println( "Error reading file '" + fileName + "'"); } return line; } int convertStr(String dir){ String str = read(dir); int value = Integer.parseInt(str); return value; } }
Help with getRotation()
By emystery, with 1 reply.
Replied to by danpost, over 8 years ago:
I think you might be better off not changing the rotation of the actor and using a "
facing
" int field to indicate the horizontally facing direction. If I recall correctly, you already had the two fields "
direction
" and "
rotation
" in the class -- either not used (
rotation
) or not being updated when needed (
direction
). Both these fields are to be removed once the
facing
field is implemented. The
facing
field should change only between the values of '1' (right) and '-1' (left). It should be adjusted according to movement key input and it should
Help with actor falling through the floor randomly
By spencer_h, with 2 replies.
Last reply by spencer_h, over 8 years ago:
I fixed the issue. It was an issue with the antiNoClip() method
Random Image
By KKobra, with 1 reply.
Replied to by danpost, over 8 years ago:
One way is to split each line up so you can set their images: <Code Omitted>
Help with world casting and how to make it work
By Shade1177, with 5 replies.
Last reply by Shade1177, over 8 years ago:
ok ill try to set something like that tonight then and come back to you if i need help... thanks for giving me and idea on what to do... ill try your suggestion and see how it turns out
How to Recover my scenerio
By Vihuleapord, with 4 replies.
Last reply by Heet_Patel, over 8 years ago:
Yeah you do. Do you have a mac or windows. If you didn't then you can look at the mac trash and the windows recycling bin
Help required. Collision/End Game
By llEnigma, with 2 replies.
Last reply by Heet_Patel, over 8 years ago:
Does it work now
256
257
258
259
260
261
262
X