Question: I need help with this , running it does not show the animation, i created two Rect classes , Sprite class and Animation class. import

I need help with this , running it does not show the animation, i created two Rect classes , Sprite class and Animation class.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class GameDriver extends Applet implements Runnable, KeyListener, MouseListener, MouseMotionListener
{
int mx =-1;
int my =-1;
Image beast = Toolkit.getDefaultToolkit().getImage("beastlands.png");
//Animation animation = new Animation("G_Jump", 100,100);
//Rect2 good = new Rect2(560,200,30,30);
//Rect bad = new Rect(800,600,30,30);
Rect2[] wall =
{
new Rect2(42,518,137,63),
new Rect2(684,567,61,124),
new Rect2(880,326,268,48),
new Rect2(217,587,473,97),
new Rect2(744,567,600,30),
new Rect2(20,564,75,102),
new Rect2(131,565,70,87),
new Rect2(659,312,90,66),
new Rect2(872,424,108,140),
new Rect2(836,469,55,104),
new Rect2(728,470,88,211),
};
boolean Jump_Pressed = false;
boolean Attack_Pressed = false;
boolean Run_Pressed = false;
boolean Walk_Pressed = false;
Image offScreenImg;
Graphics offScreenPen;
String[] pose ={"Dead", "Jump", "JaumpAttack", "Run", "Idle", "Walk", "Attack"};
Sprites soldier = new Sprites("G", pose, 100,500,9,15);
public void run()
{
// Game Loop
while(true)
{
//if(LT_Pressed) good.moveLT(10);
//if(RT_Pressed) good.moveRT(10);
//if(UP_Pressed) good.moveUP(10);
//if(DN_Pressed) good.moveDN(10);
//bad.chase(good,7);
for(int i =0; i < wall.length; i++)
{
// if(good.overlaps(wall[i])) good.pushedOutOf(wall[i]);
//if( bad.overlaps(wall[i])) bad.pushedOutOf(wall[i]);
}
//leftwall.moveBy(0,10);
repaint();
try
{
Thread.sleep(16);
}
catch(Exception x){};
}
}
public void update(Graphics pen)
{
pen.clearRect(0,0,1200,800);
paint(pen);
}
public void paint(Graphics pen)
{
pen.setColor(Color.BLACK);
double scale =0.5;
pen.drawImage(beast,0,0,1300,800, null);
//pen.drawImage(animation.nextImage(),100,100, null);
soldier.draw(pen);
//good.draw(pen);
//bad.draw(pen);
//
for(int i =0; i < wall.length; i++)
{
wall[i].draw(pen);
}
}
public void init()
{
addKeyListener(this);
requestFocus();
addMouseListener(this);
addMouseMotionListener(this);
Thread t = new Thread(this);
t.start();
}
public void mouseMoved(MouseEvent e)
{
}
public void mouseDragged(MouseEvent e)
{
int nx = e.getX();
int ny = e.getY();
int dx = nx - mx;
int dy = ny - my;
for(int i =0; i < wall.length; i++)
{
if(wall[i].resizer.held) wall[i].resizeBy(dx, dy);
else
if(wall[i].held) wall[i].moveBy(dx, dy);
}
mx = nx;
my = ny;
}
public void mousePressed(MouseEvent e)
{
mx = e.getX();
my = e.getY();
for(int i =0; i < wall.length; i++)
{
if(wall[i].contains(mx, my)) wall[i].grabbed();
if(wall[i].resizer.contains(mx, my)) wall[i].resizer.grabbed();
}
}
public void mouseReleased(MouseEvent e)
{
for(int i =0; i < wall.length; i++)
{
wall[i].dropped();
wall[i].resizer.dropped();
}
}
public void keyPressed(KeyEvent e)
{
int code = e.getKeyCode();
if (code == e.VK_UP ) Jump_Pressed = true;
if (code == e.VK_DOWN ) Attack_Pressed = true;
if (code == e.VK_LEFT ) Run_Pressed = true;
if (code == e.VK_RIGHT) Walk_Pressed = true;
if (code == e.VK_P)
{
for(int i =0; i < wall.length; i++)
{
System.out.println(wall[i]);
}
}
}
public void keyReleased(KeyEvent e)
{
int code = e.getKeyCode();
if (code == e.VK_UP ) Jump_Pressed = false;
if (code == e.VK_DOWN ) Attack_Pressed = false;
if (code == e.VK_LEFT ) Run_Pressed = false;
if (code == e.VK_RIGHT) Walk_Pressed = false;
}
public void keyTyped(KeyEvent e){}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!