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

2013/5/19

Who can help me?

chicarito chicarito

2013/5/19

#
I want to make the pacman in my game turn the way im walking. This is my code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Paggaman here. * * @author (your name) * @version (a version number or a date) */ public class Paggaman extends Actor { int score = 0; public void act(){ foundCoin(); Lost(); if (canmove() && WallUp() && Greenfoot.isKeyDown("up")){ setLocation(getX(), getY() - 1); }else{ if (canmove() && WallRight() && Greenfoot.isKeyDown("right")){ setLocation(getX() + 1, getY()); }else{ if (canmove() && WallDown() && Greenfoot.isKeyDown("down")){ setLocation(getX(), getY() + 1); }else{ if (canmove() && WallLeft() && Greenfoot.isKeyDown("left")){ setLocation(getX() - 1, getY()); } } } } } public boolean canmove(){ World myWorld = getWorld(); int x = getX(); int y = getY(); if (x >= myWorld.getWidth() || y >= myWorld.getHeight() || x < 0 || y < 0) { return false; } return true; } public boolean WallUp(){ Actor Around = getOneObjectAtOffset(0, -15, Around.class); Actor WallIn = getOneObjectAtOffset(0, -15, WallIn.class); if(Around != null){ return false; } else if (WallIn != null){ return false; } else{ return true; } } public boolean WallRight(){ Actor Around = getOneObjectAtOffset(+15, 0, Around.class); Actor WallIn = getOneObjectAtOffset(+15, 0, WallIn.class); if(Around != null){ return false; } else if (WallIn != null){ return false; } else{ return true; } } public boolean WallDown(){ Actor Around = getOneObjectAtOffset(0, +15, Around.class); Actor WallIn = getOneObjectAtOffset(0, +15, WallIn.class); if(Around != null){ return false; } else if (WallIn != null){ return false; } else{ return true; } } public boolean WallLeft(){ Actor Around = getOneObjectAtOffset(-15, 0, Around.class); Actor WallIn = getOneObjectAtOffset(-15, 0, WallIn.class); if(Around != null){ return false; } else if (WallIn != null){ return false; } else{ return true; } } public boolean foundCoin(){ Actor Coin = getOneObjectAtOffset(0, 0, Coin.class); if(Coin != null){ getWorld().removeObject(Coin); score = score + 1; } else{ return false; } return false; } public boolean getLost() { Actor Ghost = getOneObjectAtOffset( 15, 15, Ghost.class); return Ghost != null; } public void Lost() { if(getLost()) { Greenfoot.setSpeed(0); } } }
chicarito chicarito

2013/5/19

#
please?
Gevater_Tod4711 Gevater_Tod4711

2013/5/19

#
What's the problem with this code?
danpost danpost

2013/5/19

#
This: Greenfoot.setSpeed(0); should probably be this: Greenfoot.stop(); The last statement in your foundCoin method: return false; should probably be this: return true; The first two statements in your act method: foundCoin(); Lost(); should probably be the last two statements in your act method. In your getLost method, this: Actor Ghost = getOneObjectAtOffset( 15, 15, Ghost.class); should probably be this: Actor Ghost = getOneObjectAtOffset(0, 0, Ghost.class); or possibly even this: Actor Ghost = getOneIntersectingObject(Ghost.class); Finally, by convention, all variable and method names should begin with a lowercase letter; so you should be using: Actor ghost = ... Actor wallIn = ... Actor around = ... wallUp() wallDown() wallRight() wallLeft() lost()
chicarito chicarito

2013/5/20

#
Thanks, but i only want ask you guys how i can make the image of my pacman turn the direction im walking
You need to login to post a reply.