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

Bo en yang #10

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions BgObj.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.awt.Image;
import java.awt.Graphics;

public class BgObj extends GameObj {
public BgObj() {
super();
}

public BgObj(Image img, int x, int y, double speed) {
super(img,x,y,speed);
}

// Make background image like animation
@Override
public void paintSelf(Graphics gImage) {
super.paintSelf(gImage);
y += speed;
if (y >= 0) {
y = -435;
}
}
}
48 changes: 48 additions & 0 deletions BossObj.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.awt.Color;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Rectangle;

public class BossObj extends GameObj {
public static int basiclife = 10;
public static int life = 10;
int gameLevel = 0;

public BossObj(Image img,int x,int y,int width,int height,double speed, int gameLevel,Planewar frame) {
super(img,x,y,width,height,speed,frame);
this.gameLevel = gameLevel;
BossObj.life = (gameLevel + 1) * 10;
BossObj.basiclife = (gameLevel + 1) * 10;
}

@Override
public void paintSelf(Graphics gImage) {
super.paintSelf(gImage);
if (x > Planewar.width-150 || x < -50) {
speed = -speed;
}
x += speed;
for (ShellObj shellObj : GameUtil.shellObjList) {
if (this.getRec().intersects(shellObj.getRec())) {
shellObj.setX(-100);
shellObj.setY(100);
GameUtil.removeList.add(shellObj);
life--;
}

if (life <= 0) {
GameUtil.removeList.add(this);
Planewar.bossAlive = false;
if(gameLevel == 2) Planewar.currentState = Planewar.GameState.VICTORY;
}
}
gImage.setColor(Color.white);
gImage.fillRect(20,40,100,10);
gImage.setColor(Color.red);
gImage.fillRect(20,40,(life*(100))/basiclife,10);
}

public Rectangle getRec() {
return new Rectangle(x,y,width,height);
}
}
29 changes: 29 additions & 0 deletions BulletObj.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Rectangle;

public class BulletObj extends GameObj {
public BulletObj(Image img,int x,int y,int width,int height,double speed,Planewar frame) {
super(img,x,y,width,height,speed,frame);
}

@Override
public void paintSelf(Graphics gImage) {
super.paintSelf(gImage);
y += speed;
if (y > Planewar.height) {
this.x = -300; //this coordinate can't be the same as "shell" and "enemy" (or it'll collide)
this.y = 300;
GameUtil.removeList.add(this);
}

if (/*this.frame.bossObj != null &&*/ this.getRec().intersects(this.frame.planeObj.getRec())) {
Planewar.currentState = Planewar.GameState.GAMEOVER;
Planewar.explode = SoundUtil.playSoundWithVolume(GameUtil.planeExplodeSound, false, Planewar.volume);
}
}

public Rectangle getRec() {
return new Rectangle(x,y,width,height);
}
}
47 changes: 47 additions & 0 deletions EnemyObj.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Rectangle;

public class EnemyObj extends GameObj {
public EnemyObj() {
super();
}

public EnemyObj(Image img,int x,int y,int width,int height,double speed,Planewar frame) {
super(img,x,y,width,height,speed,frame);
}

@Override
public void paintSelf(Graphics gImage) {
super.paintSelf(gImage);
y += speed;

if (this.getRec().intersects(this.frame.planeObj.getRec())) {
Planewar.currentState = Planewar.GameState.GAMEOVER;
Planewar.explode = SoundUtil.playSoundWithVolume(GameUtil.planeExplodeSound, false, Planewar.volume);
}

if (y > Planewar.height) {
this.x = -200;
this.y = 200;
GameUtil.removeList.add(this);
}

for (ShellObj shellObj : GameUtil.shellObjList) {
if (this.getRec().intersects(shellObj.getRec())) {
shellObj.setX(-100);
shellObj.setY(100);
this.x = -200;
this.y = 200;
GameUtil.removeList.add(shellObj);
GameUtil.removeList.add(this);
Planewar.score++;
SoundUtil.playSoundWithVolume(GameUtil.enemyExplodeSound, false, Planewar.volume*0.9f);
}
}
}

public Rectangle getRec() {
return new Rectangle(x,y,width,height);
}
}
98 changes: 98 additions & 0 deletions GameObj.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Rectangle;

public class GameObj {
Image img;
int x;
int y;
int width;
int height;
double speed;
Planewar frame;

public Image getImage() {
return img;
}

public void setImage(Image img) {
this.img = img;
}

public int getX() {
return x;
}

public void setX(int x) {
this.x = x;
}

public int getY() {
return y;
}

public void setY(int y) {
this.y = y;
}

public int getWidth() {
return width;
}

public void setWidth(int width) {
this.width = width;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}

public double getSpeed() {
return speed;
}

public void setSpeed(double speed) {
this.speed = speed;
}

public Planewar getFrame() {
return frame;
}

public void setFrame(Planewar frame) {
this.frame = frame;
}

public GameObj() {

}

public GameObj(Image img, int x, int y, double speed) {
this.img = img;
this.x = x;
this.y = y;
this.speed = speed;
}

public GameObj(Image img,int x,int y,int width,int height,double speed,Planewar frame) {
this.img = img;
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.speed = speed;
this.frame = frame;
}

public void paintSelf (Graphics gImage) {
gImage.drawImage(img, x, y,null);
}

public Rectangle getRec() {
return new Rectangle(x,y,width,height);
}
}
Loading