DroidQuest/src/com/droidquest/materials/ElevatorLock.java

89 lines
2.2 KiB
Java
Raw Normal View History

2014-02-02 18:39:08 -03:00
package com.droidquest.materials;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.droidquest.Room;
import com.droidquest.items.Item;
public class ElevatorLock extends Material {
private int doorstate = 0;
2014-02-02 18:39:08 -03:00
// 0=closed
// 1=opening
// 2=opening
// 3=open
// 4=closing
// 5=closing
private Room room;
2014-02-02 18:39:08 -03:00
public ElevatorLock() {
super(true, false);
GenerateIcons();
}
2014-02-02 18:39:08 -03:00
public void GenerateIcons() {
BufferedImage bi = new BufferedImage(28, 32, BufferedImage.TYPE_4BYTE_ABGR);
Graphics g;
try {
g = bi.getGraphics();
}
catch (NullPointerException e) {
System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
return;
}
2014-02-02 18:39:08 -03:00
g.setColor(Color.blue);
g.fillRect(0, 0, 28, 32);
g.setColor(Color.black);
g.fillRect(4, 4, 4, 2);
g.fillRect(12, 4, 4, 2);
g.fillRect(4, 8, 4, 2);
g.fillRect(20, 8, 4, 2);
g.fillRect(20, 26, 4, 2);
g.fillRect(4, 14, 12, 4);
g.fillRect(4, 22, 12, 4);
g.fillRect(20, 12, 4, 12);
icon = new ImageIcon(bi);
}
2014-02-02 18:39:08 -03:00
public void TouchedByItem(Item item) {
if (item.getClass().toString().endsWith("ElevatorKey")) {
room = item.room;
if (doorstate == 0) {
doorstate = 1;
}
else if (doorstate == 3) {
doorstate = 4;
}
}
}
public void Animate() {
switch (doorstate) {
case 0: // Do nothing
break;
case 1:
room.SetMaterial(15, 5, 0);
doorstate++;
break;
case 2:
room.SetMaterial(15, 4, 0);
doorstate++;
break;
case 3:
break;
case 4:
room.SetMaterial(15, 4, 7);
doorstate++;
break;
case 5:
room.SetMaterial(15, 5, 7);
doorstate = 0;
break;
}
}
2014-02-02 18:39:08 -03:00
}