Skip to content

Commit 857e4ae

Browse files
committed
v1.8 Alpha - Projectiles
2 parents 4e2a1d8 + 54811e6 commit 857e4ae

File tree

18 files changed

+617
-28
lines changed

18 files changed

+617
-28
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
JavaGame Alpha v1.7.1 - 1 Year Anniversary
2-
=====================
3-
4-
[![Ohloh Stats](https://www.ohloh.net/p/JavaGame/widgets/project_thin_badge.gif)](https://www.ohloh.net/p/JavaGame)
1+
JavaGame Alpha v1.8
2+
===================
53

64
#####What is JavaGame?
75
JavaGame is a game project that have been working on since May 2013. I have added many features to the game over the last year and I plan on adding even more features. This game is purely for my own sake to practice my skills in Java.
@@ -15,6 +13,12 @@ Well i'm still not sure what exactly i'm going to do with it, and I haven't thou
1513
* For multiplayer enabled get
1614
* [v1.5.4](https://github.com/redomar/JavaGame/releases/tag/v1.5.4)
1715

16+
#####Your version naming is all wrong
17+
Yes, I recently noticed that there is a standard called Semantic Versioning that I should follow. Currently my project isn't organised as well as I hoped so starting from the Beta I will follow Semantic Versioning schema.
18+
19+
#####Your project is lacking comments
20+
I don't know why I have not commented my code but now I'm at a stage where I cannot go back to comment the entire project, I should of commented my code from the outset. This is going to be a reminder for me in the future.
21+
1822
#####How to download this repository for eclipse tutorial
1923
Watch this video [here](http://youtu.be/_3nCgac3KKM) or checkout the [GitHub Pages](http://redomar.github.io/JavaGame/)
2024
####How to use this repository
@@ -32,4 +36,5 @@ Watch this video [here](http://youtu.be/_3nCgac3KKM) or checkout the [GitHub Pag
3236
* Push to the branch (```git push origin my_branch```)
3337
* Open a [Pull Request](https://github.com/redomar/JavaGame/pull/new/master)
3438

35-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/redomar/javagame/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
39+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/redomar/javagame/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
40+
[![Ohloh Stats](https://www.ohloh.net/p/JavaGame/widgets/project_thin_badge.gif)](https://www.ohloh.net/p/JavaGame)

jar/javagame.jar

15.1 KB
Binary file not shown.

res/sprite_sheet.png

13.4 KB
Loading

src/com/redomar/game/Game.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.redomar.game.entities.Dummy;
1818
import com.redomar.game.entities.Player;
1919
import com.redomar.game.entities.PlayerMP;
20+
import com.redomar.game.entities.Vendor;
2021
import com.redomar.game.gfx.Screen;
2122
import com.redomar.game.gfx.SpriteSheet;
2223
import com.redomar.game.level.LevelHandler;
@@ -34,7 +35,7 @@ public class Game extends Canvas implements Runnable {
3435

3536
// Setting the size and name of the frame/canvas
3637
private static final long serialVersionUID = 1L;
37-
private static final String game_Version = "v1.7.1 Alpha";
38+
private static final String game_Version = "v1.8 Alpha";
3839
private static final int WIDTH = 160;
3940
private static final int HEIGHT = (WIDTH / 3 * 2);
4041
private static final int SCALE = 3;
@@ -71,10 +72,12 @@ public class Game extends Canvas implements Runnable {
7172
BufferedImage.TYPE_INT_RGB);
7273
private Screen screen;
7374
private static InputHandler input;
75+
private static MouseHandler mouse;
7476
private WindowHandler window;
7577
private LevelHandler level;
7678
private Player player;
7779
private Dummy dummy;
80+
private Vendor vendor;
7881
private Music music = new Music();
7982
private Font font = new Font();
8083
private Thread musicThread = new Thread(music, "MUSIC");
@@ -88,7 +91,7 @@ public class Game extends Canvas implements Runnable {
8891

8992
/**
9093
* @author Redomar
91-
* @version Alpha 1.7.1
94+
* @version Alpha 1.8
9295
*/
9396
public Game() {
9497
setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
@@ -124,6 +127,7 @@ public void init() {
124127

125128
screen = new Screen(WIDTH, HEIGHT, new SpriteSheet("/sprite_sheet.png"));
126129
input = new InputHandler(this);
130+
setMouse(new MouseHandler(this));
127131
setWindow(new WindowHandler(this));
128132
setMap("/levels/custom_level.png");
129133
setMap(1);
@@ -136,6 +140,9 @@ public void init() {
136140

137141
// socketClient.sendData("ping".getBytes());
138142
loginPacket.writeData(getSocketClient());
143+
144+
game.setVendor(new Vendor(getLevel(), "Vendor", 215, 215, 304, 543));
145+
getLevel().addEntity(getVendor());
139146
}
140147

141148
public void setMap(String Map_str) {
@@ -159,7 +166,7 @@ public void setMap(String Map_str) {
159166

160167
public static void npcSpawn() {
161168
if (isNpc() == true) {
162-
game.setDummy(new Dummy(Game.getLevel(), "h", 215, 215, 500, 543));
169+
game.setDummy(new Dummy(Game.getLevel(), "Dummy", 100, 150, 500, 543));
163170
game.level.addEntity(Game.getDummy());
164171
}
165172
}
@@ -260,6 +267,7 @@ public void render() {
260267
*/
261268

262269
getLevel().renderEntities(screen);
270+
getLevel().renderProjectileEntities(screen);
263271

264272
for (int y = 0; y < screen.getHeight(); y++) {
265273
for (int x = 0; x < screen.getWidth(); x++) {
@@ -292,11 +300,16 @@ public void render() {
292300
}
293301

294302
if (changeLevel == true) {
303+
print.print("Teleported into new world", PrintTypes.GAME);
295304
if (getMap() == 1) {
296305
setMap("/levels/water_level.png");
306+
getLevel().removeEntity(getDummy()); setNpc(false);
307+
getLevel().removeEntity(getVendor());
297308
setMap(2);
298309
} else if (getMap() == 2) {
299310
setMap("/levels/custom_level.png");
311+
getLevel().removeEntity(getDummy()); setNpc(false);
312+
getLevel().addEntity(getVendor());
300313
setMap(1);
301314
}
302315
changeLevel = false;
@@ -305,6 +318,7 @@ public void render() {
305318
Graphics g = bs.getDrawGraphics();
306319
g.drawRect(0, 0, getWidth(), getHeight());
307320
g.drawImage(image, 0, 0, getWidth(), getHeight() - 30, null);
321+
status(g, isDevMode(), isClosing());
308322
// Font.render("Hi", screen, 0, 0, Colours.get(-1, -1, -1, 555), 1);
309323
g.drawImage(image2, 0, getHeight() - 30, getWidth(), getHeight(), null);
310324
g.setColor(Color.WHITE);
@@ -317,7 +331,6 @@ public void render() {
317331
g.drawString("Press Q to quit", (getWidth()/2)-("Press Q to quit".length()*3), getHeight() -17);
318332
g.setColor(Color.YELLOW);
319333
g.drawString(time.getTime(), (getWidth() - 58), (getHeight() - 3));
320-
status(g, isDevMode(), isClosing());
321334
g.setColor(Color.WHITE);
322335
if (noAudioDevice == true) {
323336
g.setColor(Color.RED);
@@ -354,14 +367,18 @@ public void render() {
354367

355368
private void status(Graphics g, boolean TerminalMode, boolean TerminalQuit) {
356369
if (TerminalMode == true){
357-
g.setColor(Color.GREEN);
370+
g.setColor(Color.CYAN);
358371
g.drawString("JavaGame Stats", 0, 10);
359372
g.drawString("FPS/TPS: " + fps + "/" + tps, 0, 25);
360373
if ((player.getNumSteps() & 15) == 15) {
361374
steps += 1;
362375
}
363376
g.drawString("Foot Steps: " + steps, 0, 40);
364377
g.drawString("NPC: " + WordUtils.capitalize(String.valueOf(isNpc())) , 0, 55);
378+
g.drawString("Mouse: " + getMouse().getX() + "x |" + getMouse().getY() + "y", 0, 70);
379+
if(getMouse().getButton() != -1) g.drawString("Button: " + getMouse().getButton(), 0, 85);
380+
g.setColor(Color.CYAN);
381+
g.fillRect(getMouse().getX()-12, getMouse().getY()-12, 24, 24);
365382
}
366383
if (TerminalQuit == true){
367384
g.setColor(Color.BLACK);
@@ -488,6 +505,14 @@ public void setDummy(Dummy dummy) {
488505
this.dummy = dummy;
489506
}
490507

508+
public Vendor getVendor() {
509+
return vendor;
510+
}
511+
512+
public void setVendor(Vendor vendor) {
513+
this.vendor = vendor;
514+
}
515+
491516
public static String getJdata_IP() {
492517
return Jdata_IP;
493518
}
@@ -556,6 +581,14 @@ public void setInput(InputHandler input) {
556581
Game.input = input;
557582
}
558583

584+
public static MouseHandler getMouse() {
585+
return mouse;
586+
}
587+
588+
public static void setMouse(MouseHandler mouse) {
589+
Game.mouse = mouse;
590+
}
591+
559592
public static boolean isDevMode() {
560593
return devMode;
561594
}

src/com/redomar/game/InputHandler.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.awt.event.KeyListener;
55

66
import com.redomar.game.lib.SleepThread;
7+
import com.redomar.game.script.PopUp;
78
import com.redomar.game.script.PrintTypes;
89
import com.redomar.game.script.Printing;
910

@@ -31,6 +32,11 @@ public void toggle(boolean isPressed) {
3132
numTimesPressed++;
3233
}
3334
}
35+
36+
public void off(){
37+
pressed = false;
38+
numTimesPressed = 0;
39+
}
3440
}
3541

3642
private Key up = new Key();
@@ -40,7 +46,8 @@ public void toggle(boolean isPressed) {
4046
private Printing print = new Printing();
4147
private boolean PlayMusic = false;
4248
private int map;
43-
private boolean untoggle = false;
49+
private boolean ignoreInput = false;
50+
private PopUp popup = new PopUp();
4451

4552
public void keyPressed(KeyEvent e) {
4653
toggleKey(e.getKeyCode(), true);
@@ -55,7 +62,7 @@ public void keyTyped(KeyEvent e) {
5562
}
5663

5764
public void toggleKey(int keyCode, boolean isPressed) {
58-
if(untoggle == false){
65+
if(isIgnoreInput() == false){
5966
if (keyCode == KeyEvent.VK_W || keyCode == KeyEvent.VK_UP) {
6067
getUp().toggle(isPressed);
6168
}
@@ -68,7 +75,8 @@ public void toggleKey(int keyCode, boolean isPressed) {
6875
if (keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_RIGHT) {
6976
getRight().toggle(isPressed);
7077
}
71-
}else{
78+
}
79+
if(isIgnoreInput() == true){
7280
getUp().toggle(false);
7381
getDown().toggle(false);
7482
getLeft().toggle(false);
@@ -87,11 +95,18 @@ public void toggleKey(int keyCode, boolean isPressed) {
8795
// }
8896
if (Game.getMap() == 2) {
8997
Game.setChangeLevel(true);
90-
Game.getLevel().removeEntity(Game.getDummy());
9198
Game.setNpc(false);
9299
}
93100
}
94101
if (keyCode == KeyEvent.VK_N) {
102+
if (Game.getPlayer().isMoving()){
103+
setIgnoreInput(true);
104+
int n = popup.Warn("Stop moving before spawing dummy AI");
105+
if(n == 0){
106+
setIgnoreInput(false);
107+
}
108+
return;
109+
}
95110
if (Game.isNpc() == false) {
96111
Game.setNpc(true);
97112
Game.npcSpawn();
@@ -127,7 +142,7 @@ public void toggleKey(int keyCode, boolean isPressed) {
127142
}
128143

129144
public void untoggle(boolean toggle){
130-
this.untoggle = toggle;
145+
this.ignoreInput = toggle;
131146
}
132147

133148

@@ -179,12 +194,12 @@ public void setRight(Key right) {
179194
this.right = right;
180195
}
181196

182-
public boolean isUntoggle() {
183-
return untoggle;
197+
public boolean isIgnoreInput() {
198+
return ignoreInput;
184199
}
185200

186-
public void setUntoggle(boolean untoggle) {
187-
this.untoggle = untoggle;
201+
public void setIgnoreInput(boolean ignoreInput) {
202+
this.ignoreInput = ignoreInput;
188203
}
189204

190205
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.redomar.game;
2+
3+
import java.awt.event.MouseEvent;
4+
import java.awt.event.MouseListener;
5+
import java.awt.event.MouseMotionListener;
6+
7+
public class MouseHandler implements MouseListener, MouseMotionListener{
8+
9+
private static int mouseX = -1;
10+
private static int mouseY = -1;
11+
private static int mouseB = -1;
12+
13+
public MouseHandler(Game game){
14+
game.addMouseListener(this);
15+
game.addMouseMotionListener(this);
16+
}
17+
18+
public int getX() {
19+
return mouseX;
20+
}
21+
22+
public int getY() {
23+
return mouseY;
24+
}
25+
26+
public int getButton() {
27+
return mouseB;
28+
}
29+
30+
public void mouseDragged(MouseEvent e) {
31+
mouseX = e.getX();
32+
mouseY = e.getY();
33+
}
34+
35+
public void mouseMoved(MouseEvent e) {
36+
mouseX = e.getX();
37+
mouseY = e.getY();
38+
}
39+
40+
public void mouseClicked(MouseEvent e) {
41+
42+
}
43+
44+
public void mousePressed(MouseEvent e) {
45+
mouseB = e.getButton();
46+
}
47+
48+
public void mouseReleased(MouseEvent e) {
49+
mouseB = -1;
50+
}
51+
52+
public void mouseEntered(MouseEvent e) {
53+
54+
}
55+
56+
public void mouseExited(MouseEvent e) {
57+
58+
}
59+
60+
}

src/com/redomar/game/entities/Dummy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Dummy extends Mob {
2626

2727
public Dummy(LevelHandler level, String name, int x, int y, int shirtCol,
2828
int faceCol) {
29-
super(level, "h", x, y, speed, collisionBoders);
29+
super(level, name, x, y, speed, collisionBoders);
3030
this.faceCol = faceCol;
3131
this.shirtCol = shirtCol;
3232
this.colour = Colours.get(-1, 111, shirtCol, faceCol);

src/com/redomar/game/entities/Entity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public abstract class Entity {
77

88
protected double x, y;
9+
protected String name;
910
protected LevelHandler level;
1011

1112
public Entity(LevelHandler level) {
@@ -35,4 +36,12 @@ public double getY() {
3536
public void setY(int y) {
3637
this.y = y;
3738
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
3847
}

0 commit comments

Comments
 (0)