Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - diagostimo

1
Sea of Code / Growing Image depending on Y position
March 23, 2013, 08:08:07 pm
hey guys, I have a mini project I am working on at the moment in Java, basically what I am trying to accomplish is moving an image down the screen and scaling it depending on the Y position, the hard part is the screen is not square(640, 480), what I am doing is making a moving road Panorama, so what I am doing is drawing the road image twice, and scaling them both depending on the position, heres my code that im drawing them with at the moment:

                float scale = 0.4f;

roadFrame1.draw(0, real_y);

float width = (float) (640 * scale);;
float height = (float) (480 * scale);

float x = 320 - (width / 2);
float y = real_y - (height);

roadFrame1.draw(x, y, width, height);
 
then this is the update method that just ajusts real_y:

                if (real_y < 480) {
real_y += 1;
} else {
real_y = 0;
}

so its moving fine but I need it to scale, iv figured out that 0.4 is the exact scale for it to tile with the full sized image when placed above it, iv also tried messing around with the logic on how the scale is determined but I haven't even been able to get anything near the result I want, here is an image of the actual graphic so you have a better idea:
Spoiler: ShowHide



any ideas on how I would go about this?
2
hey there banisher, first ill explain a little about what the .new means, basically when you have a class and you want to use it, it must be created, to do this we assign it to a variable that we can use, so for example:

variable = classname.new

that creates the class we want to use and can be used with the variable name.
so next in this case we are using the Sprite class, which is used for drawing images to, to actually make the sprite have graphics we use its bitmap, just think of that as the paper you draw too, we can create a blank bitmap that we can add drawings to, or we can create a bitmap that already has graphics, I use xp but I think the classes are pretty similar, to make a sprites bitmap have graphics we would do this:

sprite = Sprite.new
sprite.bitmap = Bitmap.new(GRAPHICS_NAME_INCLUDING_DIRECTORY)
#so if I wanted to use an image called image in the directory graphics:
sprite.bitmap = Bitmap.new("graphics//image")

to create a blank bitmap we add drawings to we would do this:

sprite = Sprite.new
sprite.bitmap = Bitmap.new(WIDTH, HEIGHT)
#to actually draw to our blank bitmap we use other bitmap objects,
#so to draw an image to our blank bitmap
bitmap2 = Bitmap.new("image")
sprite.bitmap.blt(X, Y, bitmap2, RECT)

what happens there is pretty self explanatory, you define the x and y location the image will be drawn on the bitmap, then you tell it what image its going to draw, then you define a the rectangle area of the source image its going to draw, the rect is this:
Rect.new(X, Y, WIDTH, HEIGHT)
the rect is used to only draw part of an image, and is very useful for that as its used to animate characters ect, but if you want to draw the whole image you still have to define a rect area, so here is a couple of examples of us using the rect:

#blah blah we've already created our sprite and bitmap
#the following example will draw our second bitmap on our first bitmap at the x of 0 and the y of 0,
#it will also draw the whole bitmap defined by the rect
sprite.bitmap.blt(0, 0, bitmap2, Rect.new(0, 0, bitmap2.width, bitmap2.height))
#an example of the rects parameters
Rect.new(X1, Y1, X2, Y2)
#X1 & Y1 are the start locations and X2 & Y2 are the end locations for the area coppied,
# so for the whole bitmap we start at 0 and end at its width/height

#this would just copy the given area:
sprite.bitmap.blt(0, 0, bitmap2, Rect.new(40, 40, 80, 80))
#so the area drawn to the bitmap would start at 40pixles and end at 80 for both x&y,
# drawing a 40x40 square area of the bitmap


so that's an overview of how the drawing works, I think iv been pretty clear so I hope this helps :)
3
a tileset width has to be fixed, the tile size is 32x32 and the default width is 8 tiles which is a width of 264 pixels, although the height can be infinite, so every time you want to extend it another height of 1 tile just add 32 pixels to the height
4
Script Requests / Re: Items: Consuming in Steps
February 24, 2013, 03:53:34 pm
the way I would do it is have a separate item for each stage of its consume, and have a common event that is called when it is consumed, this would probably be better than just using a variable detecting how many times it has been eaten as imagine you have 4 consumes, you consume twice then sell that item or remove it from the inventory in some means or other, when you use a fresh item it will still be on the same consume count, so you could just do it in seperate items ie:

whole bread: when eaten removes 1 of whole bread and gives 3/4 of bread
3/4 of bread: when eaten removes 1 of 3/4 of bread and gives 1/2 of bread
ect
1/4 of bread: when eaten just removes(its fully used)

that way you will have to make more items but its more managable
5
ye they seem broken, I recommend just downloading the torrent as it is a wonderful collection of resources
6
Quote from: khkramer on February 19, 2013, 04:24:43 am
Yeah it was working for me too, but I had the same problem as you.
Can't see the server online even when I use localhost.

thats strange, iv have tried looking into it but cant figure out what could be the problem, when you change the script inside rpgmaker xp you will have to make sure you save the data, either by test running  or file and save project, the only problem with that you will have to reset the dll name in the ini as when rpgmakerxp saves data it resets the library path to its default, try that and it should work, but as for hosting it over a set ip im pretty stuck, also you could try the ip 127.0.0.1 as that is the same as localhost
7
 8-O that is amazing! the speed up is amazing, in comparison you can see how much better ruby 1.9 is from 1.8, I think I may use this when developing in xp from now on :D

edit:
@khkramer i got rmxos to work by merging both main methods:

#==============================================================================
# ** Main
#------------------------------------------------------------------------------
#  Runs the entire system.
#==============================================================================

ERROR_LOG_FILE = 'Error.log' # leave empty for no log

def mod_error(error)
  # load scripts
  scripts = load_data('Data/Scripts.rxdata')
  bt = error.backtrace.clone
  # change backtrace display to show script names
  bt.each_index {|i| bt[i] = bt[i].sub(/\ASection(\d+)/) {scripts[$1.to_i][1]} + "\n"}
  # new error message
  message = error.message + "\n" + bt.join('')
  # write to file if file defined
  if ERROR_LOG_FILE != ''
    File.open(ERROR_LOG_FILE, 'a') {|f| f.write("#{Time.now.to_s}:\n#{message}\n")}
  end
  return message
end

begin
  rgss_main {
  $DEBUG = $TEST = true # Remove this when your project is finished.
  # loading game data
  $data_actors        = load_data('Data/Actors.rxdata')
  $data_classes       = load_data('Data/Classes.rxdata')
  $data_skills        = load_data('Data/Skills.rxdata')
  $data_items         = load_data('Data/Items.rxdata')
  $data_weapons       = load_data('Data/Weapons.rxdata')
  $data_armors        = load_data('Data/Armors.rxdata')
  $data_enemies       = load_data('Data/Enemies.rxdata')
  $data_troops        = load_data('Data/Troops.rxdata')
  $data_states        = load_data('Data/States.rxdata')
  $data_animations    = load_data('Data/Animations.rxdata')
  $data_tilesets      = load_data('Data/Tilesets.rxdata')
  $data_common_events = load_data('Data/CommonEvents.rxdata')
  $data_system        = load_data('Data/System.rxdata')
  Graphics.resize_screen(640, 480) # Resizes the screen.
  # prepare for transition
  Graphics.freeze
  # activate the network
  $network = RMXOS::Network.new
  # active connection scene
  $scene = Scene_Servers.new
  # call main for active scene
  $scene.main while $scene != nil
  # disconnection
  $network.disconnect
  # fade out
  Graphics.transition(20)
  Graphics.update
  }
rescue SyntaxError
  $!.message.sub!($!.message, mod_error($!))
  raise
rescue
  $!.message.sub!($!.message, mod_error($!))
  raise
ensure
  # disconnection
  $network.disconnect
end

the only problem is I cant seem to connect when it is hosted over my router, ie at an ip adress, but if I use 'localhost' I can connect, pretty weird as I am using the same configuration I would connect with normal xp and it works fine with the normal version, maybe someone here knows what could be up with that? ill try and figure it out in the meantime
8
theres not really any need to remove it from the script, just go into the database/system and change title BGM to none, if your really wanted to remove it you would find it in scene_title somewhere in the initialize method
9
Sea of Code / Re: java Server
February 15, 2013, 05:57:24 pm
hey, thanks for the reply, ye ill do that, as it is now there is no more references to the streams in the loop that cause a crash when it shuts down, but when I come to add more yes I could definitely have an issue there.
also I have been looking into how to set up a database with MYSQL, and so far its going pretty well, the only question I have really is how to implement my database into my server, I know that connecting to it directly from the client would be stupid, as it is server side, but should I connect to it through the main Server, or the thread that handles the client, I know that I could connect to the database when the server launches, and get the clientThreads to go through the server to acquire information, but what would be the most practical way?
10
Sea of Code / java Server
February 14, 2013, 05:41:54 am
hey guys, recently I have been learning how to program a server in Java, and I actually don't need help for once  :^_^':, anyway I was wondering if I could get some feedback on the concept of my wonderful creation, I have read lots of tuts and realize there is a lot of ways to go about it, which is why I was wondering if this is efficient, from my perspective it seems to do its justice, at the moment its only exchanging a tiny amount of data, but it seams to fly through it, so here it is:

this is my server class:

package myServer;

import java.net.*;
import java.util.ArrayList;
import java.io.*;

public class Server {

public static Server server;
public ArrayList<ServerClientThread> users;

private boolean running;
private ServerSocket serverSocket;
private int port = 4444;
private Socket socket;

public static void main(String[] args) {

server = new Server();

}

//constructor begin
public Server() {

users = new ArrayList<ServerClientThread>();
serverSocket = null;
running = true;

try {
serverSocket = new ServerSocket(port);
System.out.println("the server has sucessfully launched");
    } catch (IOException e) {
        System.err.println("Could not listen on port: " + port + ".");
        System.exit(-1);
    }

run();

}
//constructor end

//run method begin
public void run() {

while(running) {

try {
socket = serverSocket.accept();
users.add(new ServerClientThread(socket, this));
users.get(users.size() - 1).start();
System.out.println("the server accepted a conection");

} catch (IOException e) {
e.printStackTrace();
}

}

}
//run method end

}


then this is my ServerClientThread class that manages each client on the server:

package myServer;

import java.io.*;
import java.net.*;

public class ServerClientThread extends Thread {

private Server server;
private Socket socket = null;
private boolean running;

private ObjectInputStream in;
private ObjectOutputStream out;

//constructor begin
public ServerClientThread(Socket socket, Server server) {

super("ServerClientThread");
this.socket = socket;
this.server = server;
try {
in = new ObjectInputStream(socket.getInputStream());
out = new ObjectOutputStream(socket.getOutputStream());
System.out.println("client thread successfully created");
} catch (IOException e) {
e.printStackTrace();
}
running = true;

}
//constructor end

//run method begin
public void run() {

int x = 0;
while (running) {

try {

byte command = (byte) in.readObject();

if (command == 0) {

out.writeObject(x);
x++;

} else if (command == -1) {

System.out.println("the close command has been proccessed, thread and client will now shutdown");
close();
System.out.println("also the client will be removed from the user list on the server for convinience");
server.users.remove(this);

}


} catch (IOException e) {
e.printStackTrace();
close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
close();
}

   }

}
//run method end

//close method begin
public void close() {

try {
running = false;
in.close();
out.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}

}
//close method end

}



and allas my Client class:

package myServer;

import java.io.*;
import java.net.*;

public class Client {

private Socket socket;
private int port = 4444;
private boolean running;

private ObjectInputStream in;
private ObjectOutputStream out;

//PrintWriter out = null;
   //BufferedReader in = null;

public static void main(String[] args) {

try {
Client client = new Client();
} catch (IOException e) {
e.printStackTrace();
}

}

//constructor begin
public Client() throws IOException {

try {
socket = new Socket("localhost", port);
out = new ObjectOutputStream(socket.getOutputStream());
in = new ObjectInputStream(socket.getInputStream());
} catch (UnknownHostException e) {
System.err.println("Don't know about host: " + port + ".");
       System.exit(1);
} catch (IOException e) {
       System.err.println("Couldn't get I/O for the connection to: " + port + ".");
       System.exit(1);
   }

running = true;

run();

}
//constructor end

//run method begin
public void run() {

byte command;
int x = -1;

while (running) {
       
try {
if (x < 10000) {

command = 0;
out.writeObject(command);
x = (int) in.readObject();
System.out.println(x);

} else {

command = -1;
out.writeObject(command);
close();

}

} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
       
   }

}
//run method end

//close method begin
public void close() {

try {
running = false;
in.close();
out.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}

}
//close method end

}



so ye its pretty simple right now, the server just sits and waits for connections coming in, when they do it creates a new thread to manage that connection, then the thread and the client commute an integer till it reaches 10,000, when it does the client sends a shut-down signal to the server thread, and they both close, pretty simple but its a start :D
11
Sea of Code / Re: script compiling?
February 03, 2013, 12:45:04 am
what so i could just do:


require 'Scripts.rxdata'


and that would load all the classes out of the strings? i have tried that but that does not work,
here is an example of what I am doing at the moment via the ruby interpreter:


require 'zlib'
begin

File.open("Scripts.rxdata", "rb") {|f|
file = Marshal.load(f)
inflated = Zlib::Inflate.new.inflate(file[0][2])
eval(inflated)

puts inflated
}

$game_temp = Game_Temp.new
   
puts "=============================================="
puts $game_temp.choice_start
gets


end


instead could I do each require/load on the inflated string instead of using eval?
12
you only need to replace game.rxproj with the same file from your current version, it wont delete any of your progress in your project, all that is stored inside the data files, also i remember a small bug that occurred when adding and removing extensions with the gui tool, if I remember correctly when you delete an entry it does not fully remove it, it just leaves a blank named extension, open up the config file thingy and check the extension part to make sure that is not the case
13
Sea of Code / Re: script compiling?
February 02, 2013, 07:04:19 pm
thanks, that's awesome but what I meant is, how would I run the scripts from the file like when the game runs, say I need to use a class for something outside rmxp, instead of making a copy of the script, how could I load all the classes from there strings, like requiring all the scripts in the file, would I use eval or is eval just to execute code?
edit:
ok i tryed using eval, and it let me use the classes fine, but is this a correct way to do it? also thanks you have helped out loads i thought it would have being way more complicated  :D
14
Sea of Code / Re: script compiling?
February 02, 2013, 05:57:37 am
ok cool, i did try marshal loading it but I just got a load of gobbledy goop, but knowing I need to use Zlib that helps, just tested that out in RPG maker xp and I see that everything is inside an array, so I am guessing the structure is like this:
[[script], [script], [script]]
where each script is is separated into lines(strings) right?
that is what I am guessing as the print screen console is pretty limited, I also noticed that the from the first 2 elements of the script, the first was an integer, and the second was the name, just wondering what the integer was for really? as its a high number.
that actually makes it really easy now as I can totally see how the editor separates and allows you to edit these, I guess my main question now is how does the engine turn these into scripts? like how would I convert the strings into a program?
15
Sea of Code / script compiling?
February 02, 2013, 04:28:15 am
hey guys, I was wondering if anyone could offer me any insight how to compile multiple scripts into one file, like how in RPG maker, all the scripts are compiled within Scripts.rxdata, I was just wondering as I am creating my own engine sort of thing and it would be really handy to be able to have one master file that I load to get to all my scripts, same for editing them, I would probably go about making some sort of script editor that opens up the file and lets me write to it, if anyone knows how I would pull this sort of thing off that would be great, im writing in java to be specific, so maybe there is something out there that already achieves this. 
16
Sea of Code / Re: collision inside a box
January 23, 2013, 05:04:27 pm
thanks for the input guys, ill definitely look into those methods of collision, I know I can do it very simply testing the width and the height to check if there is an intersection, I actually did it that way to begin with but the problem came when my character rotated, so I needed a more dynamic way of testing it, anyway  last night I found this v-clip Java port: http://www.cs.ubc.ca/~lloyd/java/vclip.html
so ill see if I can do anything with that, the only problem is I have no working examples with it, so I am not to sure on what methods I should be using, I also took a video last night of my issue with my current code, so I might as well upload it to show the issue a little better, although ill probably end up replacing the code, ignore the minecraft like character, I recreated the minecraft character as its a pretty easy way to build it :) if you watch the video you will see the collision works pretty well, except from when only one corner is entering a certain point of the cube, and it lets it freely enter:

http://www.youtube.com/watch?v=tlULfF8sRTI&feature=youtu.be
17
Sea of Code / collision inside a box
January 22, 2013, 11:29:14 pm
hey there guys, I have a problem figuring out the are of some triangles within a box, and thought id ask here first as you guys are pretty awesome when it comes to this sort of stuff!
so recently I have been looking into 3D game development from scratch using the LWJGL library for Java, and I am currently trying to create a collision detection system using bounding boxes around things, so the way I am currently going about it is I am testing whether a point/vector of my characters bounding box is entering another bounding box, and I will do this for all the points on my bounding box to ensure that there is no collision an the target location.

so I have managed to get it to work, well it sort of works, but at certain points of the box it doesn't work, and I cant find the problem, here is the code to my collision detection:



       public boolean collide(Cube collider, float tX, float tY, float tZ) {

boolean check;
//first check the collision of players collider vertices
check = testArea(this.collider.rotFBL, collider, tX, tY, tZ);
if (check) {
return true;
}
check = testArea(this.collider.rotFBR, collider, tX, tY, tZ);
if (check) {
return true;
}
check = testArea(this.collider.rotBBR, collider, tX, tY, tZ);
if (check) {
return true;
}
check = testArea(this.collider.rotBBL, collider, tX, tY, tZ);
if (check) {
return true;
}
//next check the targets collider vertices
//check = testArea(collider.rotFBL, this.collider, tX, tY, tZ);
//if (check) return true;
//check = testArea(collider.rotFBR, this.collider, tX, tY, tZ);
//if (check) return true;
//check = testArea(collider.rotBBR, this.collider, tX, tY, tZ);
//if (check) return true;
//check = testArea(collider.rotBBL, this.collider, tX, tY, tZ);
//if (check) return true;

//if all checks don't return true then there is no collision
return false;

}


tX ect. are the target coordinates, and what that is doing is sending the points to be individually checked to see whether they are inside the target box, also note the rotFBl etc are the rotated points named acordingly, for example rotFBL is rotatedFrontBottomLeft, next the method that checks if the point is inside the area:



private boolean testArea(Vector3f vector, Cube collider, float tX, float tY, float tZ) {

float lArea = Math.abs(collider.rotFBR.x * (collider.rotBBR.z - (vector.z + tZ)) +
collider.rotBBR.x * ((vector.z + tZ) - collider.rotFBR.z) +
(vector.x + tX) * (collider.rotFBR.z - collider.rotBBR.z)) / 2;

float rArea = Math.abs(collider.rotFBL.x * (collider.rotBBL.z - (vector.z + tZ)) +
collider.rotBBL.x * ((vector.z + tZ) - collider.rotFBL.z) +
(vector.x + tX) * (collider.rotFBL.z - collider.rotBBL.z)) / 2;

float tArea = Math.abs(collider.rotBBL.x * (collider.rotBBR.z - (vector.z + tZ)) +
collider.rotBBR.x * ((vector.z + tZ) - collider.rotBBL.z) +
(vector.x + tX) * (collider.rotBBL.z - collider.rotBBR.z)) / 2;

float bArea = Math.abs(collider.rotFBL.x * (collider.rotFBR.z - (vector.z + tZ)) +
collider.rotFBR.x * ((vector.z + tZ) - collider.rotFBL.z) +
(vector.x + tX) * (collider.rotFBL.z - collider.rotFBR.z)) / 2;

float fullArea = lArea + bArea + rArea + tArea;
float fullBoxArea = collider.xScale * collider.zScale;
//System.out.println("full area = " + fullArea);
//System.out.println("box area = " + fullBoxArea);

if (fullArea > fullBoxArea) {
return false;
}

return true;

}


now what im doing here is dividing the square into 4 triangle, where the point of the triangle is the target position, then what i do is calculate the area of my square, and the area of all the triangles, if the area of the calculated triangles is greater than the square then the position is ouside the box, if it is equal then it is is inside.

to be honest im not sure what could be wrong, as i believe i have calculated the areas properly, i seem to slightly glitch inside it if i spend a while rubbing up against it, also i tested it walking ontop of the box and there seemed to be a fall through point just around the centre next to each face, so im guessing that when the target coordinate was at that point it lets me glitch through :( any insight would be really helpful with this as its driving me crazy!

i can also provide the source code if anyone wants to look deeper into it, im using eclipse as my workspace :)
18
the second guy needs to be an auto run or parrallel proccess, the difference between the two is auto run stops you from inputing actions, whereas parrallel proccess runs along with your input, also to save on using switches, you could call a move command to move the character from within a separate event, so say:

1. show text
2. move event(1) right x times
3. whatever else you wanna do
4. control self switch so i dont repeat

that will save on switches, but say in a case you want to move more than 1 player then a switch would be better suited
19
you can test what a scene is by the using the following:
$scene.is_a?(CLASS_NAME)
so in your case when setting the variable it should only set when the scene is scene map:
$scene.is_a?(Scene_Map)
honestly i dont think that would cause a problem as scene_battle has its own event interpreter aside from scene map and only updates that, also im guessing your using the game variables to get the random functionality, ruby has its own built in function that you can use:
random_number = rand(6)
what that example would do is generate a random number between 0 and 6, if you wanted to say generate a number between 6 and 12 you would:
random = rand(6) + 6
or:
random = 6 + rand(6)
you plus 6 to the getenerated value to set the start point at that, and say it generated 3, then 6 + 3 = 9, whala it beteen 6 and 12

really you should add that random function to the start of the method that gets the coordinate, then add a loop to check if it is the same as any of the other enemies coordinates, if it is re role the dice so they dont stack until there all unique, that way you could just make one big array containing values you want the dice to roll on instead of making an array of values for each enemies :)
20
one problem is when your checking the value:

if $game_variables[20] = 1
#should be:
if $game_variables == 1

the = sign sets the value and == checks it
 
next instead of using if brances you could use a case, example:
[code]
case $game_variables[20]
when 1
  #code
when 2
  #code
end
#etc
[/code]