Fixed DriveInterface and added a new exciting item!

This commit is contained in:
Sofia 2017-05-14 00:07:42 +03:00
parent 9acd9f638f
commit 43eb01e9de
3 changed files with 19 additions and 4 deletions

View File

@ -1,6 +1,7 @@

using Cyber.Items;
using Cyber.Networking;
using UnityEngine;
using UnityEngine.Networking;
namespace Cyber.Entities.SyncBases {
@ -21,6 +22,7 @@ namespace Cyber.Entities.SyncBases {
public Inventory() {
Drive = new Drive(10f);
Drive.AddItem(ItemDB.Singleton.Get(0));
Drive.AddItem(ItemDB.Singleton.Get(1));
}
/// <summary>

View File

@ -11,14 +11,14 @@ namespace Cyber.Items {
/// <summary>
/// Width of the interface.
/// </summary>
public const int Width = 8;
public const int Width = 7;
/// <summary>
/// Minimun height of the interface.
/// </summary>
public const int MinHeight = 4;
private int[,] ItemGrid = new int[4, Width];
private int[,] ItemGrid;
private Drive Drive;
@ -28,6 +28,7 @@ namespace Cyber.Items {
/// <param name="drive"></param>
public DriveInterface(Drive drive) {
Drive = drive;
ItemGrid = CreateEmptyGrid(Width, 4);
}
/// <summary>
@ -37,7 +38,7 @@ namespace Cyber.Items {
/// <param name="y">The y-coordinate</param>
/// <returns>The item or null</returns>
public Item GetItemAt(int x, int y) {
if (ItemGrid[y, x] == 0) {
if (ItemGrid[y, x] == -1) {
return null;
} else {
return Drive.GetItem(ItemGrid[y, x]);
@ -73,7 +74,7 @@ namespace Cyber.Items {
}
}
int[,] Temp = new int[RequiredHeight + 1, Width];
int[,] Temp = CreateEmptyGrid(Width, RequiredHeight + 1);
for (int y = 0; y < RequiredHeight - 1; y++) {
for (int x = 0; x < Width; x++) {
if (GetItemAt(x, y) != null) {
@ -95,9 +96,20 @@ namespace Cyber.Items {
for (int x = 0; x < Width; x++) {
if (GetItemAt(x, y) == null) {
ItemGrid[y, x] = idx;
return;
}
}
}
}
private int[,] CreateEmptyGrid(int width, int height) {
int[,] Grid = new int[height, width];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
Grid[y, x] = -1;
}
}
return Grid;
}
}
}

View File

@ -20,6 +20,7 @@ namespace Cyber.Items {
/// </summary>
public ItemDB() {
AddItem(new Item(Counter++, 0, "Very Long Item Name", 1.5f, "This item is a rare piece of the \"way too long of a name\" technology, invented by space goblins in ancient times."));
AddItem(new Item(Counter++, 1, "Outworldly spherical tube", .5f, "It's so spherical and smooth that it seems like it's not even from this world!"));
}
/// <summary>