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

Commit

Permalink
Added instance_number(obj) and the outside room event =)
Browse files Browse the repository at this point in the history
Also threaded collision event, may make games not work properly.

git-svn-id: https://svn.code.sf.net/p/gjava/code@1734 0bf6c8e7-452b-0410-8c87-9aaedaf074f6
  • Loading branch information
amorri40 committed Jun 19, 2009
1 parent d3bc567 commit e9fe870
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 121 deletions.
5 changes: 3 additions & 2 deletions Dolphin2/Progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ When doing masks check functions like place_free as they use sprite.sprite_width
The bounding box needs to be angled for sprite and mask when the sprite is at an angle
Change code so that it doesn't modify the image when scaling, rotating etc (more efficient?)
globalvar statement doesn't work (actually changes variables so that they are global threwout whole game)

Use code from gtge game.java to check if focus for the gm setting (freeze the game when the form looses focus)

||||| Functions


|||||| IDEAS
Possibly make local variables so that they don't use hash table (faster) (won't work due to arrays)
Possibly make local variables so that they don't use hash table (faster) (won't work due to arrays)
Make a collision vector so it doesn't go through actors without collision events
2 changes: 1 addition & 1 deletion Dolphin2/src/com/golden/gamedev/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void startGameLoop() {
out: while (true) {
if (this.inFocus) {
// update game
this.update(elapsedTime);
this.update(elapsedTime);
this.bsInput.update(elapsedTime); // update input

}
Expand Down
28 changes: 19 additions & 9 deletions Dolphin2/src/org/dolphin/DolphinWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ void parseObjects() throws GmFormatException {
}
} /*
* Alarm Event
*/ else if (j == 2) {
*/ else if (j == 2 && a.mainEvents[j].events.size()>0) {
callevents+="Alarm();";
print(actor, " public void performAlarm(int alarmid) throws RoomChangedException {");
for (Event ev : a.mainEvents[j].events) {
Expand Down Expand Up @@ -523,9 +523,12 @@ void parseObjects() throws GmFormatException {
}
} /*
* Collision Event
*/ else if (j == 4) {
*/ else if (j == 4 && a.mainEvents[j].events.size()>0) {
pc.event = "Collision Event";
callevents+="checkCollision();";
print(actor, "public void callCollision(){");
print(actor, "try{checkCollision();}catch(Exception e){}");
print(actor, " }");
print(actor, " public void Collision(java.lang.String name) throws RoomChangedException{");
for (Event ev : a.mainEvents[j].events) {
System.out.println("ev.id" + ev.id);
Expand All @@ -537,7 +540,7 @@ void parseObjects() throws GmFormatException {
print(actor, "}");
} /*
* Keyboard Event
*/ else if (j == 5) {
*/ else if (j == 5 && a.mainEvents[j].events.size()>0) {
pc.event = "Keyboard Event";
callevents+="Keyboard();";
print(actor, " public void Keyboard() throws RoomChangedException {");
Expand All @@ -553,7 +556,7 @@ void parseObjects() throws GmFormatException {
print(actor, "}");
} /*
* Mouse Event
*/ else if (j == 6) {
*/ else if (j == 6 && a.mainEvents[j].events.size()>0) {
pc.event = "Mouse Event";
for (Event ev : a.mainEvents[j].events) {
pc.event = "Mouse "+ev.id+" Event";
Expand All @@ -568,8 +571,14 @@ void parseObjects() throws GmFormatException {
for (Event ev : a.mainEvents[j].events) {
System.out.println("Other event id:" + ev.id);
print(actor, "//other event:" + ev.id);
if (ev.id == 7) {
pc.event = "Animation End Event";
if (ev.id == 0){
pc.event = "Outside Room Event";
callevents+="OutsideRoom();";
print(actor, " public void OutsideRoom() throws DestroyException,RoomChangedException {");
print(actor," if (x<0 || x>Game.thegame.currentRoom.width || y<0 || y>Game.thegame.currentRoom.width) {");
}
else if (ev.id == 7) {
pc.event = "Animation End Event"; //called in actor draw event
//callevents+="EndOfAnimation();";
print(actor, " public void EndOfAnimation() throws DestroyException,RoomChangedException {");
} else {
Expand All @@ -579,8 +588,9 @@ void parseObjects() throws GmFormatException {

}
print(actor, " " + parseGCL(getActionsCode(ev)));

print(actor, " }");
if (ev.id == 0){
print(actor, " }");}
}
} /*
* Draw Event
Expand Down Expand Up @@ -658,8 +668,8 @@ void parseObjects() throws GmFormatException {
*/
print(actor,"public void callEvents() throws RoomChangedException {");
print(actor,"try{");
print(actor,""+callevents+"Move();");
print(actor,"} catch (DestroyException d) {}");
print(actor,""+callevents+" Move();");//used to add Move
print(actor,"} catch (Exception d) {} //DestoryException etc");
print(actor,"}");
print(actor, "");
print(actor, "}");//end the class
Expand Down
2 changes: 1 addition & 1 deletion Dolphin2/src/org/dolphin/game/Actor0.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void EndStep() throws DestroyException {
// {Actor[] ac
// =Game.currentRoom.setActorwithname(self.getVariable("targetHandle").getActor().getClass());
//System.out.println("mouse X:"+this.getMouse_x()+" ::"+Game.thegame.bsInput.getMouseX());

if (x<0 || x>Game.thegame.currentRoom.width || y<0 || y>Game.thegame.currentRoom.width){}

}

Expand Down
169 changes: 70 additions & 99 deletions Dolphin2/src/org/dolphin/game/Game.java
Original file line number Diff line number Diff line change
@@ -1,110 +1,90 @@
package org.dolphin.game;

import java.awt.Dimension;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Vector;

import javax.swing.JOptionPane;

import org.dolphin.game.api.Clipboard;
import org.dolphin.game.api.components.Room2D;
import com.golden.gamedev.GameLoader;
import com.golden.gamedev.engine.graphics.WindowedMode;


import java.awt.image.BufferedImage;
import java.io.Externalizable;
import java.io.Serializable;
import javax.swing.UIManager;

import org.dolphin.game.api.components.Path;
import org.dolphin.game.api.components.Sound;
import org.dolphin.game.api.components.Sprite;
import org.dolphin.game.api.components.*;
import org.dolphin.game.api.types.AllOfObject;
public class Game extends org.dolphin.game.api.gtge.BasicGame {
public static org.dolphin.game.Game thegame;//used to get this game object
public static AllOfObject object0= new AllOfObject(new object0()), object1= new AllOfObject(new object1()), nullallofobject;

public static void setupGame() {
game = new GameLoader();
thegame=new Game();
game.setup(thegame, new Dimension(640, 480), false);
frame = ((WindowedMode) Game.game.getGame().bsGraphics).getFrame();
initPaths();
}

public BufferedImage loadBackground(String name){
if (!backgrounds.containsKey(name))
{
backgrounds.put(name, getImage(name+".png"));
}
return (BufferedImage)backgrounds.get(name);
}

public Sprite loadSprite(String name){
if (!sprites.containsKey(name))
{
sprites.put(name, getSprite(name));
}
return (Sprite)sprites.get(name);
}
public Sound loadSound(String name){
if (!sounds.containsKey(name))
{
sounds.put(name, getSound(name));
}
return (Sound)sounds.get(name);
}
public Sprite getSprite(String name){
if (name.equals("sprite0")) return new Sprite("sprite0",157, 158, 0, 157, 156, 0, 0, 0, true, new BufferedImage[]{getImage("sprite0[0].png")});
return null;
}
public Sound getSound(String name){
return null;
}
public static Path DOLPHIN_nullpath;
public static void initPaths(){
}
public static void initRooms(){
rooms=new Vector<Room2D>();
rooms.add(new room0(0));
currentRoom=rooms.firstElement();
currentRoom.setvisible();

/*new Thread() {
@Override
public void run() {
while(true){
try{
for (int i = 0; i < currentRoom.instances.size(); i++) {
currentRoom.instances.elementAt(i).checkCollision();
}
}catch(Exception e){}}
}
}.start();*/

public class Game extends org.dolphin.game.api.gtge.BasicGame implements Externalizable {
private static final long serialVersionUID = 1L;

public static Path DOLPHIN_nullpath;
//test fields


//proper fields
public static org.dolphin.game.Game thegame;//used to get this game object
public static AllOfObject Actor0=new AllOfObject(new Actor0()),Actor1=new AllOfObject(new Actor1());

public static void setupGame() {
game = new GameLoader();
thegame=new Game();
game.setup(thegame, new Dimension(640, 480), false);
frame = ((WindowedMode) Game.game.getGame().bsGraphics).getFrame();

}

public BufferedImage loadBackground(String name){
if (!backgrounds.containsKey(name))
{
backgrounds.put(name, getImage(name+".png"));
}
return (BufferedImage)backgrounds.get(name);
}

public Sprite loadSprite(String name){
if (!sprites.containsKey(name))
{
sprites.put(name, getSprite(name));
}
return (Sprite)sprites.get(name);
}

public Sprite getSprite(String name){

if (name.equals("wall")) return new Sprite("wall",24, 24, 0, 23, 23, 0, 0, 0,true, new BufferedImage[]{getImage("sprimg_wall_0.png"),getImage("image.png")});
else if (name.equals("image")) return new Sprite("image",24, 24, 0, 23, 23, 0, 0, 0,true, new BufferedImage[]{getImage("image.png")});

return null;
}

public Sound loadSound(String name){
if (!sounds.containsKey(name))
{
sounds.put(name, getSound(name));
}
return (Sound)sounds.get(name);
}

public Sound getSound(String name){
if (name.equals("sound0")) return new Sound("sound0.wav");


return null;
}

public static void initRooms(){
rooms=new Vector<Room2D>();
rooms.add(new Dolphin_Room0(0));
rooms.add(new Dolphin_Room1(1));
currentRoom=rooms.firstElement();
currentRoom.setvisible();
//previousRoom();
//nextRoom();

}



@Override
public void initResources() {
}
public void initResources() {
super.initResources();
initRooms();
}

public static void main(java.lang.String[] args) {
parameter_count = args.length;
parameters = args;
Expand All @@ -119,7 +99,7 @@ public static void main(java.lang.String[] args) {
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
e.printStackTrace(printWriter);
Clipboard.setText("" + result.toString() + Clipboard.getText());
Clipboard.setText(("" + result.toString() + Clipboard.getText()));
JOptionPane
.showMessageDialog(null,"Error: "
+ e
Expand All @@ -133,13 +113,4 @@ public static void main(java.lang.String[] args) {
}

}

public void writeExternal(ObjectOutput out) throws IOException {

//no data
}

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
//no data
}
}
}
11 changes: 10 additions & 1 deletion Dolphin2/src/org/dolphin/game/api/GCL.java
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,16 @@ public Object instance_exists(Object obj)

public static Object instance_number(Object obj)
{
return 0d;
int number=0;
for (int i = 0; i < Game.currentRoom.instances.size(); i++) {
if (Game.currentRoom.instances.elementAt(i) !=null){
Actor a = (Game.currentRoom.instances.elementAt(i));
if (Variable.getActor(obj).isSameAs(a)) {
number++;
}
}
}
return number;
}

public static Object instance_position(Object x, Object y, Object obj)
Expand Down
8 changes: 6 additions & 2 deletions Dolphin2/src/org/dolphin/game/api/components/Actor.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ public void Collision(java.lang.String name) throws RoomChangedException

}

public void callCollision(){
//don't call checkcollision by default
}

/**
* check collision and call the collision event
*/
Expand Down Expand Up @@ -421,7 +425,7 @@ else if (action==3){
*/
@Override
public void Draw_event(Graphics g) throws RoomChangedException {

if (x>-10 && y>-10 && x<Game.thegame.currentRoom.width && y<Game.thegame.currentRoom.width){ //check if it is in the game area
if (sprite != null) {
sprite_index += sprite_speed;
if (sprite_index >= sprite.subimages){ //gone through animation
Expand All @@ -434,7 +438,7 @@ public void Draw_event(Graphics g) throws RoomChangedException {
} else {
//System.out.println("sprite is null");
}

}
}
// <editor-fold defaultstate="collapsed" desc="Getters">

Expand Down
Loading

0 comments on commit e9fe870

Please sign in to comment.