Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

animationtest.Mario

By: SubzeroX5 on Jul 17th, 2011  |  syntax: Java  |  size: 3.05 KB  |  views: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package animationtest.Mario;
  2.  
  3. import animationtest.Animation;
  4. import animationtest.Sprite;
  5. import java.awt.*;
  6. import java.awt.image.BufferStrategy;
  7. import javax.swing.*;
  8.  
  9. public class MarioFrames {
  10.  
  11.     public Animation irFrames;
  12.     public Sprite irSprites;
  13.  
  14.     public void allFrames() {
  15.             ilFrames();
  16.             irFrames();
  17.     }
  18.  
  19.     public Sprite irFrames() {
  20.         Image mario1 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/IRFrame0.png")).getImage();
  21.         Image mario2 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/IRFrame1.png")).getImage();
  22.         Image mario3 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/IRFrame2.png")).getImage();
  23.         Image mario4 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/IRFrame3.png")).getImage();
  24.         Image mario5 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/IRFrame4.png")).getImage();
  25.  
  26.         irFrames = new Animation();
  27.         irFrames.addScene(mario1, 130);
  28.         irFrames.addScene(mario2, 130);
  29.         irFrames.addScene(mario3, 130);
  30.         irFrames.addScene(mario4, 130);
  31.         irFrames.addScene(mario5, 130);
  32.  
  33.         irSprites = new Sprite(irFrames);
  34.         irSprites.setVelocityX(0f);
  35.         irSprites.setVelocityY(0f);
  36.  
  37.         return irSprites;
  38.     }
  39.     public Animation ilFrames;
  40.     public Sprite ilSprites;
  41.  
  42.     public Sprite ilFrames() {
  43.         Image mario1 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/ILFrame0.png")).getImage();
  44.         Image mario2 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/ILFrame1.png")).getImage();
  45.         Image mario3 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/ILFrame2.png")).getImage();
  46.         Image mario4 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/ILFrame3.png")).getImage();
  47.         Image mario5 = new ImageIcon(this.getClass().getResource("/animationtest/Mario/IdleFrames/ILFrame4.png")).getImage();
  48.  
  49.         ilFrames = new Animation();
  50.         ilFrames.addScene(mario1, 130);
  51.         ilFrames.addScene(mario2, 130);
  52.         ilFrames.addScene(mario3, 130);
  53.         ilFrames.addScene(mario4, 130);
  54.         ilFrames.addScene(mario5, 130);
  55.  
  56.         ilSprites = new Sprite(ilFrames);
  57.         ilSprites.setVelocityX(0f);
  58.         ilSprites.setVelocityY(0f);
  59.  
  60.         return ilSprites;
  61.     }
  62.     public Sprite currentSprite = null;
  63.  
  64.  
  65. }
  66.  
  67. public class MarioMoves extends MarioFrames {
  68.  
  69.     public MarioMoves() {
  70.         currentSprite = irFrames();
  71.  
  72.     }
  73.  
  74.     public void keyPressed(KeyEvent e) {
  75.         int keyCode = 0;
  76.         keyCode = e.getKeyCode();
  77.         if (keyCode == KeyEvent.VK_RIGHT) {
  78.             currentSprite = irFrames();
  79.  
  80.         }
  81.         if (keyCode == KeyEvent.VK_LEFT) {
  82.             currentSprite = ilFrames();
  83.         }
  84.     }
  85.  
  86.     public Sprite currentSprite() {
  87.         return currentSprite;
  88.     }
  89. }