-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 21dac2e
Showing
20 changed files
with
369 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4" /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>pl.venixpll</groupId> | ||
<artifactId>FlappyBird</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.6</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>23.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.vecmath</groupId> | ||
<artifactId>vecmath</artifactId> | ||
<version>1.5.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slick2d</groupId> | ||
<artifactId>slick2d-core</artifactId> | ||
<version>1.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jcraft</groupId> | ||
<artifactId>jorbis</artifactId> | ||
<version>0.0.17</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: pl.venixpll.FlappyBird | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package pl.venixpll; | ||
|
||
import org.newdawn.slick.AppGameContainer; | ||
import pl.venixpll.app.FlappyBirdAPP; | ||
|
||
public class FlappyBird { | ||
|
||
public static void main(String[] args) throws Exception{ | ||
final AppGameContainer appgc = new AppGameContainer(new FlappyBirdAPP("FlappyBird")); | ||
appgc.setDisplayMode(350,600,false); | ||
appgc.setVSync(true); | ||
appgc.setTargetFrameRate(60); | ||
appgc.start(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package pl.venixpll.app; | ||
|
||
import lombok.Data; | ||
import org.lwjgl.opengl.GL11; | ||
import org.newdawn.slick.BasicGame; | ||
import org.newdawn.slick.GameContainer; | ||
import org.newdawn.slick.Graphics; | ||
import org.newdawn.slick.SlickException; | ||
import pl.venixpll.app.render.RenderBird; | ||
import pl.venixpll.app.render.RenderObstacle; | ||
import pl.venixpll.texture.TextureLoader; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
@Data | ||
public class FlappyBirdAPP extends BasicGame { | ||
public FlappyBirdAPP(String title) { | ||
super(title); | ||
} | ||
|
||
private RenderBird bird; | ||
private TextureLoader textureLoader; | ||
private int backGroundPos = 0; | ||
|
||
private int score = 0; | ||
private boolean paused = true; | ||
private boolean gameOver = true; | ||
|
||
private GameContainer container; | ||
|
||
private final Random r = new Random(); | ||
|
||
@Override | ||
public void init(GameContainer gameContainer) throws SlickException { | ||
try { | ||
this.container = gameContainer; | ||
textureLoader = new TextureLoader(); | ||
textureLoader.init(); | ||
backgroundSegments.add(-350); | ||
bird = new RenderBird(gameContainer.getHeight() / 2); | ||
}catch(Exception exc){ | ||
exc.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void update(GameContainer gameContainer, int i) throws SlickException { | ||
if(textureLoader != null && textureLoader.isReady() && !paused){ | ||
backGroundPos--; | ||
int index = 0; | ||
for(int k : backgroundSegments){ | ||
k -= 1; | ||
backgroundSegments.set(index,k); | ||
index++; | ||
} | ||
for(RenderObstacle obstacle : obstacles){ | ||
obstacle.tick(this,gameContainer); | ||
} | ||
bird.tick(this); | ||
} | ||
} | ||
|
||
private List<Integer> backgroundSegments = new CopyOnWriteArrayList<>(); | ||
private List<RenderObstacle> obstacles = new CopyOnWriteArrayList<>(); | ||
|
||
@Override | ||
public void render(GameContainer gameContainer, Graphics graphics) throws SlickException { | ||
if(textureLoader != null && textureLoader.isReady()){ | ||
if(!paused) { | ||
|
||
if(backGroundPos % -135 == 0){ | ||
this.score++; | ||
} | ||
|
||
if(backGroundPos % -135 == 0){ | ||
obstacles.add(new RenderObstacle(gameContainer.getWidth(),0,r.nextInt(gameContainer.getHeight() - 200) + 100,this,gameContainer)); | ||
} | ||
if (backGroundPos % -350 == 0) { | ||
backgroundSegments.add(0); | ||
} | ||
|
||
if(obstacles.size() > 3){ | ||
obstacles.remove(0); | ||
} | ||
|
||
for (int i : backgroundSegments) { | ||
if (i < -1500) { | ||
backgroundSegments.remove(0); | ||
} | ||
textureLoader.getBackground().draw(i + 350, 0, 700, 600); | ||
} | ||
for(RenderObstacle obstacle : obstacles){ | ||
obstacle.render(gameContainer,graphics,this); | ||
} | ||
bird.render(gameContainer,graphics,this); | ||
|
||
|
||
|
||
}else{ | ||
if(this.gameOver){ | ||
textureLoader.getBackground().draw(0,0,700,600); | ||
graphics.drawString("CLICK TO START GAME!",(gameContainer.getWidth() / 2) - graphics.getFont().getWidth("CLICK TO START GAME!") / 2,(gameContainer.getHeight() / 2) - 50); | ||
} | ||
} | ||
|
||
|
||
final String scoreString = "Score: " + score; | ||
graphics.drawString(scoreString,10,22); | ||
if(this.paused && !this.gameOver){ | ||
graphics.drawString("PAUSED",(gameContainer.getWidth() / 2) - graphics.getFont().getWidth("PAUSED") / 2,gameContainer.getHeight() / 2); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void mouseClicked(int button, int x, int y, int clickCount) { | ||
if(this.gameOver) { | ||
this.gameOver = false; | ||
this.paused = false; | ||
this.score = 0; | ||
obstacles.clear(); | ||
obstacles.add(new RenderObstacle(container.getWidth(),0,r.nextInt(container.getHeight() - 200) + 100,this,container)); | ||
}else { | ||
if (!paused) { | ||
bird.click(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void keyPressed(int key, char c) { | ||
if(key == 1){ | ||
this.paused = !this.paused; | ||
} | ||
super.keyPressed(key, c); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package pl.venixpll.app.render; | ||
|
||
import org.newdawn.slick.Color; | ||
import org.newdawn.slick.GameContainer; | ||
import org.newdawn.slick.Graphics; | ||
import pl.venixpll.FlappyBird; | ||
import pl.venixpll.app.FlappyBirdAPP; | ||
|
||
import java.awt.*; | ||
|
||
public class RenderBird { | ||
|
||
private int posY; | ||
private double motionY = 0; | ||
private int resetPosY; | ||
|
||
public RenderBird(int posY){ | ||
this.posY = posY; | ||
resetPosY = posY; | ||
} | ||
|
||
public void render(GameContainer container, Graphics graphics, final FlappyBirdAPP app){ | ||
final int posX = (container.getWidth() / 2) - 50; | ||
app.getTextureLoader().getBird().setCenterOfRotation(45 /2,45 / 2); | ||
app.getTextureLoader().getBird().draw(posX,posY,45,45); | ||
|
||
Rectangle p = new Rectangle(posX + 10,posY + 10,25,25); | ||
|
||
graphics.setColor(Color.red); | ||
|
||
app.getObstacles().forEach(obstacle -> { | ||
Rectangle r = new Rectangle(obstacle.getPosX(),obstacle.getPosY(),60,obstacle.getPos()); | ||
Rectangle r1 = new Rectangle(obstacle.getPosX(),obstacle.getPos() + 140,60,container.getHeight() - 140); | ||
|
||
graphics.setColor(Color.orange); | ||
if(r.intersects(p)){ | ||
endgame(app); | ||
} | ||
if(r1.intersects(p)){ | ||
endgame(app); | ||
} | ||
}); | ||
graphics.setColor(Color.white); | ||
|
||
if(posY == container.getHeight() || posY > container.getHeight()){ | ||
endgame(app); | ||
} | ||
if(posY == -10 || posY < -10){ | ||
endgame(app); | ||
} | ||
} | ||
|
||
private void endgame(FlappyBirdAPP app){ | ||
posY = resetPosY; | ||
motionY = 0; | ||
app.setPaused(true); | ||
app.setGameOver(true); | ||
app.getBackgroundSegments().clear(); | ||
app.setBackGroundPos(0); | ||
app.getBackgroundSegments().add(-350); | ||
} | ||
|
||
public void click(){ | ||
motionY = 12; | ||
} | ||
|
||
public void tick(final FlappyBirdAPP app){ | ||
posY -= motionY; | ||
if(motionY < -4){ | ||
if(app.getTextureLoader().getBird().getRotation() < 50) { | ||
app.getTextureLoader().getBird().rotate(3); | ||
} | ||
}else if (motionY > 0){ | ||
if(app.getTextureLoader().getBird().getRotation() > -20){ | ||
app.getTextureLoader().getBird().rotate(-6); | ||
} | ||
} | ||
if(motionY > -7) { | ||
motionY -= 1; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package pl.venixpll.app.render; | ||
|
||
import lombok.Data; | ||
import org.newdawn.slick.Color; | ||
import org.newdawn.slick.GameContainer; | ||
import org.newdawn.slick.Graphics; | ||
import org.newdawn.slick.Image; | ||
import pl.venixpll.app.FlappyBirdAPP; | ||
|
||
@Data | ||
public class RenderObstacle { | ||
|
||
private int posX; | ||
private int posY; | ||
private int pos; | ||
|
||
private Image upperPipe; | ||
private Image bottomPipe; | ||
|
||
public RenderObstacle(int posX, int posY, int pos,FlappyBirdAPP app,final GameContainer container){ | ||
this.posX = posX; | ||
this.posY = posY; | ||
this.pos = pos; | ||
try { | ||
this.upperPipe = new Image("assets/pipe.jpg"); | ||
this.bottomPipe = new Image("assets/pipe.jpg"); | ||
}catch(Exception exc){} | ||
} | ||
|
||
public void render(GameContainer container, Graphics graphics, final FlappyBirdAPP app){ | ||
graphics.setColor(Color.red); | ||
this.upperPipe.setCenterOfRotation(60 / 2,pos / 2); | ||
this.upperPipe.setRotation(180); | ||
this.upperPipe.draw(posX,0,60,pos); | ||
this.bottomPipe.draw(posX,pos + 140,60,container.getHeight() - 140); | ||
graphics.setColor(Color.orange); | ||
graphics.setColor(Color.white); | ||
} | ||
|
||
public void tick(final FlappyBirdAPP app,GameContainer container){ | ||
posX -= 2; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package pl.venixpll.texture; | ||
|
||
import lombok.Data; | ||
import org.newdawn.slick.Image; | ||
|
||
@Data | ||
public class TextureLoader { | ||
|
||
private boolean ready; | ||
|
||
private Image background; | ||
private Image bird; | ||
private Image pipe; | ||
|
||
public void init() throws Exception{ | ||
background = new Image("assets/background.png"); | ||
bird = new Image("assets/bird.png"); | ||
pipe = new Image("assets/pipe.jpg"); | ||
ready = true; | ||
} | ||
|
||
} |