Hello I'd like some help on this game that I want to make.
So, I am making a Game related to Zelda 1, with the same textures etc.
And I have been struggling with making an attack comment which is draining health.
I have 1 monster with the int health of 2 e.g.
And this sword attack should be based on the direction Link (the character you control) is facing.
I have 4 pictures (up down left right) of the sword attack but I can't seem to get a proper code checking for the direction so it can use the right image and when touching draining 1 health.
All that should happen when space is pressed, making Link invulenrable for the attack duration and dealing the damage.
I already thank you for helping me out!
PLEASE help me out. As you can see there is not much in it yet.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.*;
/**
* Link is the main character in this game.
* Link is controlled by the player using the Arrow Keys and the Space Bar.
* Link can receive a movement-boost by pressing the Shift-Button.
*
* @author (Tommy Simson & Andreas Fedorov)
* @version (1.0)
*/
public class Link extends Actor
{
/**
* Act - do whatever Link wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private GreenfootImage Down0 = new GreenfootImage("linkDown0.png");
private GreenfootImage Down1 = new GreenfootImage("linkDown1.png");
private GreenfootImage Left0 = new GreenfootImage("linkLeft0.png");
private GreenfootImage Left1 = new GreenfootImage("linkLeft1.png");
private GreenfootImage Right0 = new GreenfootImage("linkRight0.png");
private GreenfootImage Right1 = new GreenfootImage("linkRight1.png");
private GreenfootImage Up0 = new GreenfootImage("linkUp0.png");
private GreenfootImage Up1 = new GreenfootImage("linkUp1.png");
private GreenfootImage swordDown = new GreenfootImage("linkSwordDown.png");
private GreenfootImage swordLeft = new GreenfootImage("linkSwordLeft.png");
private GreenfootImage swordUp = new GreenfootImage("linkSwordUp.png");
private GreenfootImage swordRight = new GreenfootImage("linkSwordRight.png");
//Links health
public static int health = 5;
//Variable for Animation
private static int spin = 20;
public static boolean isAttacking = false;
public static boolean isGameOver = false;
public static boolean isKnockback = false;
public static GameOverScreen gos = new GameOverScreen();
public void act()
{
keyMove();
//Checks if Link has ran out of hearts --> Leading to GameOver
if(isGameOver == true){
setImage("linkDown0.png");
Greenfoot.delay(spin);
setImage("linkLeft0.png");
Greenfoot.delay(spin);
setImage("linkUp0.png");
Greenfoot.delay(spin);
setImage("linkRight0.png");
Greenfoot.delay(spin);
setImage("linkDown0.png");
Greenfoot.delay(spin);
setImage("linkLeft0.png");
Greenfoot.delay(spin);
setImage("linkUp0.png");
Greenfoot.delay(spin);
setImage("linkRight0.png");
Greenfoot.delay(spin);
setImage("linkDown0.png");
Greenfoot.delay(spin);
setImage("linkLeft0.png");
Greenfoot.delay(spin);
setImage("linkUp0.png");
Greenfoot.delay(spin);
setImage("linkRight0.png");
Greenfoot.delay(spin);
setImage("linkDown0.png");
setImage("deadLink.png");
//move(Direction.DOWN, 500);
this.getImage().setTransparency(0);
getWorld().addObject(gos, 400, 300);
Greenfoot.stop();
}
}
public void keyMove()
{
if(Greenfoot.isKeyDown("Right")){
setLocation(getX()+5, getY());
if (getImage() == Right0) {
setImage (Right1);
} else {
setImage(Right0);
}
}
if(Greenfoot.isKeyDown("Left")){
setLocation(getX()-5, getY());
if (getImage() == Left0) {
setImage (Left1);
} else {
setImage(Left0);
}
}
if(Greenfoot.isKeyDown("Up")){
setLocation(getX(), getY()-5);
if (getImage() == Up0) {
setImage (Up1);
} else {
setImage(Up0);
}
}
if(Greenfoot.isKeyDown("Down")){
setLocation(getX(), getY()+5);
if (getImage() == Down0) {
setImage (Down1);
} else {
setImage(Down0);
Greenfoot.delay(1);
}
}
}
public void attack() {
if(Greenfoot.getKey() == "space"){
if(getRotation() == 0) {
setImage(swordRight);
}
}
}
}