Skip to content

Commit

Permalink
First files
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrx007 committed Nov 30, 2018
0 parents commit 88ebb93
Show file tree
Hide file tree
Showing 21 changed files with 3,118 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.youngdev.shooter.Main

Binary file added src/RETRO.TTF
Binary file not shown.
Binary file added src/Righteous-Regular.ttf
Binary file not shown.
137 changes: 137 additions & 0 deletions src/com/youngdev/shooter/Arrow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.youngdev.shooter;

import com.engine.libs.game.GameObject;
import com.engine.libs.game.Mask;
import com.engine.libs.input.Input;
import com.engine.libs.math.AdvancedMath;
import com.engine.libs.math.BasicMath;
import com.engine.libs.rendering.Renderer;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Random;

public class Arrow extends GameObject {
public int dir, wiggleStep;
private double xD, yD;
public double addX, addY;
private ArrayList<UniParticle> particles;
public boolean shotByFriendly;
private static final boolean UseParticles = false;
public Random random;

public static final float SPEED = 6;

public Arrow(int x, int y, int dir) {
super(1, 13);
this.x = x;
this.y = y;
this.xD = x;
this.yD = y;
this.dir = dir;

// HERE: Fix depth
this.random = new Random();
this.depth = random.nextInt(1023)+depth*1024;

wiggleStep = random.nextInt(359);
if(UseParticles)
particles = new ArrayList<>();

mask = new Mask.Rectangle(x-8, y-8, 16, 16);
}

@Override
public void update(Input input) {

wiggleStep = Main.toSlowMotion((wiggleStep+16)%359);

xD += Main.toSlowMotion(addX);
yD += Main.toSlowMotion(addY);

addX -= Math.signum(addX)*Main.toSlowMotion(0.25);
addY -= Math.signum(addY)*Main.toSlowMotion(0.25);

xD += Main.toSlowMotion(Math.cos(Math.toRadians(dir))*SPEED);
yD += Main.toSlowMotion(Math.sin(Math.toRadians(dir))*SPEED);


x = (int)xD;
y = (int)yD;

// System.out.println("X: "+xx);
// System.out.println("Y: "+yy);


if(UseParticles) {
int addWiggleX = (int) (Math.cos(Math.toRadians(wiggleStep)) * 4);
int addWiggleY = (int) (Math.sin(Math.toRadians(wiggleStep)) * 4);
if (random.nextBoolean()) {
int dir = random.nextInt(359);
int tone = random.nextInt(20);
int sDir = random.nextInt(359);
int sDistance = random.nextInt(4);
int xx = (int) x + (int) (Math.cos(Math.toRadians(sDir)) * sDistance) + addWiggleX;
int yy = (int) y + (int) (Math.sin(Math.toRadians(sDir)) * sDistance) + addWiggleY;
Color color = new Color(tone, tone, tone);
int fadingSpeed = random.nextInt(8) + 20;
UniParticle.FadingProcess fadingProcess = new UniParticle.FadingProcess(255, fadingSpeed, true);
particles.add(new UniParticle(xx, yy, random.nextBoolean() ? 4 : 2, true, color, fadingProcess));
// leaf.add(new Particle(xx, yy, 4, dir, tone, Color.red));
}

// HERE: Update leaf and remove dead ones
particles.forEach(UniParticle::update);
particles.removeIf(particle -> particle.dead);
}
}

@Override
public void render(Renderer r) {
// r.drawLine(Main.main.player.xx, Main.main.player.yy, xx, yy, Color.black);
// r.fillRectangle(xx, yy, 16, 16, Color.red);

if(UseParticles)
particles.forEach(p -> p.render(r));
else {
double[] xPs1 = new double[]{
x + Math.cos(Math.toRadians(dir+45))*4,
x + Math.cos(Math.toRadians(dir+135))*4,
x + Math.cos(Math.toRadians(dir+225))*4,
x + Math.cos(Math.toRadians(dir+315))*4
};
double[] yPs1 = new double[]{
y + Math.sin(Math.toRadians(dir+45))*4,
y + Math.sin(Math.toRadians(dir+135))*4,
y + Math.sin(Math.toRadians(dir+225))*4,
y + Math.sin(Math.toRadians(dir+315))*4
};
double[] xPs2 = new double[]{
x + Math.cos(Math.toRadians(dir+45))*2,
x + Math.cos(Math.toRadians(dir+135))*2,
x + Math.cos(Math.toRadians(dir+225))*2,
x + Math.cos(Math.toRadians(dir+315))*2
};
double[] yPs2 = new double[]{
y + Math.sin(Math.toRadians(dir+45))*2,
y + Math.sin(Math.toRadians(dir+135))*2,
y + Math.sin(Math.toRadians(dir+225))*2,
y + Math.sin(Math.toRadians(dir+315))*2

};
r.fillPolygon(xPs1, yPs1, 4, new Color(255, 200, 40));
r.fillPolygon(xPs2, yPs2, 4, new Color(255, 255, 240));
}
}

@Override
public String shareSend() {
return null;
}

@Override
public void shareReceive(String s) {

}
}
54 changes: 54 additions & 0 deletions src/com/youngdev/shooter/Camera.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.youngdev.shooter;

import com.engine.libs.game.GameObject;
import com.engine.libs.math.AdvancedMath;
import com.engine.libs.rendering.Renderer;

import java.util.Random;

public class Camera {
public double cX, cY;
private double shakeX, shakeY, shakeAmount;
private int width, height;
public float bluishEffect;
public GameObject target;
private Random random;

public Camera(int width, int height, GameObject target) {
this.width = width;
this.height = height;
this.target = target;
this.cX = target.x-width/2;
this.cY = target.y-height/2;
bluishEffect = 1f;
this.shakeX = 0d;
this.shakeY = 0d;
this.shakeAmount = 0f;

random = new Random();
}

public void update() {
if(shakeAmount != 0) {
shakeX = Main.toSlowMotion(random.nextFloat() * shakeAmount * 2 - shakeAmount);
shakeY = Main.toSlowMotion(random.nextFloat() * shakeAmount * 2 - shakeAmount);
shakeAmount *= Main.toSlowMotion(0.9f);
} else {
shakeX = 0;
shakeY = 0;
}

cX += Main.toSlowMotion((target.x - cX - width/2d) * 0.1d);
cY += Main.toSlowMotion((target.y - cY - height/2d) * 0.1d);
}

public void shake(float amount) {
shakeAmount += amount;
// shakeAmount /= amount;
}

public void apply(Renderer r) {
r.setCamX((int)cX + (int)shakeX);
r.setCamY((int)cY + (int)shakeY);
}
}
123 changes: 123 additions & 0 deletions src/com/youngdev/shooter/Coin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.youngdev.shooter;

import com.engine.libs.game.GameObject;
import com.engine.libs.game.Mask;
import com.engine.libs.input.Input;
import com.engine.libs.rendering.Renderer;

import java.awt.*;
import java.util.Random;

public class Coin extends GameObject {

public double speed, rotation, rotationSpeed, xD, yD, angle;

public Coin(int x, int y, double angle) {
super(2, 11);

// HERE: Fix depth
Random random = new Random();
this.depth = random.nextInt(1023)+depth*1024;

this.x = x;
this.y = y;
this.xD = x;
this.yD = y;
this.angle = angle;

this.speed = random.nextDouble()+3;
this.rotationSpeed = 8;
this.rotation = random.nextInt(359);

this.mask = new Mask.Rectangle(x-8, y-8, 16, 16);
}

@Override
public void update(Input input) {
this.speed *= 0.9;
this.rotationSpeed *= 0.95;
this.rotation += rotationSpeed;

if(Fly.distance(xD, yD, Main.main.player.x, Main.main.player.y) < 24d) {
if(Fly.distance(xD, yD, Main.main.player.x, Main.main.player.y) < 4d) {
dead = true;
Main.main.player.lastCoinX = xD;
Main.main.player.lastCoinY = yD;
Main.main.player.coinOverlayAlpha = 255;
Main.main.player.money += 2;
} else {
angle = Fly.angle(xD, yD, Main.main.player.x, Main.main.player.y)-180;
speed = 4d;
}
}

double addX = Math.cos(Math.toRadians(angle))*speed;
double addY = Math.sin(Math.toRadians(angle))*speed;

this.xD += addX;
this.yD += addY;

this.x = xD;
this.y = yD;

this.mask.move(addX, addY);
}

@Override
public void render(Renderer r) {
// r.fillRectangle(x, y, 8, 8, Color.yellow);

int x1 = (int)(xD+Math.cos(Math.toRadians(rotation))*5d);
int y1 = (int)(yD+Math.sin(Math.toRadians(rotation))*5d);
int x2 = (int)(xD+Math.cos(Math.toRadians(rotation-90))*5d);
int y2 = (int)(yD+Math.sin(Math.toRadians(rotation-90))*5d);
int x3 = (int)(xD+Math.cos(Math.toRadians(rotation-180))*5d);
int y3 = (int)(yD+Math.sin(Math.toRadians(rotation-180))*5d);
int x4 = (int)(xD+Math.cos(Math.toRadians(rotation-270))*5d);
int y4 = (int)(yD+Math.sin(Math.toRadians(rotation-270))*5d);

r.fillPolygon(new int[]{x1, x2, x3, x4}, new int[]{y1, y2, y3, y4}, Color.yellow);

x1 = (int)(xD+Math.cos(Math.toRadians(rotation))*3d);
y1 = (int)(yD+Math.sin(Math.toRadians(rotation))*3d);
x2 = (int)(xD+Math.cos(Math.toRadians(rotation-90))*3d);
y2 = (int)(yD+Math.sin(Math.toRadians(rotation-90))*3d);
x3 = (int)(xD+Math.cos(Math.toRadians(rotation-180))*3d);
y3 = (int)(yD+Math.sin(Math.toRadians(rotation-180))*3d);
x4 = (int)(xD+Math.cos(Math.toRadians(rotation-270))*3d);
y4 = (int)(yD+Math.sin(Math.toRadians(rotation-270))*3d);

r.fillPolygon(new int[]{x1, x2, x3, x4}, new int[]{y1, y2, y3, y4}, Color.orange);

// x1 = (int)(xD+Math.cos(Math.toRadians(rotation))*2d);
// y1 = (int)(yD+Math.sin(Math.toRadians(rotation))*2d);
// x2 = (int)(xD+Math.cos(Math.toRadians(rotation-180))*2d);
// y2 = (int)(yD+Math.sin(Math.toRadians(rotation-180))*2d);
//
// r.fillPolygon(new int[]{x1, x2, x2, x1}, new int[]{y1+2, y2+2, y2+6, y1+6}, Color.orange);

/*int x1 = (int)(xD+Math.cos(Math.toRadians(rotation))*4d);
int y1 = (int)(yD+Math.sin(Math.toRadians(rotation))*4d);
int x2 = (int)(xD+Math.cos(Math.toRadians(rotation-180))*4d);
int y2 = (int)(yD+Math.sin(Math.toRadians(rotation-180))*4d);
r.fillPolygon(new int[]{x1, x2, x2, x1}, new int[]{y1, y2, y2+8, y1+8}, Color.yellow);
x1 = (int)(xD+Math.cos(Math.toRadians(rotation))*2d);
y1 = (int)(yD+Math.sin(Math.toRadians(rotation))*2d);
x2 = (int)(xD+Math.cos(Math.toRadians(rotation-180))*2d);
y2 = (int)(yD+Math.sin(Math.toRadians(rotation-180))*2d);
r.fillPolygon(new int[]{x1, x2, x2, x1}, new int[]{y1+2, y2+2, y2+6, y1+6}, Color.orange);*/
}

@Override
public String shareSend() {
return null;
}

@Override
public void shareReceive(String s) {

}
}
67 changes: 67 additions & 0 deletions src/com/youngdev/shooter/Cursor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.youngdev.shooter;

import com.engine.libs.input.Input;
import com.engine.libs.rendering.Renderer;

import java.awt.*;
import java.util.ArrayList;
import java.util.Random;

public class Cursor {
public ArrayList<UniParticle> particles;
private Random random;

public Cursor() {
particles = new ArrayList<>();
random = new Random();
}

public void update(Input i) {
createParticle(i);

if(i.isButtonDown(1)) {
// leaf.clear();
// for(int j = 0; j < 10; j++) {
//
// }
// leaf.forEach(p -> p.impulse(i.getRelativeMouseX(), i.getRelativeMouseY(), 0.5f));
}

particles.forEach(UniParticle::update);
particles.removeIf(particle -> particle.dead);
}

private void createParticle(Input i) {
int x = i.getRelativeMouseX();
int y = i.getRelativeMouseY();
int tone = random.nextInt(20);
int dir = random.nextInt(359);
int distance = random.nextInt(8);
int xx = x + (int)(Math.cos(Math.toRadians(dir))*distance);
int yy = y + (int)(Math.sin(Math.toRadians(dir))*distance);
int alpha = random.nextInt(32)+213;
alpha = 255;
int alphaSpeed = 16;
int size = (random.nextInt(2)+1)*2;
Color color = new Color(164+tone, 170+tone, 46+tone);
UniParticle.FadingProcess fadingProcess = new UniParticle.FadingProcess(alpha, alphaSpeed, true);
particles.add(new UniParticle(xx, yy, size, false, color, fadingProcess));


/*
int xx = i.getRelativeMouseX();
int yy = i.getRelativeMouseY();
int dir = random.nextInt(359);
float speed = random.nextInt(10)/10f+1f;
int tone = random.nextInt(20);
int sDir = random.nextInt(359);
int sDistance = random.nextInt(8);
int xx = xx + (int)(Math.cos(Math.toRadians(sDir))*sDistance);
int yy = yy + (int)(Math.sin(Math.toRadians(sDir))*sDistance);
leaf.add(new Particle(xx, yy, 4, dir, 0, tone));*/
}

public void render(Renderer r) {
particles.forEach(p -> p.render(r));
}
}
Loading

0 comments on commit 88ebb93

Please sign in to comment.