Hey everybody!
I'm fairly new to Greenfoot and I'm currently trying to program a Super Mario game where an enemy is capable of moving to the left and right on the ground while throwing balls to the left and to the right. My enemy can move around, but somehow throwing those balls at Mario isn't working out. They all fly to the right side. Could anyone please check my code and maybe tell me an easy fix that I'll be able to understand at my low skill level? Thanks in advance!
This is the code for the ball:
And this is the code for the enemy:
public class Schneeball extends Gegner { private int a; public void act() { if (Greenfoot.getRandomNumber(10) < 5) { setRotation(0); move(a); } else { setRotation(180); move(-a); } a++; if(isAtEdge()) { getWorld().removeObject(this); } } }
public class Häschen extends Gegner { private int speed = 10; //Legt Geschwindigkeit fest private int leftTurn = 50; //Legt die Umkehrpunktefest private int rightTurn = 1250; int count = 0; int count2 = 0; private GreenfootImage Häschen1 = new GreenfootImage("HäschenGegner100.png"); private GreenfootImage Häschen2 = new GreenfootImage("HäschenGegner100_2.png"); public boolean atTurningPoint() { return(getX() <= leftTurn || getX()>= rightTurn); } public void act() { setLocation (getX() + speed, getY() ); if (atTurningPoint() ) { speed = - speed; } count++; count2++; changeFoot(); if (count2 > 50) { //erzeugt Schneebälle Schneeball shot = new Schneeball(); shot.setRotation(this.getRotation()); getWorld().addObject(shot, this.getX(), this.getY()); count2 = 0; } } //Hier wird nicht mit For-Schleife gearbeitet, da sonst keine andere Aktion! public void changeFoot() { if(count<5) setImage(Häschen2); else{ if(count<10) { setImage(Häschen1); //Lässt am Wendepunkt das Bild spiegeln } else { count = 0; } } } }