Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pattern application #1

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cc39b05
Collision Facade pattern
musicianZem Jun 5, 2017
a918220
Merge pull request #1 from musicianZem/master
eunsdaily Jun 5, 2017
2624029
un-uploaded file added
musicianZem Jun 5, 2017
4462e55
Merge pull request #2 from musicianZem/master
eunsdaily Jun 5, 2017
1b617fa
1. State Pattern
Jun 5, 2017
f3c3154
Merge pull request #3 from zaiha/master
eunsdaily Jun 5, 2017
e2738f9
1. no pattern. just refactoring(pull up)
suheeeee Jun 5, 2017
4674fc0
State Pattern
Jun 5, 2017
8432148
1. no pattern just refactoring(extra local variable)
suheeeee Jun 5, 2017
4e8d61a
1. no pattern just refactoring(extra method)
suheeeee Jun 5, 2017
67bae27
1. State Pattern
Jun 5, 2017
cb50673
1. no pattern just refactoring(extra method, pull up)
suheeeee Jun 5, 2017
5939aff
Merge pull request #4 from zaiha/master
eunsdaily Jun 5, 2017
553b7d1
Merge pull request #5 from suheeeee/master
eunsdaily Jun 5, 2017
945a1e3
1. singleton
Jun 5, 2017
232076d
Merge pull request #6 from zaiha/master
eunsdaily Jun 5, 2017
5d2b3ee
1. strategy pattern
eunsdaily Jun 5, 2017
f2a7f88
1. Singleton Design Pattern
eunsdaily Jun 5, 2017
fa0aefd
1. refactoring
eunsdaily Jun 5, 2017
3fb579e
1. refactoring
eunsdaily Jun 5, 2017
8a3f0e4
1. refactoring
eunsdaily Jun 5, 2017
989b933
1. refactoring
eunsdaily Jun 5, 2017
33b030f
1. no pattern just refactoring(extra local variable)
suheeeee Jun 5, 2017
84128d1
BirdBot, Player has abstract class named Friend
musicianZem Jun 6, 2017
8cb13d6
Merge pull request #7 from suheeeee/master
eunsdaily Jun 6, 2017
6773620
Merge pull request #9 from musicianZem/master
eunsdaily Jun 6, 2017
99b8e7b
1. no pattern just refactoring(extra method and pull up)
suheeeee Jun 7, 2017
c567d31
1. refatoring
suheeeee Jun 7, 2017
743f7d0
Merge pull request #10 from suheeeee/master
eunsdaily Jun 7, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/birds/Boss.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ public void setSpawn(int x, int y){
hitbox = new Rectangle(xpos + offsetX, ypos + offsetY, 75, 75);
}

public void update(){
move();
}

public void checkMode(){
modeCounter += 1;
if (modeCounter > strafeTimer && !targetMode){
Expand Down Expand Up @@ -122,24 +118,32 @@ public void shoot()
bulletX, bulletY, speed, power, piercing);
bullets.add(z);
}
updateBullets();
removeBullets();
moveBullets();
}

public void updateBullets(){
private void removeBullets(){
ArrayList<EBullet> removeList = new ArrayList<EBullet>();
for (EBullet b : bullets){
if(b.x < 0) removeList.add(b);
b.move();
}
bullets.removeAll(removeList);
}

private void moveBullets(){
for (EBullet b : bullets){
b.move();
}
}

public void boundTarget(){
if(playerTarget != null){
if (ypos + offsetY > playerTarget.ypos + playerTarget.skin.yHBOffset + 10){
boolean isOverTarget = ypos + offsetY > playerTarget.ypos + playerTarget.skin.yHBOffset + 10;
boolean isUnderTarget = ypos + offsetY < playerTarget.ypos + playerTarget.skin.yHBOffset - 10;
if (isOverTarget){
ypos -= yspeed;
}
else if (ypos + offsetY < playerTarget.ypos + playerTarget.skin.yHBOffset - 10){
else if (isUnderTarget){
ypos += yspeed;
}
}
Expand Down Expand Up @@ -189,11 +193,7 @@ private void strafeDown(){
@Override
public void draw(Graphics g) {
if(engage){
g.setColor(Color.red);
int xhploc = (int) (sizex / 2 - maxHP / 2);
g.fillRect(xpos + xhploc, ypos + sizey, (int) maxHP, 5);
g.setColor(Color.green);
g.fillRect(xpos + xhploc, ypos + sizey, (int) hp, 5);
drawHPBar(g);
}

g.drawImage(SystemData.birdImages[eID], xpos, ypos, null);
Expand Down
13 changes: 12 additions & 1 deletion src/birds/EnemyEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public void setDescription(String desc){
}

public abstract void setSpawn(int x, int y);
public abstract void update();
public abstract void move();
public abstract void draw(Graphics g);

Expand All @@ -121,4 +120,16 @@ public String toString(){
return this.name;
}

public void update() {
move();
}

protected void drawHPBar(Graphics g) {
g.setColor(Color.red);
int xhploc = (int) (sizex / 2 - maxHP / 2);
g.fillRect(xpos + xhploc, ypos + sizey, (int) maxHP, 5);
g.setColor(Color.green);
g.fillRect(xpos + xhploc, ypos + sizey, (int) hp, 5);
}

}
17 changes: 5 additions & 12 deletions src/birds/EnemyUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,11 @@ public void draw(Graphics g) {
g.setColor(Color.blue);
if (SystemData.showHitbox) g.drawRect(hitbox.x, hitbox.y, hitbox.width, hitbox.height);

g.setColor(Color.red);
int xhploc = (int) (sizex / 2 - maxHP / 2);
g.fillRect(xpos + xhploc, ypos + sizey, (int) maxHP, 5);
g.setColor(Color.green);
g.fillRect(xpos + xhploc, ypos + sizey, (int) hp, 5);
drawHPBar(g);

g.drawImage(SystemData.birdImages[eID], xpos, ypos, null);
}


public void update(){
move();
}

public void move(){
if (zigFactor > 0){
zigzag();
Expand All @@ -76,10 +67,12 @@ else if (zigFactor == -1){

public void boundTarget(){
if(playerTarget != null){
if (ypos > playerTarget.ypos + 10){
boolean isOverTarget = ypos > playerTarget.ypos + 10;
boolean isUnderTarget = ypos < playerTarget.ypos - 10;
if (isOverTarget){
ypos -= yspeed;
}
else if (ypos < playerTarget.ypos - 10){
else if (isUnderTarget){
ypos += yspeed;
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/main/Birdbot.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

import javax.swing.ImageIcon;

import mainGUI.FontData;
import mainGUI.SystemData;
import birds.Boss;
import birds.EnemyEntity;
import birds.EnemyUnit;

public class Birdbot implements Serializable{
public class Birdbot extends Friend implements Serializable{

/**
*
Expand Down Expand Up @@ -74,13 +75,13 @@ public void update(){
updateMana();
}

private void updateMana(){
public void updateMana(){
if(mana < maxMana){
mana += skin.manaRegen;
}
}

private void move(){
public void move(){
if(target != null){
if(target instanceof Boss) retreat();
else{
Expand Down Expand Up @@ -158,7 +159,7 @@ public void draw(Graphics g, Image[] playerImages, Image[] bulletImages){

g.setColor(Color.white);
if (SystemData.showHitbox) g.drawRect(hitbox.x, hitbox.y, hitbox.width, hitbox.height);
g.setFont(new Font("Arial", Font.PLAIN, 12)); g.setColor(Color.BLACK);
g.setFont(FontData.getInstance().getFont("Arial", Font.PLAIN, 12)); g.setColor(Color.BLACK);
g.drawString(skin.name, xpos + skin.sizeX / 4, ypos);

// g.setColor(Color.red);
Expand All @@ -172,7 +173,7 @@ public void draw(Graphics g, Image[] playerImages, Image[] bulletImages){
}
}

private void shoot(){
public void shoot(){
cooldown -= 1;
if (cooldown < 0 && target != null && lockedOn && mana >= skin.manaCost){
Bullet z = new Bullet(skin.bulletID, xpos + skin.xHBOffset , ypos + skin.yHBOffset,
Expand All @@ -185,7 +186,7 @@ private void shoot(){
}


private void updateBullets(){
public void updateBullets(){
ArrayList<Bullet> removeList = new ArrayList<Bullet>();
for (Bullet b : bullets){
if(b.x > 1200) removeList.add(b);
Expand All @@ -195,8 +196,8 @@ private void updateBullets(){
}


public void updateHealth(int rawDamage){
int damageRecieved = rawDamage - (rawDamage * skin.defense) / 100;
public void updateHealth(double rawDamage){
double damageRecieved = rawDamage - (rawDamage * skin.defense) / 100;
if (health - damageRecieved > 0){
health -= damageRecieved;
}
Expand Down
60 changes: 60 additions & 0 deletions src/main/BulletCollision.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main;

import java.util.ArrayList;
import java.util.Random;

import birds.Boss;
import birds.EnemyEntity;

class BulletCollision implements CollisionInterface {
public void checkCollision( GameInstance game ) {
for (EnemyEntity e : game.birds){
// Check player
for (Player p : game.players){
ArrayList<Bullet> bulletRemoveList = new ArrayList<Bullet>();
for (Bullet b : p.bullets){
if(b.hitbox.intersects(e.hitbox) && p.skin.fspeed != 0){
e.loseHealth(b.damage);
if(!b.piercing) {
bulletRemoveList.add(b);
}
}
}
p.bullets.removeAll(bulletRemoveList);
if (e instanceof Boss){
ArrayList<EBullet> ebulletRemoveList = new ArrayList<EBullet>();
for (EBullet b : e.bullets){
if(b.hitbox.intersects(p.hitbox)){
p.updateHealth(b.damage);
if(!b.piercing) ebulletRemoveList.add(b);
}
}
e.bullets.removeAll(ebulletRemoveList);
}
}
// Check NPCs
for (Birdbot bb : game.bots){
ArrayList<Bullet> bulletRemoveList = new ArrayList<Bullet>();
for (Bullet b : bb.bullets){
if(b.hitbox.intersects(e.hitbox)){
e.loseHealth(b.damage);
if(!b.piercing) bulletRemoveList.add(b);
}
}
bb.bullets.removeAll(bulletRemoveList);
}
if(e.isDead()) {
if (e.dropAmount > 0 || e.dropMinAmount > 0) dropCoin(game, e);
game.score += e.scoreValue;
}
}
}
private void dropCoin(GameInstance game, EnemyEntity b){
Random RNG = new Random();
if (RNG.nextInt(100 / b.droprate) == 0){
int amount = RNG.nextInt(b.dropAmount + 1) + b.dropMinAmount;
game.drops.add(new CoinDrop(amount, b.xpos + b.sizex / 2 - 25
, b.ypos + b.sizey / 2 - 25));
}
}
}
45 changes: 45 additions & 0 deletions src/main/CollisionCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main;

public class CollisionCheck implements CollisionInterface {

private BulletCollision bulletCollision;
private MobCollision mobCollision;
private DropCoinCollision dropCoinCollision;
private PlayerDropCollision playerDropCollision;

@Override
public void checkCollision(GameInstance game) {
checkBulletCollision(game);
checkMobCollision(game);
checkDropCoinCollision(game);
checkPlayerDropCollision(game);
}

public void checkBulletCollision(GameInstance game) {
if( bulletCollision == null )
bulletCollision = new BulletCollision();

bulletCollision.checkCollision(game);
}

public void checkMobCollision(GameInstance game) {
if( mobCollision == null )
mobCollision = new MobCollision();

mobCollision.checkCollision(game);
}

public void checkDropCoinCollision(GameInstance game) {
if( dropCoinCollision == null )
dropCoinCollision = new DropCoinCollision();

dropCoinCollision.checkCollision(game);
}

public void checkPlayerDropCollision(GameInstance game) {
if( playerDropCollision == null )
playerDropCollision = new PlayerDropCollision();

playerDropCollision.checkCollision(game);
}
}
5 changes: 5 additions & 0 deletions src/main/CollisionInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main;

public interface CollisionInterface {
public void checkCollision( GameInstance game );
}
18 changes: 18 additions & 0 deletions src/main/DropCoinCollision.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main;

import java.util.ArrayList;

class DropCoinCollision implements CollisionInterface {
public void checkCollision( GameInstance game ) {
ArrayList<CoinDrop> dropRemoveList = new ArrayList<CoinDrop>();
for (CoinDrop d : game.drops){
for (int i = 0; i < game.players.size(); i++){
if(game.players.get(i).hitbox.intersects(d.hitbox)){
game.coinsCollected += d.amountDrop;
dropRemoveList.add(d);
}
}
}
game.drops.removeAll(dropRemoveList);
}
}
27 changes: 27 additions & 0 deletions src/main/Friend.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.ArrayList;

public abstract class Friend {
private int xpos;
private int ypos;
private Skin skin;
private int maxHealth;
private int health;
private int maxMana;
private int mana;
private ArrayList<Bullet> bullets;
private int cooldown = 0;
private Rectangle hitbox;

public abstract void draw(Graphics g, Image[] playerImages, Image[] bulletImages);
public abstract void move();
public abstract void shoot();
public abstract void update();
public abstract void updateHealth(double rawDamage);
public abstract void updateMana();
public abstract void updateBullets();
}
Loading