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

2015/10/15

Receiving False positives:

ando600 ando600

2015/10/15

#
Hello again, still working on that mortal kombat game. I put in a function to check if certain conditions are true, and am getting false positives. I pass values between two classes, and i may be messing them up that way. HERE IS THE FIRST CLASS: import greenfoot.*; /** * Write a description of class FighterTwo here. * * @author (your name) * @version (a version number or a date) */ public class FighterOne extends Animal { GifImage currentGif; private int speed = 4; private int vSpeed = 0; private int acceleration = 1; private int jumpStrength = 14; private int jumpCounter = 0; private int jumpCounterAnimation = 0; private int fightCounterAnimation = 0; private int launchCounter = 0; private int ballCounter = 0; private int kneeCounterAnimation = 0; private GifImage stand = new GifImage("fighterOneStand.gif"); private GifImage walkBack = new GifImage("fighterOneWalkBa.gif"); private GifImage block = new GifImage("oneBlock.gif"); private GifImage run = new GifImage("oneRun.gif"); private GifImage flipJump = new GifImage("jumpThree.gif"); private GifImage punchOne = new GifImage("fighterOnePunch.gif"); private GifImage launchMove = new GifImage("launchMove.gif"); private GifImage knee = new GifImage("kneeOne.gif"); public boolean blockStateOne, punchStateOne, kneeStateOne; private int damageState; /** * Check keyboard input and act accordingly */ public void act() { damageState = ((hitBoxOne) getWorld().getObjects(hitBoxOne.class).get(0)).getShared(); checkDamage(); checkKeys(); setGif(); checkFall(); setImage(currentGif.getCurrentImage()); getKneeStateOne(); getPunchStateOne(); getBlockStateOne(); ballCounter++; } public boolean getKneeStateOne() { if (kneeStateOne == true) { return true; } return false; } public boolean getPunchStateOne() { if (punchStateOne == true) { return true; } return false; } public boolean getBlockStateOne() { if (blockStateOne == true) { return true; } return false; } private void checkDamage() { if (damageState == 12) { jump(); return; } } private void setGif() { blockStateOne = false; punchStateOne = false; kneeStateOne = false; if (Greenfoot.isKeyDown("h")) { launchCounter = 4; } if (launchCounter > 0) { launchCounter = (launchCounter -1); currentGif = launchMove; try { Thread.sleep(11); } catch (InterruptedException e) { return; } return; } if (Greenfoot.isKeyDown("f")) { currentGif = block; blockStateOne = true; return; } if (Greenfoot.isKeyDown("a")) { currentGif = walkBack; return; } if (Greenfoot.isKeyDown("d")) { currentGif = run; return; } if (Greenfoot.isKeyDown("w")) { jumpCounterAnimation = 18; } if (jumpCounterAnimation > 0) { jumpCounterAnimation = (jumpCounterAnimation -1); currentGif = flipJump; try { Thread.sleep(11); } catch (InterruptedException e) { return; } return; } if (Greenfoot.isKeyDown("g")) { fightCounterAnimation = 8; } if (fightCounterAnimation > 0) { fightCounterAnimation = (fightCounterAnimation -1); currentGif = punchOne; punchStateOne = true; try { Thread.sleep(11); } catch (InterruptedException e) { return; } return; } if (Greenfoot.isKeyDown("s")) { kneeCounterAnimation = 4; } if (kneeCounterAnimation > 0) { kneeCounterAnimation = (kneeCounterAnimation -1); currentGif = knee; kneeStateOne = true; try { Thread.sleep(15); } catch (InterruptedException e) { return; } return; } else { currentGif = stand; return; } } private void checkKeys() { if (Greenfoot.isKeyDown("z")) { blockStateOne = true; return; } if (Greenfoot.isKeyDown("a")) { move(-3); return; } if (Greenfoot.isKeyDown("d")) { move(5); return; } if (Greenfoot.isKeyDown("w")) { jumpCounter++; if (jumpCounter==2) { jumpCounter = 0; jump(); return; } return; // Greenfoot.playSound("jump.wav"); } if (Greenfoot.isKeyDown("h")){ if (ballCounter > 100) { ballCounter = 0; int x = getX()+61; int y = getY()-60; getWorld().addObject(new Ki_Ball(), x, y); return; } return; } } public void jump() { if (onRoad()) { vSpeed = -jumpStrength; fall(); } } public void checkFall() { if(onRoad()) { vSpeed = 0; } else { fall(); } } public boolean onRoad() { Actor under = getOneObjectAtOffset ( 0, getImage().getHeight() / 2-8, Road.class); return under !=null; } public void fall() { setLocation ( getX(), getY() + vSpeed ); vSpeed = vSpeed + acceleration; } public void moveRight() { setLocation ( getX() - speed, getY() ); } public void moveLeft() { setLocation ( getX() - speed, getY() ); } } HERE IS THE SECOND CLASS: import greenfoot.*; import static java.lang.Math.*; /** * Write a description of class hitBoxOne here. * * @author (your name) * @version (a version number or a date) */ public class hitBoxOne extends FighterOne { private int moveSpeed; private boolean kneeState, punchState; private boolean blockState = false; /** * Act - do whatever the hitBoxOne wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { punchState = ((FighterOne) getWorld().getObjects(FighterOne.class).get(0)).getPunchStateOne(); kneeState = ((FighterOne) getWorld().getObjects(FighterOne.class).get(0)).getKneeStateOne(); blockState = ((FighterOne) getWorld().getObjects(FighterOne.class).get(0)).getBlockStateOne(); moveTo(); getShared(); findDamage(); } private void moveTo() { Actor player = (Actor) getWorld().getObjects(FighterOne.class).get(0); turnTowards(player.getX(), player.getY()); moveSpeed = (Math.abs(player.getX() - getX()) + Math.abs(player.getY() - getY())); move(moveSpeed); } private void findDamage() { if (blockState = true) { int x = getX()+70; int y = getY(); getWorld().addObject(new Ki_Ball(), x, y); return; } } public int getShared() { Actor Ki_Ball = getOneIntersectingObject(Ki_Ball.class); if (Ki_Ball != null) { getWorld().removeObject(Ki_Ball); return 12; } return 0; } } Thank you. I apologize for the length of my code.
ando600 ando600

2015/10/15

#
Never mind. I found the error. I apologize for posting this.
You need to login to post a reply.