We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello I'm making simple game like rpg dungeon style
I want to my character attack enemy I created and kill it
But I have no idea how to do it now..
help me.. I'm newbee to code...
ArrayList <Flame> flames = new ArrayList<Flame>();
ArrayList <Eye> eyes = new ArrayList<Eye>();
sprite lilGuy;
PImage brick;
PImage wall;
PImage pillertop;
PImage pillerside;
PImage pillerside2;
PImage background;
PImage LOCK;
PImage pillerside3;
PImage bottomtile;
PImage pillertop3;
PImage lamp;
PImage keybox;
PImage bottomtile2;
int interval =80;
int last =0;
int GRID_TILE_WIDTH =48;
int GRID_TILE_HEIGHT = GRID_TILE_WIDTH;
int numFlames = 10;
int numEyes = 10;
int [][] worldGrid = {
{6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6},
{6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6},
{6,6,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,6,6,6},
{6,6,10,4,4,4,4,4,11,4,4,4,4,4,4,4,4,4,4,4,4,11,4,4,4,4,4,10,6,6,6},
{6,6,10,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,10,6,6,6},
{6,6,10,2,2,12,2,12,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,10,6,6,6},
{6,6,10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,10,6,6,6},
{3,3,10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,10,3,3},
{4,7,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,4,4},
{5,8,5,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,5,5,5},
{9,9,9,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,9,9,9},
{13,13,13,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,13,13,13},
{3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3},
{6,6,10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,10,6,6},
{6,6,10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,10,6,6},
{6,6,10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,10,6,6},
{6,6,10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,10,6,6},
{6,6,10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,10,6,6},
{6,6,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,6,6},
{6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6}
};
void setup(){
size (GRID_TILE_WIDTH*30, GRID_TILE_WIDTH*20);
noSmooth();
brick = loadImage("brick.jpg");
wall = loadImage("wall.png");
pillertop = loadImage("pillertop.jpg");
pillerside = loadImage("pillerside.png");
pillerside2 = loadImage("pillerside2.png");
background = loadImage("background.png");
LOCK = loadImage("LOCK.png");
pillerside3 = loadImage("pillerside3.png");
bottomtile = loadImage("bottomtile.png");
pillertop3 = loadImage("pillertop3.png");
lamp = loadImage("lamp.png");
keybox = loadImage("keybox.png");
bottomtile2 = loadImage("bottomtile2.png");
lilGuy= new sprite();
for (int i=0; i <numFlames; i++){
flames.add(new Flame());
}
for (int i=0; i <numEyes; i++){
eyes.add(new Eye());
}
}
void draw (){
background (#262626);
worldDrawGrid();
lilGuy.display();
for (int i=0; i <numFlames; i++){
flames.get(i).drawFlame();
}
for (int i=0; i <numEyes; i++){
eyes.get(i).drawEye();
}
}
void worldDrawGrid() {
noStroke();
for (int row=0; row<worldGrid.length; row++) {
for ( int col=0; col<worldGrid[row].length; col++) {
if (worldGrid[row][col]==1) {
image(wall, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==2){
image(brick, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==3){
image(pillertop, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==4){
image(pillerside, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==5){
image(pillerside2, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==6){
image(background, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==7){
image(LOCK, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==8){
image(pillerside3, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==9){
image(bottomtile, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==10){
image(pillertop3, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==11){
image(lamp, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==12){
image(keybox, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
} else if (worldGrid[row][col]==13){
image(bottomtile2, col*GRID_TILE_WIDTH, row*GRID_TILE_HEIGHT,GRID_TILE_WIDTH,GRID_TILE_WIDTH);
}
}
}
}
void keyPressed (){
switch (keyCode ){
case DOWN:
lilGuy.pDown= true;
break;
case UP:
lilGuy.pUp= true;
break;
case LEFT:
lilGuy.pLeft= true;
break;
case RIGHT:
lilGuy.pRight= true;
break;
}
lilGuy.moving = true;
}
void keyReleased (){
switch (keyCode ){
case DOWN:
lilGuy.pDown= false;
break;
case UP:
lilGuy.pUp= false ;
break;
case LEFT:
lilGuy.pLeft= false;
break;
case RIGHT:
lilGuy.pRight= false;
break;
}
}
boolean animTimer(){
if (millis()-last>= interval ){// millis keeps on counting
last= millis ();
return true;
} else {
return false;
}
}
class Enemy {
float x;
float y=0;
int size=10;
float speed;
color myColor=#FFFFFF;
boolean counted=false;
Enemy (float x, float speed) {
this.x=x;
this.speed=speed;
}
void display() {
fill(myColor);
move();
collision();
rect(x, y, size, size);
}
void move() {
y+=speed;
if (y>height) {
y=0;
x=random(width);
counted=false;
}
if (x<sprite.x) {
x=x+speed/6;
}
if (x>sprite.x) {
x=x-speed/6;
}
}
void collision() {
if (x>sprite.x-sprite.size/2 && x<sprite.x+sprite.size/2 && y>sprite.y-sprite.size/2 && y<sprite.y+sprite.size/2) {
myColor=#FF0055;
if (!counted){
score=score-10;
counted=true;
}
} else {
myColor=int(speed*50);
}
}
}
class sprite {
//-fields
PImage spriteSheet;
PImage mySprite [][];
int f=0;
boolean pDown, pUp, pLeft, pRight = false;
boolean moving = false;
int posX = width /2;
int posY = height/2;
int speed= 2;
int direction=0;
boolean playerhit;
int size = 10;
//-constructor
sprite(){
playerhit = true;
spriteSheet = loadImage ("example2.png");
mySprite = new PImage [4][3];
for (int row =0; row <4; row ++){
for (int col= 0; col <3; col ++){
mySprite [row][col]= spriteSheet.get (col*32, row*28, 32,28);
}
}
}
//-methods
void display (){
if (pDown){
direction =0 ;
posY+=speed;
} else if (pUp){
direction =1 ;
posY-=speed;
}else if (pLeft){
direction =2 ;
posX-=speed;
}else if (pRight) {
direction =3 ;
posX+=speed;
} else {
moving= false;
}
image (mySprite [direction][f], posX, posY, 32*3, 28*3);
if (moving && animTimer())f++;
if (f>=3)f=0;
}
}
}
``
Answers
https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text#latest
@TfGuy44 I just clear my codes line
That code doesn't run. First you have a mismatched }. Then it complains that wid and height are being set based on variables. Then it complains that there is no Flame class.
Even if I were to fix the first two things (and spoof your images), a missing class means that a major component of your code is missing.
If we can't run your code to see what is wrong, how are we possibly going to help?
@TfGuy44 I just checked my comment 5 min ago and I figured out the bracket problem I made. I should check it before I post and totally my fault . I know the wid and height are being set it is because that is the only way I know on making array I reposted my codes again and thank you for replying comments to remind me.
flame class still missing?
continued else where
@Chrisisr hey I'm trying run it but it has cannot find "sprite.x"