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

Save system #3

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2061ace
Created Save.java
svenar-nl Mar 14, 2015
1c425bc
Created Load.java
svenar-nl Mar 14, 2015
fefd91d
Added inGame pause menu
svenar-nl Mar 14, 2015
bf3db39
Added Escape key
svenar-nl Mar 14, 2015
8470657
Updated TitleMenu
svenar-nl Mar 14, 2015
189183a
Created LoadMenu.java
svenar-nl Mar 14, 2015
6d4108f
Created SaveMenu.java
svenar-nl Mar 14, 2015
947f105
Updated Game.java
svenar-nl Mar 14, 2015
d5b2049
Update README.md
svenar-nl Mar 14, 2015
e8aaa03
Update Inventory.java
svenar-nl Mar 14, 2015
9975bd6
Created DATA.java
svenar-nl Mar 14, 2015
e9e6966
Update Item.java
svenar-nl Mar 14, 2015
05f0819
Create EscMenu.java
svenar-nl Mar 14, 2015
b34a626
Update Level.java
svenar-nl Mar 14, 2015
6d8ded8
Update Mob.java
svenar-nl Mar 14, 2015
8b64501
Update LoadMenu.java
svenar-nl Mar 14, 2015
cba0102
Update SaveMenu.java
svenar-nl Mar 14, 2015
45d6e5a
Update EscMenu.java
svenar-nl Mar 14, 2015
e665863
Update Game.java
svenar-nl Mar 14, 2015
89a7d11
Update Game.java
svenar-nl Mar 14, 2015
d4fead7
Fixed typo
May 30, 2015
afa0ac7
Fixed unknown location
May 30, 2015
cea06f8
Fixed import error
Jul 12, 2015
5b1d28a
Update LoadMenu.java
Jul 12, 2015
7ce368c
Update DATA.java
Jul 12, 2015
a376e44
Update Game.java
Jul 12, 2015
8528a6f
Update Save.java
Jul 12, 2015
36c45b7
Update Load.java
Jul 12, 2015
20c49b0
Update Game.java
Jul 12, 2015
59c4101
Update Game.java
Jul 12, 2015
ad6bea4
Update DATA.java
Jul 12, 2015
c737f91
Update Game.java
Jul 12, 2015
2ba3b55
Update DATA.java
Jul 12, 2015
eb6be7f
Update Inventory.java
Jul 12, 2015
8f64a92
Update README.md
Jul 13, 2015
b872014
Update README.md
Jul 13, 2015
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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# Minicraft
## By Notch (http://notch.tumblr.com/)
## By Notch (http://notch.tumblr.com/ - http://notch.net/)

For the Ludum Dare 22 competition!

This is the originally released official source code, unofficially hosted on GitHub. If you want to play around with it,
please fork this one! Pull requests accepted.

## mods by Sven Arends (http://twitter.com/sven_arends/)

For a better Minicraft experience.
Sometimes i work on new features for Minicraft


## Android Port
## by Rich Jones (http://gun.io)
## by Rich Jones (http://gun.io/)

I'm going to try to spend the weekend porting this game to Android. This will be done on the 'android' branch of this
git repository. Let's see how it goes (and no, I won't be screencasting it :( )
100 changes: 95 additions & 5 deletions src/com/mojang/ld22/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.File;
import java.io.IOException;
import java.util.Random;

Expand All @@ -20,6 +21,8 @@
import com.mojang.ld22.gfx.SpriteSheet;
import com.mojang.ld22.level.Level;
import com.mojang.ld22.level.tile.Tile;
import com.mojang.ld22.saveload.DATA;
import com.mojang.ld22.saveload.Save;
import com.mojang.ld22.screen.DeadMenu;
import com.mojang.ld22.screen.LevelTransitionMenu;
import com.mojang.ld22.screen.Menu;
Expand All @@ -28,11 +31,16 @@

public class Game extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
private Random random = new Random();
public static final String NAME = "Minicraft";
private int autosaveDelay = 7200; // 3600 is ~1min
private int autosaveTick = 0;
private String autosaveText = "";
public static final int HEIGHT = 120;
public static final int WIDTH = 160;
private static final int SCALE = 3;
private boolean startup = true;

private BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
private int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
Expand All @@ -42,19 +50,22 @@ public class Game extends Canvas implements Runnable {
private InputHandler input = new InputHandler(this);

private int[] colors = new int[256];
private int tickCount = 0;
public static int tickCount = 0;
public int gameTime = 0;

private Level level;
private Level[] levels = new Level[5];
private int currentLevel = 3;
public static Level[] levels = new Level[5];
public static int currentLevel = 3;
public Player player;

public Menu menu;
private int playerDeadTime;
private int pendingLevelChange;
private int wonTimer = 0;
public boolean hasWon = false;

public static String achievementText = "";
private int achievementTick = 0;

public void setMenu(Menu menu) {
this.menu = menu;
Expand Down Expand Up @@ -168,7 +179,48 @@ public void run() {
}

public void tick() {
if (startup == true){
if (DATA.OPERATING_SYSTEM.indexOf("win") >= 0) {
System.out.println("Windows detected");
DATA.location = System.getenv("APPDATA") + "\\minicraft\\saves\\";
} else if (DATA.OPERATING_SYSTEM.indexOf("mac") >= 0) {
System.out.println("Mac detected");
DATA.location = System.getProperty( "user.home" ) + "/minicraft/saves/";
} else if (DATA.OPERATING_SYSTEM.indexOf("nix") >= 0 || DATA.OPERATING_SYSTEM.indexOf("nux") >= 0 || DATA.OPERATING_SYSTEM.indexOf("aix") > 0) {
System.out.println("Unix or Linux detected");
DATA.location = System.getProperty( "user.home" ) + "/minicraft/saves/";
} else if (DATA.OPERATING_SYSTEM.indexOf("sunos") >= 0) {
System.out.println("Solaris detected");
} else {
System.out.println("OS not found fallback to Linux");
DATA.location = System.getProperty( "user.home" ) + "/minicraft/saves/";
}
File file = new File(DATA.location);
file.mkdirs();
System.out.println("Save directory: " + DATA.location);
startup = false;
}
tickCount++;
autosaveTick++;
if(autosaveDelay <= autosaveTick){
System.out.println("auto saving");
autosaveTick = 0;
autosaveText = "Saved";
@SuppressWarnings("unused")
Save save = new Save("AutoSave", player);
System.out.println("saved");
}
if(autosaveTick >= autosaveDelay / 8){
autosaveText = "";
}

if (achievementTick >= 200)
achievementTick = 0;
if (achievementText != "")
achievementTick++;
if (achievementText != "" && achievementTick >= 200)
achievementText = "";

if (!hasFocus()) {
input.releaseAll();
} else {
Expand Down Expand Up @@ -198,6 +250,35 @@ public void tick() {
Tile.tickCount++;
}
}

try{ //Achievements (getting wood and gems is in Player.java touchItem() due problems)
for (int i = 0; i < player.inventory.itemCount+1; i++) {
//System.out.println(player.inventory.items.get(i).getName());
if (player.inventory.items.get(i).getName().equalsIgnoreCase("wood")) { //Achievement Getting wood
if (DATA.hasAchievements[0] == false) {
//System.out.println(i);
DATA.hasAchievements[0] = true;
Game.achievementText = "Getting wood";
}
}
if (player.inventory.items.get(i).getName().equalsIgnoreCase("wood pick")) { //Achievement Craft a pickaxe
if (DATA.hasAchievements[1] == false) {
//System.out.println(i);
DATA.hasAchievements[1] = true;
Game.achievementText = "Craft a pickaxe";
}
}
if (player.inventory.items.get(i).getName().equalsIgnoreCase("gem")) { //Achievement Get gems
if (DATA.hasAchievements[2] == false) {
//System.out.println(i);
DATA.hasAchievements[2] = true;
Game.achievementText = "Gems!";
}
}
}
}catch(Exception e){

}
}

public void changeLevel(int dir) {
Expand Down Expand Up @@ -271,6 +352,15 @@ private void renderGui() {
}
}

Font.draw(autosaveText, screen, screen.w - 8 * autosaveText.length(), 2, Color.get(-1, 222, 222, 222));
Font.draw(autosaveText, screen, screen.w - 8 * autosaveText.length() - 1, 1, Color.get(-1, 555, 555, 555));

if (achievementText != "") {
Font.renderFrame(screen, "Achievement get!", 1, 1, 18, 4);
Font.draw(achievementText, screen, 1+achievementText.length(), 22, Color.get(-1, 222, 222, 222));
Font.draw(achievementText, screen, 1+achievementText.length() - 1, 21, Color.get(-1, 555, 555, 555));
}

for (int i = 0; i < 10; i++) {
if (i < player.health)
screen.render(i * 8, screen.h - 16, 0 + 12 * 32, Color.get(000, 200, 500, 533), 0);
Expand Down Expand Up @@ -299,7 +389,7 @@ private void renderGui() {
}

private void renderFocusNagger() {
String msg = "Click to focus!";
String msg = "Game Paused";
int xx = (WIDTH - msg.length() * 8) / 2;
int yy = (HEIGHT - 8) / 2;
int w = msg.length();
Expand Down Expand Up @@ -351,4 +441,4 @@ public void won() {
wonTimer = 60 * 3;
hasWon = true;
}
}
}
2 changes: 2 additions & 0 deletions src/com/mojang/ld22/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void tick() {
public Key right = new Key();
public Key attack = new Key();
public Key menu = new Key();
public Key escape = new Key();

public void releaseAll() {
for (int i = 0; i < keys.size(); i++) {
Expand Down Expand Up @@ -91,6 +92,7 @@ private void toggle(KeyEvent ke, boolean pressed) {

if (ke.getKeyCode() == KeyEvent.VK_X) menu.toggle(pressed);
if (ke.getKeyCode() == KeyEvent.VK_C) attack.toggle(pressed);
if (ke.getKeyCode() == KeyEvent.VK_ESCAPE) escape.toggle(pressed);
}

public void keyTyped(KeyEvent ke) {
Expand Down
29 changes: 29 additions & 0 deletions src/com/mojang/ld22/entity/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@

public class Inventory {
public List<Item> items = new ArrayList<Item>();
public static List<Item> items1 = new ArrayList<Item>();
public int itemCount = items.size();


public void add(Item item) {
add(items.size(), item);
}

public void add(int slot, Item item) {
itemCount = items.size();
if (item instanceof ResourceItem) {
ResourceItem toTake = (ResourceItem) item;
ResourceItem has = findResource(toTake.resource);
if (has == null) {
items.add(slot, toTake);
items1.add(slot, toTake);
} else {
has.count += toTake.count;
}
} else {
items.add(slot, item);
items1.add(slot, item);
}
}

Expand All @@ -37,6 +43,15 @@ private ResourceItem findResource(Resource resource) {
}
return null;
}
private static ResourceItem findResource1(Resource resource) {
for (int i = 0; i < items1.size(); i++) {
if (items1.get(i) instanceof ResourceItem) {
ResourceItem has = (ResourceItem) items1.get(i);
if (has.resource == resource) return has;
}
}
return null;
}

public boolean hasResources(Resource r, int count) {
ResourceItem ri = findResource(r);
Expand Down Expand Up @@ -66,4 +81,18 @@ public int count(Item item) {
}
return 0;
}

public static int count1(Item item) {
if (item instanceof ResourceItem) {
ResourceItem ri = findResource1(((ResourceItem)item).resource);
if (ri!=null) return ri.count;
} else {
int count = 0;
for (int i=0; i<items1.size(); i++) {
if (items1.get(i).matches(item)) count++;
}
return count;
}
return 0;
}
}
1 change: 1 addition & 0 deletions src/com/mojang/ld22/entity/Mob.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Mob extends Entity {
public int health = maxHealth;
public int swimTimer = 0;
public int tickTime = 0;
public int lvl;

public Mob() {
x = y = 8;
Expand Down
8 changes: 7 additions & 1 deletion src/com/mojang/ld22/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.mojang.ld22.item.resource.Resource;
import com.mojang.ld22.level.Level;
import com.mojang.ld22.level.tile.Tile;
import com.mojang.ld22.screen.EscMenu;
import com.mojang.ld22.screen.InventoryMenu;
import com.mojang.ld22.sound.Sound;

Expand Down Expand Up @@ -113,6 +114,11 @@ public void tick() {
game.setMenu(new InventoryMenu(this));
}
}
if (input.escape.clicked) {
if (!use()) {
game.setMenu(new EscMenu(this));
}
}
if (attackTime > 0) attackTime--;

}
Expand Down Expand Up @@ -392,4 +398,4 @@ public void gameWon() {
level.player.invulnerableTime = 60 * 5;
game.won();
}
}
}
21 changes: 20 additions & 1 deletion src/com/mojang/ld22/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mojang.ld22.gfx.Screen;
import com.mojang.ld22.level.Level;
import com.mojang.ld22.level.tile.Tile;
import com.mojang.ld22.saveload.DATA;
import com.mojang.ld22.screen.ListItem;

public class Item implements ListItem {
Expand All @@ -16,7 +17,23 @@ public int getColor() {
public int getSprite() {
return 0;
}
public Item addItem()
{
DATA.items.add(this);
return this;
}

public static Item getItem(String name)
{
Item newItem = DATA.cloth;
for(int i = 0; i < DATA.items.size(); i++){
if(((Item)DATA.items.get(i)).getName().replaceAll(" ", "").equalsIgnoreCase(name.replaceAll(" ", ""))){
newItem = (Item)DATA.items.get(i);
}
}

return newItem;
}
public void onTake(ItemEntity itemEntity) {
}

Expand Down Expand Up @@ -53,4 +70,6 @@ public String getName() {
public boolean matches(Item item) {
return item.getClass() == getClass();
}
}


}
4 changes: 2 additions & 2 deletions src/com/mojang/ld22/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Level {
public int grassColor = 141;
public int dirtColor = 322;
public int sandColor = 550;
private int depth;
public int depth;
public int monsterDensity = 8;

public List<Entity> entities = new ArrayList<Entity>();
Expand Down Expand Up @@ -306,4 +306,4 @@ public List<Entity> getEntities(int x0, int y0, int x1, int y1) {
}
return result;
}
}
}
Loading