Java Game Programming - Making Enemies

preview_player
Показать описание

In episode 15 of Java Game Programming we lay the foundation for our Enemy class by creating our first adversary! We create a new class to store data about our enemy and implement our two new Tile methods to position him on the map with precision. In next week's episode we will begin our Clock which will allow our enemies, bullets, etc. to move around the screen!
Рекомендации по теме
Комментарии
Автор

this tutorial should have a lot more views! without knowing much you can still follow what the code is doing thanks to the great explanation. pls make a new, or a follow up tutorial. or maybe in another language. i tried so long to get started, but all the beginner tutorials are either to hard or to boring! you keep it easy and interesting!

ratzabur
Автор

These are the best tutorials ever. Thank you so much for making these and keep them coming it's awesome.

WillR
Автор

This will have been my first video game I've ever made and I am probably way too happy about it even though I'm just copying lol... it will make a great reference code for the future tho keep the videos coming, I am having way too much fun xP

PureNrGG
Автор

Excellent tutorials when you gonna do next video

anpapala
Автор

On line 38, its not letting me use QuickLoad despite having Artist imported
"The constructor Enemy(Texture, Tile, int, int, int) is undefined"
the line looks exactly the same as yours as well, no case issues either?
"Enemy e = new Enemy(QuickLoad("UFO"), grid.GetTile(10, 10), 64, 64, 2);"
and my image is just UFO, not UFO64 so that's not the issue either...
The full Boot:
ackage data;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import

import static org.lwjgl.opengl.GL11.*;
import static helpers.Artist.*;

public class Boot {
    
    public Boot() {
        
        BeginSession();
        
        int[][] map = {
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, },
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, },
                {1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, },
                {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
                {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, },
                {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, },
                {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, },
                {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, },
                {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, },
                {0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, },
                {0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 2, 0, 1, 1, 1, 1, 1, 0, 0, },
                {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, },
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, },
                {0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, },
        };
        
        
        TileGrid grid = new TileGrid(map);
        grid.SetTile(10, 4, grid.GetTile(11, 4).getType());
        Enemy e = new Enemy(QuickLoad("UFO"), grid.GetTile(10, 10), 64, 64, 2);
       {
            
            grid.Draw();
            e.Draw();
            
            Display.update();
            Display.sync(60);
        }
        
        Display.destroy();
    }
    
    public static void main(String[] args) {
        new Boot();
    }

}

I cant see whats wrong :\

haileyhart
Автор

I'm at a loss. I'm getting an error message that say "Could not find or load main class data.Boot"
The problem marker says "Could not delete '/Tower defense/bin/res'.".
I think I know why this is happening. It is because when I coded in my Enemy, it worked the first time, but it was too small compared to the other textures(I made my own design), so I made a new enemy design and deleted the other .png image in the workbench and replaced it with the new one. Unfortunately after doing this I can't even open up the game anymore and have no idea how to fix it. here's my Boot.java class:

package data;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import

import static org.lwjgl.opengl.GL11.*;

import static helpers.Artist.*;

public class Boot {

public Boot() {

BeginSession();

int[][] map = {
{2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},

};


TileGrid grid = new TileGrid(map);
grid.SetTile(3, 3, grid.GetTile(2, 3).getType());
Enemy e = new Enemy(QuickLoad("EyeDroid 64"), grid.GetTile(10, 10), 64, 64, 2);
{

grid.Draw();
e.Draw();

Display.update();
Display.sync(60);
}

Display.destroy();
}


public static void main(String[] args) {
new Boot();
}

}

supercow
Автор

I hate to comment on something so old, but with everything done exactly as it is in the video(except I made my own enemy that looks worse lol), my enemy won't show up in the game at all with Enemy e = new Enemy(Quickload("enemy TileType name"), grid.GetTile(0, 0), 64, 64, 2); and e.Draw. I can use grid.SetTile(0, 0, TileType.enemyName); to set the enemy tile in the grid, but it will not draw onto the grid over other tiles.

joshuabennett
Автор

Awesome! Hey, are you guys going to cover full screen and Sprite animations and sprite sheets at some point?

ThatEntityGirl
Автор

Hey wait, how do you make enemies move?! I can't seem to find how...

ThatEntityGirl
Автор

BTW guys change QuickLoad to ql to make it work!!!

nominatorchris