[READ-ONLY] Mirror of https://github.com/jackmawer/ProjectRain.
0

Configure Feed

Select the types of activity you want to include in your feed.

Update to newer code

Jack Mawer (Sep 15, 2014, 9:09 PM +0100) 20799571 c59ccfa3

+293 -7
bin/com/mawersoft/projrain/Game.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/entity/mob/Mob.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/entity/mob/Player.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/entity/projectile/Projectile.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/entity/projectile/WizardProjectile.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/graphics/Screen.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/graphics/Sprite.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/graphics/SpriteSheet.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/input/Keyboard.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/input/Mouse.class

This is a binary file and will not be displayed.

bin/com/mawersoft/projrain/level/Level.class

This is a binary file and will not be displayed.

res/textures/sheets/projectiles/wizard.png

This is a binary file and will not be displayed.

res/textures/sheets/projectiles/wizard.xcf

This is a binary file and will not be displayed.

+33 -4
src/com/mawersoft/projrain/Game.java
··· 13 13 import com.mawersoft.projrain.entity.mob.Player; 14 14 import com.mawersoft.projrain.graphics.Screen; 15 15 import com.mawersoft.projrain.input.Keyboard; 16 + import com.mawersoft.projrain.input.Mouse; 16 17 import com.mawersoft.projrain.level.Level; 17 18 import com.mawersoft.projrain.level.RandomLevel; 18 19 import com.mawersoft.projrain.level.SpawnLevel; ··· 24 25 */ 25 26 private static final long serialVersionUID = 1L; 26 27 // 27 - public static int width = 300; 28 - public static int height = width / 16 * 9; 29 - public static int scale = 3; 30 - public static String ver = "0.0.4"; 28 + private static int width = 300; 29 + private static int height = width / 16 * 9; 30 + private static int scale = 3; 31 + public static String ver = "0.0.5"; 31 32 //public static String title = "ProjRain"; 32 33 public static String title = "Project Rain "+ver; 34 + public int currentFPS; 35 + public int currentTPS; 33 36 34 37 private Thread thread; 35 38 private JFrame frame; ··· 56 59 player = new Player(playerSpawn.x(), playerSpawn.y(), key); 57 60 player.init(level); 58 61 addKeyListener(key); 62 + 63 + Mouse mouse = new Mouse(); 64 + addMouseListener(mouse); 65 + addMouseMotionListener(mouse); 66 + } 67 + 68 + public static int getWindowWidth() { 69 + return width * scale; 70 + } 71 + 72 + public static int getWindowHeight() { 73 + return height * scale; 59 74 } 60 75 61 76 // ··· 103 118 timer += 1000; 104 119 //System.out.println(ticks + "Ticks " + frames + " FPS"); //Print info to console if needed. 105 120 frame.setTitle(title + " | " + ticks + "TPS " + frames + " FPS"); 121 + currentFPS = frames; 122 + currentTPS = ticks; 106 123 ticks = 0; 107 124 frames = 0; 108 125 } ··· 115 132 //In the tutorial, tick = update 116 133 key.update(); 117 134 player.update(); 135 + level.update(); 118 136 119 137 } 120 138 ··· 139 157 //g.setColor(Color.BLACK);//Testing only 140 158 //g.fillRect(0, 0, getWidth(), getHeight() );//Testing only 141 159 g.drawImage(image, 0, 0, getWidth(), getHeight(), null); 160 + //g.fillRect(Mouse.getX() - 32, Mouse.getY() - 32, 64, 64); // Don't need it 161 + g.drawString("Project Rain by Jack Mawer, Version " + ver, 5, 10); 162 + g.drawString("CurrentMouseButton: " + Mouse.getB(), 5, 20); 163 + g.drawString("MouseX: " + Mouse.getX() + " MouseY:" +Mouse.getY(), 5, 30); 164 + //g.drawString("PlayerX: " + + " PlayerY: " + , 5, 40); // Broken... 165 + g.drawString("TPS: " + currentTPS + " FPS: " + currentFPS, 5, 40); 166 + if (currentFPS >= 60) g.drawString("Your FPS is great!", 5, 50); 167 + if (currentFPS >= 30 && currentFPS < 60) g.drawString("Your FPS is good", 5, 50); 168 + if (currentFPS >= 10 && currentFPS < 30) g.drawString("Your FPS is bad...", 5, 50); 169 + if (currentFPS >= 1 && currentFPS < 10) g.drawString("Your FPS is terrible!", 5, 50); 170 + 142 171 g.dispose(); 143 172 bs.show();//If using testing code, disable me 144 173 }
+1 -1
src/com/mawersoft/projrain/entity/Entity.java
··· 7 7 8 8 public abstract class Entity { 9 9 10 - public int x, y; 10 + public int x,y; 11 11 public boolean removed = false; 12 12 protected Level level; 13 13 protected final Random random = new Random();
+15
src/com/mawersoft/projrain/entity/mob/Mob.java
··· 1 1 package com.mawersoft.projrain.entity.mob; 2 2 3 + import java.util.ArrayList; 4 + import java.util.List; 5 + 3 6 import com.mawersoft.projrain.entity.Entity; 7 + import com.mawersoft.projrain.entity.projectile.Projectile; 8 + import com.mawersoft.projrain.entity.projectile.WizardProjectile; 4 9 import com.mawersoft.projrain.graphics.Sprite; 10 + import com.mawersoft.projrain.level.Level; 5 11 6 12 public abstract class Mob extends Entity { 7 13 8 14 protected Sprite sprite; 9 15 protected int dir = 0;// 0 N, 1 E, 2 S, 3 W 10 16 protected boolean moving = false; 17 + 18 + 11 19 12 20 public void move(int xa, int ya) { 13 21 ··· 28 36 } 29 37 30 38 public void update() { 39 + } 40 + 41 + protected void shoot(int x, int y, double dir) { 42 + //dir *= 182 / Math.PI; 43 + //System.out.println("Angle: " + dir); 44 + Projectile p = new WizardProjectile(x, y, dir); 45 + level.addProjectile(p); 31 46 } 32 47 33 48 private boolean collision(int xa, int ya) {
+27 -1
src/com/mawersoft/projrain/entity/mob/Player.java
··· 1 1 package com.mawersoft.projrain.entity.mob; 2 2 3 + import com.mawersoft.projrain.Game; 4 + import com.mawersoft.projrain.entity.projectile.Projectile; 5 + import com.mawersoft.projrain.entity.projectile.WizardProjectile; 3 6 import com.mawersoft.projrain.graphics.Screen; 4 7 import com.mawersoft.projrain.graphics.Sprite; 5 8 import com.mawersoft.projrain.input.Keyboard; 9 + import com.mawersoft.projrain.input.Mouse; 6 10 7 11 public class Player extends Mob { 8 12 ··· 11 15 private int anim = 0; 12 16 private boolean walking = false; 13 17 18 + private int fireRate = 0; 19 + 14 20 15 21 public Player(Keyboard input) { 16 22 this.input = input; ··· 22 28 this.y = y; 23 29 this.input = input; 24 30 sprite = Sprite.player_forward; 31 + fireRate = WizardProjectile.FIRE_RATE; 25 32 } 26 33 27 34 public void update() { 35 + if (fireRate > 0) fireRate--; 28 36 int xa = 0, ya = 0; 29 37 if (anim < 7500) anim++; 30 38 else anim = 0; ··· 32 40 if (input.down) ya++; 33 41 if (input.left) xa--; 34 42 if (input.right) xa++; 35 - 36 43 if (xa != 0 || ya != 0) { 37 44 move (xa, ya); 38 45 walking = true; 39 46 } else { 40 47 walking = false; 48 + } 49 + clear(); 50 + updateShooting(); 51 + } 52 + 53 + private void clear() { 54 + for (int i = 0; i < level.getProjectiles().size(); i++) { 55 + Projectile p = level.getProjectiles().get(i); 56 + if (p.isRemoved()) level.getProjectiles().remove(i); 57 + } 58 + } 59 + 60 + private void updateShooting() { 61 + if (Mouse.getB() == 1 && fireRate <=0) { 62 + double dx = Mouse.getX() - Game.getWindowWidth() / 3; 63 + double dy = Mouse.getY() - Game.getWindowHeight() / 2; 64 + double dir = Math.atan2(dy, dx); 65 + shoot(x, y, dir); 66 + fireRate = WizardProjectile.FIRE_RATE; 41 67 } 42 68 } 43 69
+39
src/com/mawersoft/projrain/entity/projectile/Projectile.java
··· 1 + package com.mawersoft.projrain.entity.projectile; 2 + 3 + import java.util.Random; 4 + 5 + import com.mawersoft.projrain.entity.Entity; 6 + import com.mawersoft.projrain.graphics.Sprite; 7 + 8 + public abstract class Projectile extends Entity { 9 + 10 + protected final int xOrigin, yOrigin; 11 + protected double angle; 12 + protected Sprite sprite; 13 + protected double x, y; 14 + protected double nx, ny; 15 + protected double distance; 16 + protected double speed, range, damage; 17 + 18 + protected final Random random = new Random(); 19 + 20 + public Projectile(int x, int y, double dir) { 21 + xOrigin = x; 22 + yOrigin = y; 23 + angle = dir; 24 + this.x = x; 25 + this.y = y; 26 + } 27 + 28 + public Sprite getSprite() { 29 + return sprite; 30 + } 31 + 32 + public int getSpriteSize() { 33 + return sprite.SIZE; 34 + } 35 + 36 + protected void move() { 37 + } 38 + 39 + }
+49
src/com/mawersoft/projrain/entity/projectile/WizardProjectile.java
··· 1 + package com.mawersoft.projrain.entity.projectile; 2 + 3 + import com.mawersoft.projrain.graphics.Screen; 4 + import com.mawersoft.projrain.graphics.Sprite; 5 + 6 + public class WizardProjectile extends Projectile { 7 + 8 + public static final int FIRE_RATE = 10; // higher = slower 9 + 10 + public WizardProjectile(int x, int y, double dir) { 11 + super(x, y, dir); 12 + range = random.nextInt(100) + 150; 13 + speed = 4; 14 + damage = 20; 15 + sprite = Sprite.projectile_wizard; 16 + 17 + nx = speed * Math.cos(angle); 18 + ny = speed * Math.sin(angle); 19 + } 20 + 21 + public void update() { 22 + if (level.tileCollision(x, y, nx, ny, 7)) remove(); 23 + move(); 24 + 25 + } 26 + 27 + 28 + 29 + protected void move() { 30 + 31 + x += nx; 32 + y += ny; 33 + 34 + if (distance() > range) remove(); 35 + } 36 + 37 + private double distance() { 38 + double dist = 0; 39 + dist = Math.sqrt(Math.abs((xOrigin - x) * (xOrigin - x) + (yOrigin - y) * (yOrigin - y))); 40 + return dist; 41 + } 42 + 43 + public void render(Screen screen) { 44 + 45 + screen.renderProjectile((int) x - 12, (int) y - 2, this); 46 + 47 + } 48 + 49 + }
+16
src/com/mawersoft/projrain/graphics/Screen.java
··· 3 3 import java.util.Random; 4 4 5 5 import com.mawersoft.projrain.entity.mob.Player; 6 + import com.mawersoft.projrain.entity.projectile.Projectile; 6 7 import com.mawersoft.projrain.level.tile.Tile; 7 8 8 9 public class Screen { ··· 57 58 if (xa < -tile.sprite.SIZE || xa >= width || ya < 0 || ya >= height) break; 58 59 if (xa < 0) xa = 0; 59 60 pixels[xa+ya*width] = tile.sprite.pixels[x+y*tile.sprite.SIZE]; 61 + } 62 + } 63 + } 64 + 65 + public void renderProjectile(int xp, int yp, Projectile p) { 66 + xp -= xOffset; 67 + yp -= yOffset; 68 + for (int y = 0; y < p.getSpriteSize(); y++) { 69 + int ya = y + yp; 70 + for (int x = 0; x < p.getSpriteSize(); x++) { 71 + int xa = x + xp; 72 + if (xa < -p.getSpriteSize() || xa >= width || ya < 0 || ya >= height) break; 73 + if (xa < 0) xa = 0; 74 + int col = p.getSprite().pixels[x+y*p.getSpriteSize()]; 75 + if (col != 0xffff00ff) pixels[xa+ya*width] = col; 60 76 } 61 77 } 62 78 }
+5
src/com/mawersoft/projrain/graphics/Sprite.java
··· 48 48 public static Sprite player_back_1 = new Sprite(32, 2, 6, SpriteSheet.tiles); 49 49 public static Sprite player_back_2 = new Sprite(32, 2, 7, SpriteSheet.tiles); 50 50 51 + 52 + //Projectile sprites 53 + public static Sprite projectile_wizard = new Sprite(16, 0, 0, SpriteSheet.projectile_wizard); 54 + 55 + 51 56 public Sprite(int size, int x, int y, SpriteSheet sheet) { 52 57 SIZE = size; 53 58 pixels = new int[SIZE * SIZE];
+2
src/com/mawersoft/projrain/graphics/SpriteSheet.java
··· 13 13 14 14 public static SpriteSheet tiles = new SpriteSheet("/textures/sheets/spritesheet.png", 256); 15 15 public static SpriteSheet spawn_level = new SpriteSheet("/textures/sheets/spawn_level.png", 48); 16 + public static SpriteSheet projectile_wizard = new SpriteSheet("/textures/sheets/projectiles/wizard.png", 48); 17 + 16 18 public SpriteSheet(String path, int size) { 17 19 this.path = path; 18 20 SIZE = size;
+1 -1
src/com/mawersoft/projrain/input/Keyboard.java
··· 16 16 17 17 for (int i = 0; i < keys.length; i++) { 18 18 if (keys[i]) { 19 - System.out.println("Key:" + i); 19 + //System.out.println("Key:" + i); 20 20 } 21 21 } 22 22
+59
src/com/mawersoft/projrain/input/Mouse.java
··· 1 + package com.mawersoft.projrain.input; 2 + 3 + import java.awt.event.MouseEvent; 4 + import java.awt.event.MouseListener; 5 + import java.awt.event.MouseMotionListener; 6 + 7 + public class Mouse implements MouseListener, MouseMotionListener { 8 + 9 + private static int mouseX = -1; 10 + private static int mouseY = -1; 11 + private static int mouseB = -1; 12 + 13 + public static int getX() { 14 + return mouseX; 15 + } 16 + 17 + public static int getY() { 18 + return mouseY; 19 + } 20 + 21 + public static int getB() { 22 + return mouseB; 23 + } 24 + 25 + 26 + 27 + public void mouseDragged(MouseEvent e) { 28 + mouseX = e.getX(); 29 + mouseY = e.getY(); 30 + } 31 + 32 + 33 + public void mouseMoved(MouseEvent e) { 34 + mouseX = e.getX(); 35 + mouseY = e.getY(); 36 + } 37 + 38 + 39 + public void mouseClicked(MouseEvent e) { 40 + } 41 + 42 + public void mouseEntered(MouseEvent e) { 43 + } 44 + 45 + 46 + public void mouseExited(MouseEvent e) { 47 + } 48 + 49 + 50 + public void mousePressed(MouseEvent e) { 51 + mouseB = e.getButton(); 52 + } 53 + 54 + 55 + public void mouseReleased(MouseEvent e) { 56 + mouseB = -1; 57 + } 58 + 59 + }
+46
src/com/mawersoft/projrain/level/Level.java
··· 1 1 package com.mawersoft.projrain.level; 2 2 3 + import java.util.ArrayList; 4 + import java.util.List; 5 + 6 + import com.mawersoft.projrain.entity.Entity; 7 + import com.mawersoft.projrain.entity.projectile.Projectile; 3 8 import com.mawersoft.projrain.graphics.Screen; 4 9 import com.mawersoft.projrain.level.tile.Tile; 5 10 ··· 9 14 protected int[] tilesInt; 10 15 protected int[] tiles; 11 16 public static Level spawn = new SpawnLevel("/levels/spawn.png"); 17 + 18 + private List<Entity> entities = new ArrayList<Entity>(); 19 + private List<Projectile> projectiles = new ArrayList<Projectile>(); 12 20 13 21 public Level(int width, int height) { 14 22 this.width = width; ··· 30 38 } 31 39 32 40 public void update() { 41 + for (int i = 0; i < entities.size(); i++) { 42 + entities.get(i).update(); 43 + } 44 + 45 + for (int i = 0; i < projectiles.size(); i++) { 46 + projectiles.get(i).update(); 47 + } 48 + } 49 + 50 + 51 + public List<Projectile> getProjectiles() { 52 + return projectiles; 33 53 } 34 54 35 55 private void time() { 36 56 } 37 57 58 + public boolean tileCollision(double x, double y, double xa, double ya, int size) { 59 + boolean solid = false; 60 + for (int c = 0; c < 4; c++) { 61 + int xt = (((int)x + (int)xa) + c % 2 * size / 2 - 5) / 16; 62 + int yt = (((int)y + (int)ya) + c / 2 * size / 2 + 5) / 16; 63 + if (getTile(xt, yt).solid()) solid = true; 64 + } 65 + return solid; 66 + } 67 + 38 68 public void render(int xScroll, int yScroll, Screen screen) { 39 69 screen.setOffset(xScroll, yScroll); 40 70 int x0 = xScroll >> 4; ··· 47 77 getTile(x, y).render(x, y, screen); 48 78 } 49 79 } 80 + for (int i = 0; i < entities.size(); i++) { 81 + entities.get(i).render(screen); 82 + } 83 + for (int i = 0; i < projectiles.size(); i++) { 84 + projectiles.get(i).render(screen); 85 + } 50 86 } 87 + 88 + public void add(Entity e) { 89 + entities.add(e); 90 + } 91 + 92 + public void addProjectile(Projectile p) { 93 + p.init(this); 94 + projectiles.add(p); 95 + } 96 + 51 97 52 98 53 99 // Grass = 0xFF00FF00