Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

Commit

Permalink
Added Actor persistence =)
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/gjava/code@1720 0bf6c8e7-452b-0410-8c87-9aaedaf074f6
  • Loading branch information
amorri40 committed Jun 8, 2009
1 parent e00c008 commit 6e00767
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions Dolphin2/src/org/dolphin/DolphinWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ void parseObjects() throws GmFormatException {
print(actor, " ystart = Y;");
print(actor, " x = X;");
print(actor, " y = Y;");
print(actor, " setObject_index(Game."+name+");");
print(actor, " this.instance_id = instance_id;");
print(actor, " self=this;");
/*print(actor, " try{");
Expand Down
4 changes: 2 additions & 2 deletions Dolphin2/src/org/dolphin/game/api/components/Actor.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,14 @@ public Object getGravity_direction() {

public Object getHspeed() {

return new Double(hspeed);
return hspeed;
}

public Object getId() {
// if (id == null) {
// id = 0d;
// }
return new Double(id);
return self.instance_id;
}

public Object getImage_alpha() {
Expand Down
17 changes: 17 additions & 0 deletions Dolphin2/src/org/dolphin/game/api/components/Room2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,23 @@ public Actor[] setActorwithname(Class name){
return ac.toArray(a);
}

/*
* Used when moving room to get the persistent objects to move to next room
*/
public Vector<Actor> getPersistent(){
Vector<Actor> ac = new Vector<Actor>();
for (int i = 0; i < instances.size(); i++) {
if (instances.elementAt(i) !=null){
Actor a = (Game.currentRoom.instances.elementAt(i));

if (Variable.toBoolean(a.persistent)) {
ac.add(a);
}
}
}
return ac;
}

public Actor getInstance(double id){
for (int i = 0; i < instances.size(); i++) {
if (instances.elementAt(i) !=null){
Expand Down
17 changes: 17 additions & 0 deletions Dolphin2/src/org/dolphin/game/api/gtge/BasicGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.swing.JOptionPane;

import org.dolphin.game.api.Clipboard;
import org.dolphin.game.api.components.Actor;
import org.dolphin.game.api.components.Room2D;

import com.golden.gamedev.Game;
Expand Down Expand Up @@ -156,9 +157,16 @@ public static void nextRoom() throws RoomChangedException{
for (int i = 0; i < rooms.size(); i++) {
if (rooms.get(i).vectorid==(currentRoom.vectorid+1)){
org.dolphin.game.Game.thegame.bsInput.refresh();
Vector<Actor> per = currentRoom.getPersistent();
currentRoom.setinvisible();

currentRoom=rooms.get(i);

currentRoom.setvisible();

currentRoom.instances.addAll(per);
currentRoom.depth.addAll(per);
currentRoom.SortDepth();
throw new RoomChangedException();
}}
} else {
Expand All @@ -175,9 +183,13 @@ public static void previousRoom() throws RoomChangedException{
for (int i = 0; i < rooms.size(); i++) {
if (rooms.get(i).vectorid==(currentRoom.vectorid-1)){
org.dolphin.game.Game.thegame.bsInput.refresh();
Vector<Actor> per = currentRoom.getPersistent();
currentRoom.setinvisible();
currentRoom=rooms.get(i);
currentRoom.setvisible();
currentRoom.instances.addAll(per);
currentRoom.depth.addAll(per);
currentRoom.SortDepth();
throw new RoomChangedException();
}}
}else {
Expand All @@ -200,9 +212,14 @@ public static void certainRoom(int roomid) throws RoomChangedException{
for (int i = 0; i < rooms.size(); i++) {
if (rooms.get(i).id==roomid){
org.dolphin.game.Game.thegame.bsInput.refresh();
Vector<Actor> per = currentRoom.getPersistent();
currentRoom.setinvisible();

currentRoom=rooms.get(i);
currentRoom.setvisible();
currentRoom.instances.addAll(per);
currentRoom.depth.addAll(per);
currentRoom.SortDepth();
throw new RoomChangedException();
}
}
Expand Down

0 comments on commit 6e00767

Please sign in to comment.