Skip to content

Commit 7e30e01

Browse files
committed
Project Uploaded
1 parent 53aa418 commit 7e30e01

File tree

888 files changed

+51024
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

888 files changed

+51024
-0
lines changed

.metadata/.lock

Whitespace-only changes.

.metadata/.log

+1,831
Large diffs are not rendered by default.
20 Bytes
Binary file not shown.
32 Bytes
Binary file not shown.

.metadata/.mylyn/.tasks.xml.zip

235 Bytes
Binary file not shown.

.metadata/.mylyn/repositories.xml.zip

560 Bytes
Binary file not shown.

.metadata/.mylyn/tasks.xml.zip

235 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package dev.project.game.worlds;
2+
3+
import java.awt.Graphics;
4+
5+
import dev.project.game.Handler;
6+
import dev.project.game.entities.EntityManager;
7+
import dev.project.game.entities.creatures.Player;
8+
import dev.project.game.tiles.Tile;
9+
import dev.project.game.utils.Utils;
10+
11+
public class World {
12+
13+
private Handler handler;
14+
private int width, height;
15+
private int spawnX, spawnY;
16+
private int[][] tiles;
17+
18+
//Entites
19+
private EntityManager entityManager;
20+
21+
public World(Handler handler, String path){
22+
this.handler = handler;
23+
entityManager = new EntityManager(handler, new Player(handler, 100, 100));
24+
25+
loadWorld(path);
26+
27+
entityManager.getPlayer().setX(spawnX);
28+
entityManager.getPlayer().setY(y);
29+
}
30+
31+
public void update(){
32+
33+
}
34+
35+
public void render(Graphics g){
36+
37+
int xStart = (int) Math.max(0, handler.getGameCamera().getxOffset() / Tile.TILEWIDTH);
38+
int xEnd = (int) Math.min(width, (handler.getGameCamera().getxOffset() + handler.getWidth() ) / Tile.TILEWIDTH + 1);
39+
int yStart = (int) Math.max(0, handler.getGameCamera().getyOffset() / Tile.TILEHEIGHT);
40+
int yEnd = (int) Math.min(height, (handler.getGameCamera().getyOffset() + handler.getHeight() ) / Tile.TILEHEIGHT + 1);
41+
42+
for(int y = yStart; y < yEnd; y++){
43+
for(int x = xStart; x < xEnd; x++){
44+
getTile(x,y).render(g,(int) (x * Tile.TILEWIDTH - handler.getGameCamera().getxOffset()),(int) (y * Tile.TILEHEIGHT - handler.getGameCamera().getyOffset()) );
45+
}
46+
}
47+
}
48+
49+
public Tile getTile(int x, int y){
50+
51+
if(x < 0 || y < 0 || x >= width || y >= height)
52+
return Tile.grassTile;
53+
54+
Tile t = Tile.tiles[tiles[x][y]];
55+
if(t == null)
56+
return Tile.dirtTile;
57+
return t;
58+
}
59+
60+
private void loadWorld(String path){
61+
62+
String file = Utils.loadFileAsString(path);
63+
String[] tokens = file.split("\\s+");
64+
width = Utils.parseInt(tokens[0]);
65+
height = Utils.parseInt(tokens[1]);
66+
spawnX = Utils.parseInt(tokens[2]);
67+
spawnY = Utils.parseInt(tokens[3]);
68+
69+
tiles = new int[width][height];
70+
for(int y = 0 ; y < height; y++){
71+
for(int x = 0; x < width; x++){
72+
tiles[x][y] = Utils.parseInt(tokens[(x + y * width) + 4]);
73+
}
74+
}
75+
}
76+
77+
public int getWidth(){
78+
return width;
79+
}
80+
81+
public int getHeight(){
82+
return height;
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package dev.project.game.ui;
2+
3+
import java.awt.Graphics;
4+
import java.awt.event.MouseEvent;
5+
6+
public abstract class UIObject {
7+
8+
protected float x, y;
9+
protected int width, height;
10+
protected Rectangle bounds;
11+
protected boolean hovering = false;
12+
13+
public float getX() {
14+
return x;
15+
}
16+
17+
public abstract void update();
18+
19+
public abstract void render(Graphics g);
20+
21+
public void onMouseMove(MouseEvent e){
22+
23+
}
24+
25+
public void onMouseRelease(MouseEvent e){
26+
27+
}
28+
29+
30+
// Getters and Setter
31+
32+
public void setX(float x) {
33+
this.x = x;
34+
}
35+
36+
public float getY() {
37+
return y;
38+
}
39+
40+
public void setY(float y) {
41+
this.y = y;
42+
}
43+
44+
public int getWidth() {
45+
return width;
46+
}
47+
48+
public void setWidth(int width) {
49+
this.width = width;
50+
}
51+
52+
public int getHeight() {
53+
return height;
54+
}
55+
56+
public void setHeight(int height) {
57+
this.height = height;
58+
}
59+
60+
public boolean isHovering() {
61+
return hovering;
62+
}
63+
64+
public void setHovering(boolean hovering) {
65+
this.hovering = hovering;
66+
}
67+
68+
public UIObject(float x, float y, int width, int height){
69+
70+
this.x = x;
71+
this.y = y;
72+
this.width = width;
73+
this.height = height;
74+
}
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package dev.project.game.entities;
2+
3+
import java.awt.Graphics;
4+
import java.util.ArrayList;
5+
6+
import dev.project.game.Handler;
7+
import dev.project.game.entities.creatures.Player;
8+
9+
public class EntityManager {
10+
11+
private Handler handler;
12+
private Player player;
13+
private ArrayList<Entity> entities;
14+
15+
public EntityManager(Handler handler, Player player){
16+
this.handler = handler;
17+
this.player = player;
18+
entities = new ArrayList<Entity>();
19+
}
20+
21+
public void update(){
22+
23+
}
24+
25+
public void render(Graphics g){
26+
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package dev.project.game.entities.creatures;
2+
3+
import java.awt.Graphics;
4+
import java.awt.Rectangle;
5+
import java.awt.image.BufferedImage;
6+
7+
import dev.project.game.Handler;
8+
import dev.project.game.entities.Entity;
9+
import dev.project.game.gfx.Animations;
10+
import dev.project.game.gfx.Assets;
11+
import dev.project.game.inventory.Inventory;
12+
13+
public class Player extends Creature {
14+
15+
16+
//Animations
17+
private Animations animDown, animUp, animLeft, animRight;
18+
19+
// Attack Time
20+
private long lastAttackTimer, attackCoolDown = 200 , attackTimer = attackCoolDown;
21+
22+
23+
// Inventory
24+
public Inventory inventory;
25+
26+
public Player(Handler handler, float x, float y) {
27+
super(handler, x, y, Creature.DEFAULT_CREATURE_WIDTH, Creature.DEFAULT_CREATURE_HEIGHT);
28+
29+
bounds.x = 0;
30+
bounds.y = 30;
31+
bounds.width = 32;
32+
bounds.height = 32;
33+
34+
//Animations
35+
animDown = new Animations(500, Assets.player_down);
36+
animUp = new Animations(500, Assets.player_up);
37+
animLeft = new Animations(500, Assets.player_left);
38+
animRight = new Animations(500, Assets.player_right);
39+
40+
inventory = new Inventory(handler);
41+
}
42+
43+
@Override
44+
public void update() {
45+
//Animations
46+
animDown.update();
47+
animUp.update();
48+
animLeft.update();
49+
animRight.update();
50+
51+
//Movement
52+
getInput();
53+
move();
54+
handler.getGameCamera().centerOnEntity(this);
55+
56+
// Attack
57+
checkAttack();
58+
59+
//Inventpry
60+
inventory.update();
61+
}
62+
63+
private void checkAttack(){
64+
65+
attackTimer += System.currentTimeMillis() - lastAttackTimer;
66+
lastAttackTimer = System.currentTimeMillis();
67+
68+
if(attackTimer < attackCoolDown)
69+
return;
70+
71+
Rectangle cb = getCollisionBounds(0, 0);
72+
Rectangle ar = new Rectangle();
73+
int arSize = 20;
74+
ar.width = arSize;
75+
ar.height = arSize;
76+
77+
if(handler.getKeyManager().aUp){
78+
ar.x = cb.x + cb.width / 2 - arSize;
79+
ar.y = cb.y - arSize;
80+
}else if(handler.getKeyManager().aDown){
81+
ar.x = cb.x + cb.width / 2 - arSize;
82+
ar.y = cb.y + cb.height;
83+
}else if(handler.getKeyManager().aLeft){
84+
ar.x = cb.x - arSize;
85+
ar.y = cb.y + cb.height / 2 - arSize / 2;
86+
}else if(handler.getKeyManager().aRight){
87+
ar.x = cb.x + cb.width;
88+
ar.y = cb.y + cb.height / 2 - arSize / 2;
89+
}else{
90+
return;
91+
}
92+
93+
attackTimer = 0;
94+
95+
for(Entity e : handler.getWorld().getEntityManager().getEntities()){
96+
if(e.equals(this))
97+
continue;
98+
if(e.getCollisionBounds(0, 0).intersects(ar)){
99+
e.hurt(1);
100+
return;
101+
}
102+
}
103+
104+
}
105+
106+
@Override
107+
public void die(){
108+
System.out.println("YOU LOSE");
109+
}
110+
111+
private void getInput(){
112+
xMove = 0;
113+
yMove = 0;
114+
115+
if(handler.getKeyManager().up)
116+
yMove = -speed;
117+
if(handler.getKeyManager().down)
118+
yMove = speed;
119+
if(handler.getKeyManager().left)
120+
xMove = -speed;
121+
if(handler.getKeyManager().right)
122+
xMove = speed;
123+
124+
}
125+
@Override
126+
public void render(Graphics g) {
127+
g.drawImage(getCurrentAnimationFrame(), (int) (x - handler.getGameCamera().getxOffset() ), (int) (y - handler.getGameCamera().getyOffset()), width, height, null);
128+
129+
//g.setColor(Color.RED);
130+
//g.fillRect((int) (x + bounds.x - handler.getGameCamera().getxOffset() ), (int) (y + bounds.y - handler.getGameCamera().getyOffset()) , bounds.width, bounds.height);
131+
}
132+
133+
private BufferedImage getCurrentAnimationFrame(){
134+
if(xMove < 0){
135+
return animLeft.getCurrentFrame();
136+
}else if(xMove > 0){
137+
return animRight.getCurrentFrame();
138+
}else if(yMove < 0){
139+
return animUp.getCurrentFrame();
140+
}else{
141+
return animDown.getCurrentFrame();
142+
}
143+
144+
}
145+
}

0 commit comments

Comments
 (0)