Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBigEye authored Aug 10, 2020
1 parent ad79a86 commit 023afb6
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/minicraft/entity/SoulBall.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package minicraft.entity;

import java.util.List;

import minicraft.entity.mob.AirWizard;
import minicraft.entity.mob.Cthulhu;
import minicraft.entity.mob.Mob;
import minicraft.gfx.Rectangle;
import minicraft.gfx.Screen;

public class SoulBall extends Entity {
private int lifeTime; // how much time until the spark disappears
private double xa, ya; // the x and y acceleration
private double xx, yy; // the x and y positions
private int time; // the amount of time that has passed
private Cthulhu owner; // the AirWizard that created this spark

/**
* Creates a new spark. Owner is the AirWizard which is spawning this spark.
* @param owner The AirWizard spawning the spark.
* @param xa X velocity.
* @param ya Y velocity.
*/
public SoulBall(Cthulhu owner, double xa, double ya) {
super(0, 0);

this.owner = owner;
xx = owner.x;
yy = owner.y;
this.xa = xa;
this.ya = ya;

// Max time = 629 ticks. Min time = 600 ticks.
lifeTime = 60 * 10 + random.nextInt(30);
}

@Override
public void tick() {
time++;
if (time >= lifeTime) {
remove(); // remove this from the world
return;
}
// move the spark:
xx += xa;
yy += ya;
x = (int) xx;
y = (int) yy;
List<Entity> toHit = level.getEntitiesInRect(new Rectangle(x, y, 0, 0, Rectangle.CENTER_DIMS)); // gets the entities in the current position to hit.
for (int i = 0; i < toHit.size(); i++) {
Entity e = toHit.get(i);
if (e instanceof Mob && !(e instanceof AirWizard)) {
// if the entity is a mob, but not a Air Wizard, then hurt the mob with 1 damage.
((Mob)e).hurt(owner, 1);
}
}
}

/** Can this entity block you? Nope. */
public boolean isSolid() {
return false;
}

@Override
public void render(Screen screen) {
/* this first part is for the blinking effect */
if (time >= lifeTime - 6 * 20) {
if (time / 6 % 2 == 0) return; // if time is divisible by 12, then skip the rest of the code.
}

int randmirror = random.nextInt(4);

screen.render(x - 4, y - 4 - 2, 8 + 24 * 32, randmirror, 2); // renders the spark
}

/**
* Returns the owners id as a string.
* @return the owners id as a string.
*/
public String getData() {
return owner.eid+"";
}
}
82 changes: 82 additions & 0 deletions src/minicraft/entity/Spark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package minicraft.entity;

import java.util.List;

import minicraft.entity.mob.AirWizard;
import minicraft.entity.mob.Mob;
import minicraft.gfx.Rectangle;
import minicraft.gfx.Screen;

public class Spark extends Entity {
private int lifeTime; // how much time until the spark disappears
private double xa, ya; // the x and y acceleration
private double xx, yy; // the x and y positions
private int time; // the amount of time that has passed
private AirWizard owner; // the AirWizard that created this spark

/**
* Creates a new spark. Owner is the AirWizard which is spawning this spark.
* @param owner The AirWizard spawning the spark.
* @param xa X velocity.
* @param ya Y velocity.
*/
public Spark(AirWizard owner, double xa, double ya) {
super(0, 0);

this.owner = owner;
xx = owner.x;
yy = owner.y;
this.xa = xa;
this.ya = ya;

// Max time = 629 ticks. Min time = 600 ticks.
lifeTime = 60 * 10 + random.nextInt(30);
}

@Override
public void tick() {
time++;
if (time >= lifeTime) {
remove(); // remove this from the world
return;
}
// move the spark:
xx += xa;
yy += ya;
x = (int) xx;
y = (int) yy;
List<Entity> toHit = level.getEntitiesInRect(new Rectangle(x, y, 0, 0, Rectangle.CENTER_DIMS)); // gets the entities in the current position to hit.
for (int i = 0; i < toHit.size(); i++) {
Entity e = toHit.get(i);
if (e instanceof Mob && !(e instanceof AirWizard)) {
// if the entity is a mob, but not a Air Wizard, then hurt the mob with 1 damage.
((Mob)e).hurt(owner, 1);
}
}
}

/** Can this entity block you? Nope. */
public boolean isSolid() {
return false;
}

@Override
public void render(Screen screen) {
/* this first part is for the blinking effect */
if (time >= lifeTime - 6 * 20) {
if (time / 6 % 2 == 0) return; // if time is divisible by 12, then skip the rest of the code.
}

int randmirror = random.nextInt(4);

screen.render(x - 4, y - 4 - 2, 8 + 24 * 32, randmirror, 2); // renders the spark
}

/**
* Returns the owners id as a string.
* @return the owners id as a string.
*/
public String getData() {
return owner.eid+"";
}
}
7 changes: 7 additions & 0 deletions src/minicraft/entity/Tickable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package minicraft.entity;

public interface Tickable {

void tick();

}
48 changes: 48 additions & 0 deletions src/minicraft/entity/particle/Particle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package minicraft.entity.particle;

import minicraft.entity.ClientTickable;
import minicraft.entity.Entity;
import minicraft.gfx.Screen;
import minicraft.gfx.Sprite;

public class Particle extends Entity implements ClientTickable {
private int time; // lifetime elapsed.
private int lifetime;

protected Sprite sprite;

/**
* Creates an particle entity at the given position. The particle has a x and y radius = 1.
* @param x X map coordinate
* @param y Y map coorindate
* @param xr x radius of the particle
* @param lifetime How many game ticks the particle lives before its removed
* @param sprite The particle's sprite
*/
public Particle(int x, int y, int xr, int lifetime, Sprite sprite) {
// make a particle at the given coordinates
super(xr, 1);
this.x = x;
this.y = y;
this.lifetime = lifetime;
this.sprite = sprite;
time = 0;
}
public Particle(int x, int y, int lifetime, Sprite sprite) {
this(x, y, 1, lifetime, sprite);
}

@Override
public void tick() {
time++;
if(time > lifetime) {
remove();
}
}

@Override
public void render(Screen screen) { sprite.render(screen, x, y); }

@Override
public boolean isSolid() { return false; }
}
18 changes: 18 additions & 0 deletions src/minicraft/entity/particle/SmashParticle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package minicraft.entity.particle;

import minicraft.gfx.Sprite;

public class SmashParticle extends Particle {
static int[][] mirrors = {{2, 3}, {0, 1}};

/**
* Creates a smash particle at the given position. Has a lifetime of 10 ticks.
* Will also play a monsterhurt sound when created.
*
* @param x X map position
* @param y Y map position
*/
public SmashParticle(int x, int y) {
super(x, y, 10, new Sprite(3, 3, 2, 2, 3, true, mirrors));
}
}
70 changes: 70 additions & 0 deletions src/minicraft/entity/particle/TextParticle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package minicraft.entity.particle;

import minicraft.gfx.Color;
import minicraft.gfx.FontStyle;
import minicraft.gfx.Screen;

public class TextParticle extends Particle {
private String msg; // Message of the text particle
private double xa, ya, za; // x,y,z acceleration
private double xx, yy, zz; // x,y,z coordinates

private FontStyle style;

/**
* Creates a text particle which shows a message on the screen.
*
* @param msg Message to display
* @param x X map position
* @param y Y map position
* @param col Text color
*/
public TextParticle(String msg, int x, int y, int col) {
super(x, y, msg.length(), 60, null);

style = new FontStyle(col).setShadowType(Color.BLACK, false);
this.msg = msg;
xx = x; //assigns x pos
yy = y; //assigns y pos
zz = 2; //assigns z pos to be 2

//assigns x,y,z acceleration:
xa = random.nextGaussian() * 0.3;
ya = random.nextGaussian() * 0.2;
za = random.nextFloat() * 0.7 + 2;
}

@Override
public void tick() {
super.tick();

//move the particle according to the acceleration
xx += xa;
yy += ya;
zz += za;
if (zz < 0) {
//if z pos if less than 0, alter accelerations...
zz = 0;
za *= -0.5;
xa *= 0.6;
ya *= 0.6;
}
za -= 0.15; // za decreases by 0.15 every tick.
//truncate x and y coordinates to integers:
x = (int) xx;
y = (int) yy;
}

@Override
public void render(Screen screen) {
style.setXPos(x - msg.length() * 4).setYPos(y - (int)zz).draw(msg, screen);
}

/**
* Returns the message and color divied by the character :.
* @return string representation of the particle
*/
public String getData() {
return msg+":"+style.getColor();
}
}

0 comments on commit 023afb6

Please sign in to comment.