anyone wanna make an UGH! remake?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: anyone wanna make an UGH! remake?

Post by avansc »

PixelP wrote:
avansc wrote:
PixelP wrote:
avansc wrote:so pixelp, do you wanna make a level loader and saver for our game?
Hell yeah!

okay buddy. im just gonna go out to supper. i'll be back in 45 min. then we will get cracking.
Sounds good... have a nice meal.

im back. let me know when you wanna start.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
PixelP
Chaos Rift Regular
Chaos Rift Regular
Posts: 153
Joined: Tue Oct 07, 2008 12:23 pm
Programming Language of Choice: c/c++
Location: sweden
Contact:

Re: anyone wanna make an UGH! remake?

Post by PixelP »

okey., give me 5 min.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: anyone wanna make an UGH! remake?

Post by avansc »

PixelP wrote:okey., give me 5 min.
sure thing. hey if you have AIM that be great. i feel i can help you more that way.

my screen name is avans2die

ps: if anyone wants to ask me something or needs some help you can contact me via AIM.
please just identify yourself when you contact me.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
PixelP
Chaos Rift Regular
Chaos Rift Regular
Posts: 153
Joined: Tue Oct 07, 2008 12:23 pm
Programming Language of Choice: c/c++
Location: sweden
Contact:

Re: anyone wanna make an UGH! remake?

Post by PixelP »

okey.. im ready.
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: anyone wanna make an UGH! remake?

Post by avansc »

PixelP wrote:okey.. im ready.
ya have aim?
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
PixelP
Chaos Rift Regular
Chaos Rift Regular
Posts: 153
Joined: Tue Oct 07, 2008 12:23 pm
Programming Language of Choice: c/c++
Location: sweden
Contact:

Re: anyone wanna make an UGH! remake?

Post by PixelP »

avansc wrote:
PixelP wrote:okey.. im ready.
ya have aim?
yup... pixelpr0
User avatar
PixelP
Chaos Rift Regular
Chaos Rift Regular
Posts: 153
Joined: Tue Oct 07, 2008 12:23 pm
Programming Language of Choice: c/c++
Location: sweden
Contact:

Re: anyone wanna make an UGH! remake?

Post by PixelP »

PixelP wrote:
avansc wrote:
PixelP wrote:It's 5:40 here and I'm going to bed...

yeah i can, you gave the design ideas. the collision code. i just implimented it for you.
tomorrow we will make a level saver and loader, so that sohuld eb fun.
I've been reading trough all the code and I get everything but the update_Player function...

Code: Select all

void physics::update_Player(player *p)
{
	float g = 9.8;
	g *= p->weight;
	g *= 0.0001;
	p->yA += g;

	p->x += p->xA;
	p->y += p->yA;

	for(int a = 0;a < this->temp->object_Count;a++)
	{
		if(this->col(&this->temp->data[a], p))
		{
			p->x -= p->xA;
			p->y -= p->yA;
			p->yA = 0;
			p->xA = 0;
			return;
		}
	}

}
Can you comment it up?
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: anyone wanna make an UGH! remake?

Post by avansc »

PixelP wrote:
PixelP wrote:
avansc wrote:
PixelP wrote:It's 5:40 here and I'm going to bed...

yeah i can, you gave the design ideas. the collision code. i just implimented it for you.
tomorrow we will make a level saver and loader, so that sohuld eb fun.
I've been reading trough all the code and I get everything but the update_Player function...

Code: Select all

void physics::update_Player(player *p)
{
	float g = 9.8;     // this is gravity. (9.8 m/s)
	g *= p->weight;  // multiply out weight to is. our weight affects what gravity does on us
	g *= 0.0001;      // usually we would use a delta time, but i just messed around till i got a number that worked
	p->yA += g;        // finally add it to out current Y acceleration

	p->x += p->xA;    // update our x possition by adding our X accel to it
	p->y += p->yA;    // same for y


        // now we are going to loop through all the objects in the level to see if our new position causes a collision
	for(int a = 0;a < this->temp->object_Count;a++)  // loop through all objects
	{
		if(this->col(&this->temp->data[a], p))   // this is our collision check function
		{
                       // if we get to this point in the code we know there was a collision
                       // so we need to moce back and make our accelerations to 0
			p->x -= p->xA;   // move back to old x
			p->y -= p->yA;   // same
			p->yA = 0;         // set y accel to 0
			p->xA = 0;         // set x accel to 0
			return;             // get out of function, no need to continue.
		}
	}

}
Can you comment it up?
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

binary level loading AIM tutorial something or another.

Post by avansc »

i thought id just post it since we had some following on the thread.

Code: Select all

  
avans2die (5:37:00 PM): hey
pixelpr0 (5:37:16 PM): hi
avans2die (5:37:52 PM): okay. yeah this will be better. i think i'll be able to help more this way. you know you can ask a question about something and get an answer quickly.
avans2die (5:38:05 PM): okay... so we are gonna make a level saver and loader.
pixelpr0 (5:38:11 PM): yeah
avans2die (5:38:29 PM): send me your level.h and your player.h over AIM
pixelpr0 (5:38:43 PM): ok...
ATTENTION (5:39:10 PM): Transfer complete: level.h.
ATTENTION (5:39:10 PM): Transfer complete: player.h.
avans2die (5:39:13 PM): today you are gonna do all the coding. and im just here for advice. so i wanna see that you have.
avans2die (5:40:21 PM): okay awesome. no out design is not the best so we are going to have to get a little creative on how we save an load our levels.
avans2die (5:40:27 PM): but everything will work out fine.
avans2die (5:40:57 PM): we are going to make a class that will handle the saving and loading. what do you think we should call out class?
pixelpr0 (5:41:03 PM): okey.. but before we start check out the forum... i made a new post
avans2die (5:41:09 PM): okay
avans2die (5:41:56 PM): sure. let me comment it for you quickly.
pixelpr0 (5:42:04 PM): thanks man
pixelpr0 (5:42:45 PM): a class name that would fit loading and saving is hard to come up with...
pixelpr0 (5:43:42 PM): mayby log or something
pixelpr0 (5:43:48 PM): record
pixelpr0 (5:44:04 PM): ?
avans2die (5:44:21 PM): how about level_Loader?
pixelpr0 (5:44:53 PM): that will work out fine... is the class for both saving and loading?
avans2die (5:45:51 PM): yeah
pixelpr0 (5:45:58 PM): ok
avans2die (5:46:07 PM): so start making the class and get back to me.
avans2die (5:46:13 PM): i'll finish up the commenting
pixelpr0 (5:46:33 PM): ok
pixelpr0 (5:48:53 PM): what functions and variables should we use?
avans2die (5:49:51 PM): void save_Level(level *lvl, player *p);
void load_Level(level *lvl, player *p);\
avans2die (5:49:59 PM): no variables
avans2die (5:50:24 PM): remember to add

#include <level.h>
#include <player.h>

in level_Loader.h
pixelpr0 (5:51:06 PM): ofcurse
avans2die (5:52:21 PM): i replied to your post.
pixelpr0 (5:53:21 PM): good
avans2die (5:53:23 PM): let me know when you want to start on the level_Save function
pixelpr0 (5:54:10 PM): right away. and thaks for comment it up... ill read it later
avans2die (5:54:18 PM): okay
avans2die (5:55:16 PM): so, what we want to do, is save the level object and the player object at a state that represents a gamestate.
avans2die (5:56:14 PM): so first we want to make the level by putting a bunch of add_object statements like we did, or use a level editor (we might do that after we get through level_saving and loading)
avans2die (5:56:26 PM): okay. so do you have a basic level setup??
avans2die (5:56:44 PM): i mean like i sent it to you last night. with the 4 walls and the 2 platforms
pixelpr0 (5:57:11 PM): yeah.. i have that level but just one platform
avans2die (5:57:14 PM): somthing like this in main.cpp
player *p = new player(100,100,30,30);
level *lvl = new level();
lvl->add_Object(0, 0, 10, 499);
lvl->add_Object(489, 0, 10, 499);
lvl->add_Object(10, 0, 479, 10);
lvl->add_Object(10, 489, 479, 10);
lvl->add_Object(10, 350, 200, 20);
lvl->add_Object(300, 200, 189, 20);
pixelpr0 (5:57:37 PM): yeah... but i got color too!
avans2die (5:57:44 PM): okay thats fine.
pixelpr0 (5:57:59 PM): player *p = new player(100,100,30,30);
level *lvl = new level();

lvl->add_Object(0, 0, 10, 499, 255, 0, 0);
lvl->add_Object(489, 0, 10, 499, 255, 0, 0);
lvl->add_Object(10, 0, 479, 10, 255, 0, 0);
lvl->add_Object(10, 489, 479, 10, 255, 0, 0);

lvl->add_Object(100, 200, 50, 30, 23, 23, 123);
avans2die (5:58:01 PM): okay. go make level_Loader.cpp
avans2die (5:58:23 PM): also make a default constructor for level_Loader()
avans2die (5:58:48 PM): so in level_Loader.cpp you will have something like

level_Loader::level_Loader()
avans2die (5:58:49 PM): {
avans2die (5:58:50 PM): }\
pixelpr0 (5:58:51 PM): ive made level_Loader.cpp
avans2die (5:59:02 PM): did you code the default constructor>?
avans2die (5:59:08 PM): its important we need it
avans2die (5:59:21 PM): not really, but the way i like doing things we do
pixelpr0 (5:59:38 PM): default constructor... i maybe know what it is but not when i see that name?
avans2die (6:00:35 PM): i just mean that in level_Loader.h
do you have a 
level_Loader(); definition

and in level_Loader.cpp
level_Loader::level_Loader()
{
}
pixelpr0 (6:01:12 PM): oh... thats the name for that?? haha... yeah i got one "default constructoir
avans2die (6:01:17 PM): okay good.
avans2die (6:01:56 PM): have you type out

void level_Loader::save_Level(level *lvl, player *p)
{
}\
pixelpr0 signed off at 6:01:56 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
avans2die (6:02:44 PM): you there?
pixelpr0 signed on at 6:03:31 PM.
avans2die (6:03:44 PM): you back?
pixelpr0 (6:03:55 PM): what?
avans2die (6:04:02 PM): AIM said you logged off
pixelpr0 (6:04:04 PM): ive ben here all the time
avans2die (6:04:08 PM): oh.
avans2die (6:04:11 PM): anywaus
avans2die (6:04:28 PM): copy and paste what you have in level_Loader.cpp
pixelpr0 (6:04:43 PM): //level_loader.cpp
#include "level_loader.h"

level_Loader::level_Loader() {
    
}

void level_Loader::save_Level(level* lvl, player* p) {
    
}

void level_Loader::load_Level(level* lvl, player* p) {
    
}

avans2die (6:04:56 PM): okay excelent.
avans2die (6:05:00 PM): now the fun starts
pixelpr0 (6:05:05 PM): !!!
avans2die (6:05:12 PM): make sure these are in level_Loader.h
avans2die (6:05:13 PM): #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
pixelpr0 (6:05:56 PM): done
avans2die (6:06:01 PM): okay
avans2die (6:06:09 PM): fstream binFile(fileName, ios::out|ios::binary|ios::app);

avans2die (6:06:32 PM): thats the first line in savelevel
avans2die (6:06:56 PM): oh shit. we need to make a 3 parameter in out load and save function
avans2die (6:06:59 PM): char *fileName
avans2die (6:07:05 PM): do you understand what i mean?
pixelpr0 (6:07:18 PM): yeah, the file name for the binary file
pixelpr0 (6:07:29 PM): i do 20 elements
avans2die (6:07:38 PM): yeah. tell me when you done with adding the marameters.
avans2die (6:08:03 PM): dont worry about how many you have, out function wont care
avans2die (6:08:08 PM): our**
pixelpr0 (6:08:33 PM): done
avans2die (6:08:54 PM): good. di you add that line to the save_Level function?
avans2die (6:09:15 PM): the fstream line
pixelpr0 (6:09:24 PM): yup
avans2die (6:09:28 PM): okay good.
avans2die (6:09:42 PM): nest we are going to write the level to the file
pixelpr0 (6:10:13 PM): why do we need ios::binary and ios::app?
avans2die (6:10:42 PM): good question, ios::binary makes that we write a binary file
avans2die (6:11:19 PM): ios::app makes that if that file alreade exsists we only append to it. i do that just incase i dont over right important data by accidenty
avans2die (6:11:23 PM): okay
avans2die (6:11:26 PM): next line
avans2die (6:11:41 PM): 
binFile.write((char*)lvl, sizeof(level));
pixelpr0 (6:11:52 PM): of, okey
avans2die (6:12:23 PM): 
that writes the entire lvl variable into the file and know that its the size of the level class
avans2die (6:12:30 PM): got that done?
pixelpr0 (6:12:59 PM): yeah... i think i understand too
avans2die (6:13:14 PM): thats good. please stop and ask me if you have any questions
avans2die (6:13:28 PM): there is no such thing as a dumb question in my book
avans2die (6:13:54 PM): okay. no that we have finished saving out level, we have to save where out player is.
pixelpr0 (6:14:04 PM): yeah... lvl is a class object right..or whatever its called... why do we convert it to a char*
pixelpr0 (6:14:06 PM): ?
avans2die (6:14:24 PM): thats also a good question
avans2die (6:15:19 PM): so (char*) is another way of just saying a byte. and when we want to write binary files we have to write it in bytes.
avans2die (6:15:23 PM): 
binFile.write((char*)p, sizeof(player));
avans2die (6:15:27 PM): thats the next line
avans2die (6:15:37 PM): tell me when you are done
pixelpr0 (6:16:00 PM): oh.. yeah, now i get it
avans2die (6:16:29 PM): oaky.
avans2die (6:16:32 PM): you done?
pixelpr0 (6:16:35 PM): yup
avans2die (6:16:49 PM): okay. now all we need to do is close out file.
avans2die (6:16:54 PM): binFile.close()
avans2die (6:16:55 PM): ;
avans2die (6:17:08 PM): done?
pixelpr0 (6:17:13 PM): yup
avans2die (6:17:24 PM): okay. now we get to test our new function.
avans2die (6:17:31 PM): go to main.cpp
pixelpr0 (6:17:38 PM): so first it writes the levele data and then the player data?
avans2die (6:17:53 PM): yes sir
pixelpr0 (6:17:59 PM): that was easier than i thought
avans2die (6:18:03 PM): haha, yup
pixelpr0 (6:18:16 PM): im in main.cpp
avans2die (6:18:18 PM): player *p = new player(100,100,30,30);
level *lvl = new level();
avans2die (6:18:27 PM): can you find those lines in your main
pixelpr0 (6:18:30 PM): yup
avans2die (6:18:34 PM): you parameters might be diferent
pixelpr0 (6:18:48 PM): now, i dont change the player color
avans2die (6:19:10 PM): okay now make a new level_Loader object just like you would a player or level object
avans2die (6:19:25 PM): level_Loader *LL = new level_Loader();
avans2die (6:19:30 PM): tell me when you are done.
pixelpr0 (6:20:14 PM): yup.. no errors
avans2die (6:20:51 PM): okay
avans2die (6:21:00 PM): now go to the end of your game loop
pixelpr0 (6:21:00 PM): i played some UGH! today and i love it
avans2die (6:21:04 PM): haha good
avans2die (6:21:07 PM): me to
pixelpr0 (6:21:23 PM): hehe... im there
avans2die (6:22:22 PM): just befor SDL_Quit();
and just after the closing bracker "}"

place this line

LL->save_Level(lvl, p, "test.lvl")
avans2die (6:23:11 PM): just change the things that you have thats different. like if you didnt call it LL but something else. and if your level ovbject is not lvl and so on.
you can also call the "test.lvl" annything you like
avans2die (6:23:18 PM): let me know when you are done
avans2die (6:23:28 PM): dont run the program yer
avans2die (6:23:30 PM): yet
pixelpr0 (6:23:51 PM): im done..
avans2die (6:24:57 PM): okay. run the program, then moce the player object some where where it doesent start. ie, just land it on a platform thats not directly below it. then exit the program. dont run it afterwards.
avans2die (6:25:09 PM): tell me when you are done.
pixelpr0 (6:25:12 PM): ok
pixelpr0 (6:25:28 PM): ive opend it in ultraedit
avans2die (6:25:29 PM): okay. go look in the exe directory if you can see your level file
avans2die (6:25:34 PM): send me the file as well
ATTENTION (6:25:42 PM): Transfer complete: test.lvl.
avans2die (6:26:16 PM): okay nice.
avans2die (6:26:30 PM): now comment out the save_Level line in main.
pixelpr0 (6:26:46 PM): ok
avans2die (6:26:58 PM): okay, no we are goint to make our load_Level function
avans2die (6:27:07 PM): and you are gonna tell me what you think we need to do
avans2die (6:27:50 PM): you there?
pixelpr0 (6:28:24 PM): yeah.. we should read in the bytes or momething
avans2die (6:28:30 PM): haha, yeah
avans2die (6:28:53 PM): okay so first we need to make a file handle
avans2die (6:28:54 PM): fstream binGet(fileName, ios::binary|ios::in);
avans2die (6:29:18 PM): binGet is just a variable name, so you can call it whatever you want to
pixelpr0 (6:29:27 PM): binFile.read((char*)lvl, sizeof(level));
pixelpr0 (6:29:41 PM): maybe
avans2die (6:29:42 PM): yes, excelent
avans2die (6:30:09 PM): also remember the order we saved it in, we need to follow that order exactly or it wont work
pixelpr0 (6:30:19 PM): yeas... 
avans2die (6:30:39 PM): okay. did you  do the reading of the player as well yet?
avans2die (6:30:49 PM): and dont forget to close the file once you are done.
avans2die (6:31:41 PM): send me the level_Load function once you are dont
avans2die (6:31:43 PM): done
avans2die (6:32:07 PM): dont run the program yet, or try to. i'll tell you exactly how it needs to be done.
pixelpr0 signed off at 6:32:07 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
avans2die (6:32:20 PM): hello
pixelpr0 signed on at 6:33:05 PM.
pixelpr0 (6:33:15 PM): it was even more easier than i thounght ...
avans2die (6:33:37 PM): dont run the program yet, or try to. i'll tell you exactly how it needs to be done.
avans2die (6:34:06 PM): or have you done it already?
pixelpr0 (6:34:19 PM): you say i should run it?
avans2die (6:34:25 PM): not yet
pixelpr0 (6:34:28 PM): ok
avans2die (6:34:50 PM): vopy and paste load_Level function so i can look over it
avans2die (6:34:53 PM): then go to main.cpp
pixelpr0 (6:35:05 PM): void level_Loader::load_Level(level* lvl, player* p, char* fileName) {
    std::fstream binGet(fileName, std::ios::in|std::ios::binary);
    binGet.read((char*)lvl, sizeof(level));
    binGet.read((char*)p, sizeof(player));
    binGet.close();
}

avans2die (6:35:15 PM): okay good.
avans2die (6:35:21 PM): are you in main.cpp
pixelpr0 (6:35:26 PM): yup
pixelpr0 (6:35:39 PM): i assum we are going to do some loading
avans2die (6:36:06 PM): yeah, but we need to declare out variables a little different
pixelpr0 (6:36:18 PM): huh?
avans2die (6:36:49 PM): comment out all the decalrations like player *p = new player. and so on. you can leave the level variable. so just comment out the player and level variable
pixelpr0 (6:37:16 PM): done
avans2die (6:37:35 PM): the declare the variables like this.
player *p = (player*)malloc(sizeof(player));
level *lvl = (level*)malloc(sizeof(level));
avans2die (6:37:51 PM): that makes space in memory for player p and level lvl
pixelpr0 (6:37:52 PM): what does malloc do?
avans2die (6:38:01 PM): memory allocation
pixelpr0 (6:38:14 PM): oke
pixelpr0 (6:38:26 PM): why are we doing this?
avans2die (6:38:58 PM): because we are going to give LL there as perameter so we have to make sure that they are declaired and have their own memory
pixelpr0 (6:39:15 PM): oh, okey
avans2die (6:39:29 PM): the other way would have worked to, but this is more professional
pixelpr0 (6:39:40 PM): coool
avans2die (6:40:07 PM): also comment out any lines where you have lvl->add_Object or anything liek that. (all the stuff that you used to set up the level)
avans2die (6:40:19 PM): tell me when you are done.
pixelpr0 (6:40:34 PM): done
avans2die (6:41:18 PM): okay. ont more line. place this line after all the declarations of your object.

LL->load_Level(lvl, p, "test.lvl");
avans2die (6:41:28 PM): and run the program and lets see if our level is there.
avans2die (6:42:19 PM): any news?
pixelpr0 (6:42:41 PM): WHAT?!??! ITS WORKOIG!
pixelpr0 (6:42:52 PM): wow... damn thats great!
avans2die (6:43:01 PM): haha, good job. and i didnt write a line of code. you did it all!
pixelpr0 (6:43:32 PM): hheh, yeah.. im a little pround but you gave me all the instructions
avans2die (6:44:25 PM): well its not different than it would have been reading out a book
avans2die (6:45:02 PM): doesent matter how good or how much i know, if you werent capable we would have not been able to do this. so congrats
ATTENTION (6:45:09 PM): Transfer complete: main.cpp.
pixelpr0 (6:45:23 PM): thanks!
pixelpr0 (6:45:35 PM): is that right?
avans2die (6:45:52 PM): just remember that evertime you save it. it append to the file. so its gets bigger.
avans2die (6:46:00 PM): you were suppose to comment that out.
pixelpr0 (6:46:18 PM): yeah i know.. the save thing
pixelpr0 (6:46:39 PM): i just tried it out and forgot to change it back
avans2die (6:46:40 PM): it will still work. but there is data in the file you are not reading. its just basically a duplicate over and over, depending on how manytimes you have run the program
avans2die (6:47:00 PM): well now you are equipt with level loading
pixelpr0 (6:47:12 PM): souldnt the game overwrite it?
avans2die (6:48:01 PM): well we uss ios::app which just appends data
pixelpr0 (6:48:24 PM): yeah
pixelpr0 (6:49:25 PM): but when i remove the comment out of the save line and runs the game and exits and  then starts over again it doesnt save
pixelpr0 (6:49:56 PM): should it do so?
avans2die (6:49:56 PM): i dont understand
avans2die (6:50:08 PM): oaky do this.
avans2die (6:50:48 PM): make the save_Level thing have "level01.lvl" as the level name parameter.
avans2die (6:50:54 PM): run the program only once.
avans2die (6:50:59 PM): tell me when you are done.
pixelpr0 (6:51:23 PM): ok
pixelpr0 (6:51:25 PM): done
avans2die (6:51:42 PM): now comment the save line out (play a "//" infront of it)
pixelpr0 (6:51:51 PM): and change the loading
pixelpr0 (6:51:55 PM): it works...
pixelpr0 (6:51:59 PM): thx
avans2die (6:52:00 PM): then go to the load_Level and change it to "level01.lvl"
avans2die (6:52:03 PM): good
pixelpr0 (6:52:19 PM): so it cant load and save in the same file?
avans2die (6:52:51 PM): no it can. but the problem is that if you load it, then save it again you are just appending it.
avans2die (6:53:11 PM): open up test.lvl and level01.lvl in ultra edit
avans2die (6:53:14 PM): look at them
avans2die (6:54:10 PM): test.lvl should just be like level01.lvl except that it has a loop in it. its like duplicated over and over (deoending on how many times you had run it)
avans2die (6:55:09 PM): you understand?
pixelpr0 (6:55:19 PM): wait...
avans2die (6:55:50 PM): yes
pixelpr0 (6:56:29 PM): yeah.. its the same until the end.. thats where it adds new bytes
avans2die (6:56:51 PM): send me both lvl files
ATTENTION (6:57:02 PM): Transfer complete: test.lvl.
ATTENTION (6:57:07 PM): Transfer complete: level01.lvl.
avans2die (6:58:07 PM): oh, the minor diferences of bytes you see in the files is the position of the player.
avans2die (6:58:48 PM): obviously you didnt exit the game having the player be at the same place. so those bytes are different
pixelpr0 (6:58:50 PM): oh, okey
pixelpr0 (7:00:11 PM): if you finds the memory adress of the playerscoordinates you can edit them in the savestate...
pixelpr0 (7:00:45 PM): thisi is a really smart way of saving&loading....
avans2die (7:02:28 PM): yes. you can. you can write another program that you can load up a level (if you knew how it was stored) and chage values and then load the level with the game and you will see those reflected values.

thats exactly how character editors work for games. like diablo had a bunch of char editors.
pixelpr0 signed off at 7:02:29 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
pixelpr0 signed on at 7:05:06 PM.
avans2die (7:05:29 PM): yes. you can. you can write another program that you can load up a level (if you knew how it was stored) and chage values and then load the level with the game and you will see those reflected values.

thats exactly how character editors work for games. like diablo had a bunch of char editors.
pixelpr0 (7:06:26 PM): oh okey.. ive made programms that changes the values of memory adresses in games
avans2die (7:06:35 PM): cool
pixelpr0 (7:06:45 PM): i got a vid on youtube
avans2die (7:06:54 PM): really. send the link
pixelpr0 (7:07:04 PM): wait then
avans2die (7:07:06 PM): k
pixelpr0 (7:07:45 PM): http://www.youtube.com/watch?v=s978shNelPQ
pixelpr0 (7:07:56 PM): kinda shitty vid but whatever
pixelpr0 (7:08:03 PM): i got alot of devvids
avans2die (7:08:11 PM): i'll check them out
pixelpr0 (7:08:33 PM): itll take like x hours
avans2die (7:09:01 PM): i only see 11 videos
pixelpr0 (7:09:15 PM): hehe, i was kiddign
avans2die (7:09:20 PM): oh
avans2die (7:09:21 PM): hehe
pixelpr0 (7:09:52 PM): dont watch the old ones... they sucks alot
avans2die (7:09:58 PM): well you look like you are very capable. keep up the good work. and always push yourself. dont doubt yourself ever.
pixelpr0 (7:11:01 PM): i dont really know... some times i  just want to die when i sees my code...
pixelpr0 (7:11:23 PM): Ii like to learn and youve been very kind and helped me
avans2die (7:13:11 PM): haha. dont worry. with time you will find a style and get into a rythem. no one just starts programming and is good at it. the people that made games like doom and what not, did not just pick up a keyboard and get it right the first time. the dedicated thousands of man hours. and i love to help, especially when the person wants to learn. so if you ever have a question please feel free to ask.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
PixelP
Chaos Rift Regular
Chaos Rift Regular
Posts: 153
Joined: Tue Oct 07, 2008 12:23 pm
Programming Language of Choice: c/c++
Location: sweden
Contact:

Re: anyone wanna make an UGH! remake?

Post by PixelP »

good.
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: anyone wanna make an UGH! remake?

Post by M_D_K »

avansc wrote:i thought id just post it since we had some following on the thread.

Code: Select all

  
avans2die (5:37:00 PM): hey
pixelpr0 (5:37:16 PM): hi
avans2die (5:37:52 PM): okay. yeah this will be better. i think i'll be able to help more this way. you know you can ask a question about something and get an answer quickly.
avans2die (5:38:05 PM): okay... so we are gonna make a level saver and loader.
pixelpr0 (5:38:11 PM): yeah
avans2die (5:38:29 PM): send me your level.h and your player.h over AIM
pixelpr0 (5:38:43 PM): ok...
ATTENTION (5:39:10 PM): Transfer complete: level.h.
ATTENTION (5:39:10 PM): Transfer complete: player.h.
avans2die (5:39:13 PM): today you are gonna do all the coding. and im just here for advice. so i wanna see that you have.
avans2die (5:40:21 PM): okay awesome. no out design is not the best so we are going to have to get a little creative on how we save an load our levels.
avans2die (5:40:27 PM): but everything will work out fine.
avans2die (5:40:57 PM): we are going to make a class that will handle the saving and loading. what do you think we should call out class?
pixelpr0 (5:41:03 PM): okey.. but before we start check out the forum... i made a new post
avans2die (5:41:09 PM): okay
avans2die (5:41:56 PM): sure. let me comment it for you quickly.
pixelpr0 (5:42:04 PM): thanks man
pixelpr0 (5:42:45 PM): a class name that would fit loading and saving is hard to come up with...
pixelpr0 (5:43:42 PM): mayby log or something
pixelpr0 (5:43:48 PM): record
pixelpr0 (5:44:04 PM): ?
avans2die (5:44:21 PM): how about level_Loader?
pixelpr0 (5:44:53 PM): that will work out fine... is the class for both saving and loading?
avans2die (5:45:51 PM): yeah
pixelpr0 (5:45:58 PM): ok
avans2die (5:46:07 PM): so start making the class and get back to me.
avans2die (5:46:13 PM): i'll finish up the commenting
pixelpr0 (5:46:33 PM): ok
pixelpr0 (5:48:53 PM): what functions and variables should we use?
avans2die (5:49:51 PM): void save_Level(level *lvl, player *p);
void load_Level(level *lvl, player *p);\
avans2die (5:49:59 PM): no variables
avans2die (5:50:24 PM): remember to add

#include <level.h>
#include <player.h>

in level_Loader.h
pixelpr0 (5:51:06 PM): ofcurse
avans2die (5:52:21 PM): i replied to your post.
pixelpr0 (5:53:21 PM): good
avans2die (5:53:23 PM): let me know when you want to start on the level_Save function
pixelpr0 (5:54:10 PM): right away. and thaks for comment it up... ill read it later
avans2die (5:54:18 PM): okay
avans2die (5:55:16 PM): so, what we want to do, is save the level object and the player object at a state that represents a gamestate.
avans2die (5:56:14 PM): so first we want to make the level by putting a bunch of add_object statements like we did, or use a level editor (we might do that after we get through level_saving and loading)
avans2die (5:56:26 PM): okay. so do you have a basic level setup??
avans2die (5:56:44 PM): i mean like i sent it to you last night. with the 4 walls and the 2 platforms
pixelpr0 (5:57:11 PM): yeah.. i have that level but just one platform
avans2die (5:57:14 PM): somthing like this in main.cpp
player *p = new player(100,100,30,30);
level *lvl = new level();
lvl->add_Object(0, 0, 10, 499);
lvl->add_Object(489, 0, 10, 499);
lvl->add_Object(10, 0, 479, 10);
lvl->add_Object(10, 489, 479, 10);
lvl->add_Object(10, 350, 200, 20);
lvl->add_Object(300, 200, 189, 20);
pixelpr0 (5:57:37 PM): yeah... but i got color too!
avans2die (5:57:44 PM): okay thats fine.
pixelpr0 (5:57:59 PM): player *p = new player(100,100,30,30);
level *lvl = new level();

lvl->add_Object(0, 0, 10, 499, 255, 0, 0);
lvl->add_Object(489, 0, 10, 499, 255, 0, 0);
lvl->add_Object(10, 0, 479, 10, 255, 0, 0);
lvl->add_Object(10, 489, 479, 10, 255, 0, 0);

lvl->add_Object(100, 200, 50, 30, 23, 23, 123);
avans2die (5:58:01 PM): okay. go make level_Loader.cpp
avans2die (5:58:23 PM): also make a default constructor for level_Loader()
avans2die (5:58:48 PM): so in level_Loader.cpp you will have something like

level_Loader::level_Loader()
avans2die (5:58:49 PM): {
avans2die (5:58:50 PM): }\
pixelpr0 (5:58:51 PM): ive made level_Loader.cpp
avans2die (5:59:02 PM): did you code the default constructor>?
avans2die (5:59:08 PM): its important we need it
avans2die (5:59:21 PM): not really, but the way i like doing things we do
pixelpr0 (5:59:38 PM): default constructor... i maybe know what it is but not when i see that name?
avans2die (6:00:35 PM): i just mean that in level_Loader.h
do you have a 
level_Loader(); definition

and in level_Loader.cpp
level_Loader::level_Loader()
{
}
pixelpr0 (6:01:12 PM): oh... thats the name for that?? haha... yeah i got one "default constructoir
avans2die (6:01:17 PM): okay good.
avans2die (6:01:56 PM): have you type out

void level_Loader::save_Level(level *lvl, player *p)
{
}\
pixelpr0 signed off at 6:01:56 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
avans2die (6:02:44 PM): you there?
pixelpr0 signed on at 6:03:31 PM.
avans2die (6:03:44 PM): you back?
pixelpr0 (6:03:55 PM): what?
avans2die (6:04:02 PM): AIM said you logged off
pixelpr0 (6:04:04 PM): ive ben here all the time
avans2die (6:04:08 PM): oh.
avans2die (6:04:11 PM): anywaus
avans2die (6:04:28 PM): copy and paste what you have in level_Loader.cpp
pixelpr0 (6:04:43 PM): //level_loader.cpp
#include "level_loader.h"

level_Loader::level_Loader() {
    
}

void level_Loader::save_Level(level* lvl, player* p) {
    
}

void level_Loader::load_Level(level* lvl, player* p) {
    
}

avans2die (6:04:56 PM): okay excelent.
avans2die (6:05:00 PM): now the fun starts
pixelpr0 (6:05:05 PM): !!!
avans2die (6:05:12 PM): make sure these are in level_Loader.h
avans2die (6:05:13 PM): #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
pixelpr0 (6:05:56 PM): done
avans2die (6:06:01 PM): okay
avans2die (6:06:09 PM): fstream binFile(fileName, ios::out|ios::binary|ios::app);

avans2die (6:06:32 PM): thats the first line in savelevel
avans2die (6:06:56 PM): oh shit. we need to make a 3 parameter in out load and save function
avans2die (6:06:59 PM): char *fileName
avans2die (6:07:05 PM): do you understand what i mean?
pixelpr0 (6:07:18 PM): yeah, the file name for the binary file
pixelpr0 (6:07:29 PM): i do 20 elements
avans2die (6:07:38 PM): yeah. tell me when you done with adding the marameters.
avans2die (6:08:03 PM): dont worry about how many you have, out function wont care
avans2die (6:08:08 PM): our**
pixelpr0 (6:08:33 PM): done
avans2die (6:08:54 PM): good. di you add that line to the save_Level function?
avans2die (6:09:15 PM): the fstream line
pixelpr0 (6:09:24 PM): yup
avans2die (6:09:28 PM): okay good.
avans2die (6:09:42 PM): nest we are going to write the level to the file
pixelpr0 (6:10:13 PM): why do we need ios::binary and ios::app?
avans2die (6:10:42 PM): good question, ios::binary makes that we write a binary file
avans2die (6:11:19 PM): ios::app makes that if that file alreade exsists we only append to it. i do that just incase i dont over right important data by accidenty
avans2die (6:11:23 PM): okay
avans2die (6:11:26 PM): next line
avans2die (6:11:41 PM): 
binFile.write((char*)lvl, sizeof(level));
pixelpr0 (6:11:52 PM): of, okey
avans2die (6:12:23 PM): 
that writes the entire lvl variable into the file and know that its the size of the level class
avans2die (6:12:30 PM): got that done?
pixelpr0 (6:12:59 PM): yeah... i think i understand too
avans2die (6:13:14 PM): thats good. please stop and ask me if you have any questions
avans2die (6:13:28 PM): there is no such thing as a dumb question in my book
avans2die (6:13:54 PM): okay. no that we have finished saving out level, we have to save where out player is.
pixelpr0 (6:14:04 PM): yeah... lvl is a class object right..or whatever its called... why do we convert it to a char*
pixelpr0 (6:14:06 PM): ?
avans2die (6:14:24 PM): thats also a good question
avans2die (6:15:19 PM): so (char*) is another way of just saying a byte. and when we want to write binary files we have to write it in bytes.
avans2die (6:15:23 PM): 
binFile.write((char*)p, sizeof(player));
avans2die (6:15:27 PM): thats the next line
avans2die (6:15:37 PM): tell me when you are done
pixelpr0 (6:16:00 PM): oh.. yeah, now i get it
avans2die (6:16:29 PM): oaky.
avans2die (6:16:32 PM): you done?
pixelpr0 (6:16:35 PM): yup
avans2die (6:16:49 PM): okay. now all we need to do is close out file.
avans2die (6:16:54 PM): binFile.close()
avans2die (6:16:55 PM): ;
avans2die (6:17:08 PM): done?
pixelpr0 (6:17:13 PM): yup
avans2die (6:17:24 PM): okay. now we get to test our new function.
avans2die (6:17:31 PM): go to main.cpp
pixelpr0 (6:17:38 PM): so first it writes the levele data and then the player data?
avans2die (6:17:53 PM): yes sir
pixelpr0 (6:17:59 PM): that was easier than i thought
avans2die (6:18:03 PM): haha, yup
pixelpr0 (6:18:16 PM): im in main.cpp
avans2die (6:18:18 PM): player *p = new player(100,100,30,30);
level *lvl = new level();
avans2die (6:18:27 PM): can you find those lines in your main
pixelpr0 (6:18:30 PM): yup
avans2die (6:18:34 PM): you parameters might be diferent
pixelpr0 (6:18:48 PM): now, i dont change the player color
avans2die (6:19:10 PM): okay now make a new level_Loader object just like you would a player or level object
avans2die (6:19:25 PM): level_Loader *LL = new level_Loader();
avans2die (6:19:30 PM): tell me when you are done.
pixelpr0 (6:20:14 PM): yup.. no errors
avans2die (6:20:51 PM): okay
avans2die (6:21:00 PM): now go to the end of your game loop
pixelpr0 (6:21:00 PM): i played some UGH! today and i love it
avans2die (6:21:04 PM): haha good
avans2die (6:21:07 PM): me to
pixelpr0 (6:21:23 PM): hehe... im there
avans2die (6:22:22 PM): just befor SDL_Quit();
and just after the closing bracker "}"

place this line

LL->save_Level(lvl, p, "test.lvl")
avans2die (6:23:11 PM): just change the things that you have thats different. like if you didnt call it LL but something else. and if your level ovbject is not lvl and so on.
you can also call the "test.lvl" annything you like
avans2die (6:23:18 PM): let me know when you are done
avans2die (6:23:28 PM): dont run the program yer
avans2die (6:23:30 PM): yet
pixelpr0 (6:23:51 PM): im done..
avans2die (6:24:57 PM): okay. run the program, then moce the player object some where where it doesent start. ie, just land it on a platform thats not directly below it. then exit the program. dont run it afterwards.
avans2die (6:25:09 PM): tell me when you are done.
pixelpr0 (6:25:12 PM): ok
pixelpr0 (6:25:28 PM): ive opend it in ultraedit
avans2die (6:25:29 PM): okay. go look in the exe directory if you can see your level file
avans2die (6:25:34 PM): send me the file as well
ATTENTION (6:25:42 PM): Transfer complete: test.lvl.
avans2die (6:26:16 PM): okay nice.
avans2die (6:26:30 PM): now comment out the save_Level line in main.
pixelpr0 (6:26:46 PM): ok
avans2die (6:26:58 PM): okay, no we are goint to make our load_Level function
avans2die (6:27:07 PM): and you are gonna tell me what you think we need to do
avans2die (6:27:50 PM): you there?
pixelpr0 (6:28:24 PM): yeah.. we should read in the bytes or momething
avans2die (6:28:30 PM): haha, yeah
avans2die (6:28:53 PM): okay so first we need to make a file handle
avans2die (6:28:54 PM): fstream binGet(fileName, ios::binary|ios::in);
avans2die (6:29:18 PM): binGet is just a variable name, so you can call it whatever you want to
pixelpr0 (6:29:27 PM): binFile.read((char*)lvl, sizeof(level));
pixelpr0 (6:29:41 PM): maybe
avans2die (6:29:42 PM): yes, excelent
avans2die (6:30:09 PM): also remember the order we saved it in, we need to follow that order exactly or it wont work
pixelpr0 (6:30:19 PM): yeas... 
avans2die (6:30:39 PM): okay. did you  do the reading of the player as well yet?
avans2die (6:30:49 PM): and dont forget to close the file once you are done.
avans2die (6:31:41 PM): send me the level_Load function once you are dont
avans2die (6:31:43 PM): done
avans2die (6:32:07 PM): dont run the program yet, or try to. i'll tell you exactly how it needs to be done.
pixelpr0 signed off at 6:32:07 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
avans2die (6:32:20 PM): hello
pixelpr0 signed on at 6:33:05 PM.
pixelpr0 (6:33:15 PM): it was even more easier than i thounght ...
avans2die (6:33:37 PM): dont run the program yet, or try to. i'll tell you exactly how it needs to be done.
avans2die (6:34:06 PM): or have you done it already?
pixelpr0 (6:34:19 PM): you say i should run it?
avans2die (6:34:25 PM): not yet
pixelpr0 (6:34:28 PM): ok
avans2die (6:34:50 PM): vopy and paste load_Level function so i can look over it
avans2die (6:34:53 PM): then go to main.cpp
pixelpr0 (6:35:05 PM): void level_Loader::load_Level(level* lvl, player* p, char* fileName) {
    std::fstream binGet(fileName, std::ios::in|std::ios::binary);
    binGet.read((char*)lvl, sizeof(level));
    binGet.read((char*)p, sizeof(player));
    binGet.close();
}

avans2die (6:35:15 PM): okay good.
avans2die (6:35:21 PM): are you in main.cpp
pixelpr0 (6:35:26 PM): yup
pixelpr0 (6:35:39 PM): i assum we are going to do some loading
avans2die (6:36:06 PM): yeah, but we need to declare out variables a little different
pixelpr0 (6:36:18 PM): huh?
avans2die (6:36:49 PM): comment out all the decalrations like player *p = new player. and so on. you can leave the level variable. so just comment out the player and level variable
pixelpr0 (6:37:16 PM): done
avans2die (6:37:35 PM): the declare the variables like this.
player *p = (player*)malloc(sizeof(player));
level *lvl = (level*)malloc(sizeof(level));
avans2die (6:37:51 PM): that makes space in memory for player p and level lvl
pixelpr0 (6:37:52 PM): what does malloc do?
avans2die (6:38:01 PM): memory allocation
pixelpr0 (6:38:14 PM): oke
pixelpr0 (6:38:26 PM): why are we doing this?
avans2die (6:38:58 PM): because we are going to give LL there as perameter so we have to make sure that they are declaired and have their own memory
pixelpr0 (6:39:15 PM): oh, okey
avans2die (6:39:29 PM): the other way would have worked to, but this is more professional
pixelpr0 (6:39:40 PM): coool
avans2die (6:40:07 PM): also comment out any lines where you have lvl->add_Object or anything liek that. (all the stuff that you used to set up the level)
avans2die (6:40:19 PM): tell me when you are done.
pixelpr0 (6:40:34 PM): done
avans2die (6:41:18 PM): okay. ont more line. place this line after all the declarations of your object.

LL->load_Level(lvl, p, "test.lvl");
avans2die (6:41:28 PM): and run the program and lets see if our level is there.
avans2die (6:42:19 PM): any news?
pixelpr0 (6:42:41 PM): WHAT?!??! ITS WORKOIG!
pixelpr0 (6:42:52 PM): wow... damn thats great!
avans2die (6:43:01 PM): haha, good job. and i didnt write a line of code. you did it all!
pixelpr0 (6:43:32 PM): hheh, yeah.. im a little pround but you gave me all the instructions
avans2die (6:44:25 PM): well its not different than it would have been reading out a book
avans2die (6:45:02 PM): doesent matter how good or how much i know, if you werent capable we would have not been able to do this. so congrats
ATTENTION (6:45:09 PM): Transfer complete: main.cpp.
pixelpr0 (6:45:23 PM): thanks!
pixelpr0 (6:45:35 PM): is that right?
avans2die (6:45:52 PM): just remember that evertime you save it. it append to the file. so its gets bigger.
avans2die (6:46:00 PM): you were suppose to comment that out.
pixelpr0 (6:46:18 PM): yeah i know.. the save thing
pixelpr0 (6:46:39 PM): i just tried it out and forgot to change it back
avans2die (6:46:40 PM): it will still work. but there is data in the file you are not reading. its just basically a duplicate over and over, depending on how manytimes you have run the program
avans2die (6:47:00 PM): well now you are equipt with level loading
pixelpr0 (6:47:12 PM): souldnt the game overwrite it?
avans2die (6:48:01 PM): well we uss ios::app which just appends data
pixelpr0 (6:48:24 PM): yeah
pixelpr0 (6:49:25 PM): but when i remove the comment out of the save line and runs the game and exits and  then starts over again it doesnt save
pixelpr0 (6:49:56 PM): should it do so?
avans2die (6:49:56 PM): i dont understand
avans2die (6:50:08 PM): oaky do this.
avans2die (6:50:48 PM): make the save_Level thing have "level01.lvl" as the level name parameter.
avans2die (6:50:54 PM): run the program only once.
avans2die (6:50:59 PM): tell me when you are done.
pixelpr0 (6:51:23 PM): ok
pixelpr0 (6:51:25 PM): done
avans2die (6:51:42 PM): now comment the save line out (play a "//" infront of it)
pixelpr0 (6:51:51 PM): and change the loading
pixelpr0 (6:51:55 PM): it works...
pixelpr0 (6:51:59 PM): thx
avans2die (6:52:00 PM): then go to the load_Level and change it to "level01.lvl"
avans2die (6:52:03 PM): good
pixelpr0 (6:52:19 PM): so it cant load and save in the same file?
avans2die (6:52:51 PM): no it can. but the problem is that if you load it, then save it again you are just appending it.
avans2die (6:53:11 PM): open up test.lvl and level01.lvl in ultra edit
avans2die (6:53:14 PM): look at them
avans2die (6:54:10 PM): test.lvl should just be like level01.lvl except that it has a loop in it. its like duplicated over and over (deoending on how many times you had run it)
avans2die (6:55:09 PM): you understand?
pixelpr0 (6:55:19 PM): wait...
avans2die (6:55:50 PM): yes
pixelpr0 (6:56:29 PM): yeah.. its the same until the end.. thats where it adds new bytes
avans2die (6:56:51 PM): send me both lvl files
ATTENTION (6:57:02 PM): Transfer complete: test.lvl.
ATTENTION (6:57:07 PM): Transfer complete: level01.lvl.
avans2die (6:58:07 PM): oh, the minor diferences of bytes you see in the files is the position of the player.
avans2die (6:58:48 PM): obviously you didnt exit the game having the player be at the same place. so those bytes are different
pixelpr0 (6:58:50 PM): oh, okey
pixelpr0 (7:00:11 PM): if you finds the memory adress of the playerscoordinates you can edit them in the savestate...
pixelpr0 (7:00:45 PM): thisi is a really smart way of saving&loading....
avans2die (7:02:28 PM): yes. you can. you can write another program that you can load up a level (if you knew how it was stored) and chage values and then load the level with the game and you will see those reflected values.

thats exactly how character editors work for games. like diablo had a bunch of char editors.
pixelpr0 signed off at 7:02:29 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
pixelpr0 signed on at 7:05:06 PM.
avans2die (7:05:29 PM): yes. you can. you can write another program that you can load up a level (if you knew how it was stored) and chage values and then load the level with the game and you will see those reflected values.

thats exactly how character editors work for games. like diablo had a bunch of char editors.
pixelpr0 (7:06:26 PM): oh okey.. ive made programms that changes the values of memory adresses in games
avans2die (7:06:35 PM): cool
pixelpr0 (7:06:45 PM): i got a vid on youtube
avans2die (7:06:54 PM): really. send the link
pixelpr0 (7:07:04 PM): wait then
avans2die (7:07:06 PM): k
pixelpr0 (7:07:45 PM): http://www.youtube.com/watch?v=s978shNelPQ
pixelpr0 (7:07:56 PM): kinda shitty vid but whatever
pixelpr0 (7:08:03 PM): i got alot of devvids
avans2die (7:08:11 PM): i'll check them out
pixelpr0 (7:08:33 PM): itll take like x hours
avans2die (7:09:01 PM): i only see 11 videos
pixelpr0 (7:09:15 PM): hehe, i was kiddign
avans2die (7:09:20 PM): oh
avans2die (7:09:21 PM): hehe
pixelpr0 (7:09:52 PM): dont watch the old ones... they sucks alot
avans2die (7:09:58 PM): well you look like you are very capable. keep up the good work. and always push yourself. dont doubt yourself ever.
pixelpr0 (7:11:01 PM): i dont really know... some times i  just want to die when i sees my code...
pixelpr0 (7:11:23 PM): Ii like to learn and youve been very kind and helped me
avans2die (7:13:11 PM): haha. dont worry. with time you will find a style and get into a rythem. no one just starts programming and is good at it. the people that made games like doom and what not, did not just pick up a keyboard and get it right the first time. the dedicated thousands of man hours. and i love to help, especially when the person wants to learn. so if you ever have a question please feel free to ask.
Wow! thats alot to read (but I did :) ) Nice work, you guys covered alot.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
PixelP
Chaos Rift Regular
Chaos Rift Regular
Posts: 153
Joined: Tue Oct 07, 2008 12:23 pm
Programming Language of Choice: c/c++
Location: sweden
Contact:

Re: anyone wanna make an UGH! remake?

Post by PixelP »

M_D_K wrote:
avansc wrote:i thought id just post it since we had some following on the thread.

Code: Select all

  
avans2die (5:37:00 PM): hey
pixelpr0 (5:37:16 PM): hi
avans2die (5:37:52 PM): okay. yeah this will be better. i think i'll be able to help more this way. you know you can ask a question about something and get an answer quickly.
avans2die (5:38:05 PM): okay... so we are gonna make a level saver and loader.
pixelpr0 (5:38:11 PM): yeah
avans2die (5:38:29 PM): send me your level.h and your player.h over AIM
pixelpr0 (5:38:43 PM): ok...
ATTENTION (5:39:10 PM): Transfer complete: level.h.
ATTENTION (5:39:10 PM): Transfer complete: player.h.
avans2die (5:39:13 PM): today you are gonna do all the coding. and im just here for advice. so i wanna see that you have.
avans2die (5:40:21 PM): okay awesome. no out design is not the best so we are going to have to get a little creative on how we save an load our levels.
avans2die (5:40:27 PM): but everything will work out fine.
avans2die (5:40:57 PM): we are going to make a class that will handle the saving and loading. what do you think we should call out class?
pixelpr0 (5:41:03 PM): okey.. but before we start check out the forum... i made a new post
avans2die (5:41:09 PM): okay
avans2die (5:41:56 PM): sure. let me comment it for you quickly.
pixelpr0 (5:42:04 PM): thanks man
pixelpr0 (5:42:45 PM): a class name that would fit loading and saving is hard to come up with...
pixelpr0 (5:43:42 PM): mayby log or something
pixelpr0 (5:43:48 PM): record
pixelpr0 (5:44:04 PM): ?
avans2die (5:44:21 PM): how about level_Loader?
pixelpr0 (5:44:53 PM): that will work out fine... is the class for both saving and loading?
avans2die (5:45:51 PM): yeah
pixelpr0 (5:45:58 PM): ok
avans2die (5:46:07 PM): so start making the class and get back to me.
avans2die (5:46:13 PM): i'll finish up the commenting
pixelpr0 (5:46:33 PM): ok
pixelpr0 (5:48:53 PM): what functions and variables should we use?
avans2die (5:49:51 PM): void save_Level(level *lvl, player *p);
void load_Level(level *lvl, player *p);\
avans2die (5:49:59 PM): no variables
avans2die (5:50:24 PM): remember to add

#include <level.h>
#include <player.h>

in level_Loader.h
pixelpr0 (5:51:06 PM): ofcurse
avans2die (5:52:21 PM): i replied to your post.
pixelpr0 (5:53:21 PM): good
avans2die (5:53:23 PM): let me know when you want to start on the level_Save function
pixelpr0 (5:54:10 PM): right away. and thaks for comment it up... ill read it later
avans2die (5:54:18 PM): okay
avans2die (5:55:16 PM): so, what we want to do, is save the level object and the player object at a state that represents a gamestate.
avans2die (5:56:14 PM): so first we want to make the level by putting a bunch of add_object statements like we did, or use a level editor (we might do that after we get through level_saving and loading)
avans2die (5:56:26 PM): okay. so do you have a basic level setup??
avans2die (5:56:44 PM): i mean like i sent it to you last night. with the 4 walls and the 2 platforms
pixelpr0 (5:57:11 PM): yeah.. i have that level but just one platform
avans2die (5:57:14 PM): somthing like this in main.cpp
player *p = new player(100,100,30,30);
level *lvl = new level();
lvl->add_Object(0, 0, 10, 499);
lvl->add_Object(489, 0, 10, 499);
lvl->add_Object(10, 0, 479, 10);
lvl->add_Object(10, 489, 479, 10);
lvl->add_Object(10, 350, 200, 20);
lvl->add_Object(300, 200, 189, 20);
pixelpr0 (5:57:37 PM): yeah... but i got color too!
avans2die (5:57:44 PM): okay thats fine.
pixelpr0 (5:57:59 PM): player *p = new player(100,100,30,30);
level *lvl = new level();

lvl->add_Object(0, 0, 10, 499, 255, 0, 0);
lvl->add_Object(489, 0, 10, 499, 255, 0, 0);
lvl->add_Object(10, 0, 479, 10, 255, 0, 0);
lvl->add_Object(10, 489, 479, 10, 255, 0, 0);

lvl->add_Object(100, 200, 50, 30, 23, 23, 123);
avans2die (5:58:01 PM): okay. go make level_Loader.cpp
avans2die (5:58:23 PM): also make a default constructor for level_Loader()
avans2die (5:58:48 PM): so in level_Loader.cpp you will have something like

level_Loader::level_Loader()
avans2die (5:58:49 PM): {
avans2die (5:58:50 PM): }\
pixelpr0 (5:58:51 PM): ive made level_Loader.cpp
avans2die (5:59:02 PM): did you code the default constructor>?
avans2die (5:59:08 PM): its important we need it
avans2die (5:59:21 PM): not really, but the way i like doing things we do
pixelpr0 (5:59:38 PM): default constructor... i maybe know what it is but not when i see that name?
avans2die (6:00:35 PM): i just mean that in level_Loader.h
do you have a 
level_Loader(); definition

and in level_Loader.cpp
level_Loader::level_Loader()
{
}
pixelpr0 (6:01:12 PM): oh... thats the name for that?? haha... yeah i got one "default constructoir
avans2die (6:01:17 PM): okay good.
avans2die (6:01:56 PM): have you type out

void level_Loader::save_Level(level *lvl, player *p)
{
}\
pixelpr0 signed off at 6:01:56 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
avans2die (6:02:44 PM): you there?
pixelpr0 signed on at 6:03:31 PM.
avans2die (6:03:44 PM): you back?
pixelpr0 (6:03:55 PM): what?
avans2die (6:04:02 PM): AIM said you logged off
pixelpr0 (6:04:04 PM): ive ben here all the time
avans2die (6:04:08 PM): oh.
avans2die (6:04:11 PM): anywaus
avans2die (6:04:28 PM): copy and paste what you have in level_Loader.cpp
pixelpr0 (6:04:43 PM): //level_loader.cpp
#include "level_loader.h"

level_Loader::level_Loader() {
    
}

void level_Loader::save_Level(level* lvl, player* p) {
    
}

void level_Loader::load_Level(level* lvl, player* p) {
    
}

avans2die (6:04:56 PM): okay excelent.
avans2die (6:05:00 PM): now the fun starts
pixelpr0 (6:05:05 PM): !!!
avans2die (6:05:12 PM): make sure these are in level_Loader.h
avans2die (6:05:13 PM): #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
pixelpr0 (6:05:56 PM): done
avans2die (6:06:01 PM): okay
avans2die (6:06:09 PM): fstream binFile(fileName, ios::out|ios::binary|ios::app);

avans2die (6:06:32 PM): thats the first line in savelevel
avans2die (6:06:56 PM): oh shit. we need to make a 3 parameter in out load and save function
avans2die (6:06:59 PM): char *fileName
avans2die (6:07:05 PM): do you understand what i mean?
pixelpr0 (6:07:18 PM): yeah, the file name for the binary file
pixelpr0 (6:07:29 PM): i do 20 elements
avans2die (6:07:38 PM): yeah. tell me when you done with adding the marameters.
avans2die (6:08:03 PM): dont worry about how many you have, out function wont care
avans2die (6:08:08 PM): our**
pixelpr0 (6:08:33 PM): done
avans2die (6:08:54 PM): good. di you add that line to the save_Level function?
avans2die (6:09:15 PM): the fstream line
pixelpr0 (6:09:24 PM): yup
avans2die (6:09:28 PM): okay good.
avans2die (6:09:42 PM): nest we are going to write the level to the file
pixelpr0 (6:10:13 PM): why do we need ios::binary and ios::app?
avans2die (6:10:42 PM): good question, ios::binary makes that we write a binary file
avans2die (6:11:19 PM): ios::app makes that if that file alreade exsists we only append to it. i do that just incase i dont over right important data by accidenty
avans2die (6:11:23 PM): okay
avans2die (6:11:26 PM): next line
avans2die (6:11:41 PM): 
binFile.write((char*)lvl, sizeof(level));
pixelpr0 (6:11:52 PM): of, okey
avans2die (6:12:23 PM): 
that writes the entire lvl variable into the file and know that its the size of the level class
avans2die (6:12:30 PM): got that done?
pixelpr0 (6:12:59 PM): yeah... i think i understand too
avans2die (6:13:14 PM): thats good. please stop and ask me if you have any questions
avans2die (6:13:28 PM): there is no such thing as a dumb question in my book
avans2die (6:13:54 PM): okay. no that we have finished saving out level, we have to save where out player is.
pixelpr0 (6:14:04 PM): yeah... lvl is a class object right..or whatever its called... why do we convert it to a char*
pixelpr0 (6:14:06 PM): ?
avans2die (6:14:24 PM): thats also a good question
avans2die (6:15:19 PM): so (char*) is another way of just saying a byte. and when we want to write binary files we have to write it in bytes.
avans2die (6:15:23 PM): 
binFile.write((char*)p, sizeof(player));
avans2die (6:15:27 PM): thats the next line
avans2die (6:15:37 PM): tell me when you are done
pixelpr0 (6:16:00 PM): oh.. yeah, now i get it
avans2die (6:16:29 PM): oaky.
avans2die (6:16:32 PM): you done?
pixelpr0 (6:16:35 PM): yup
avans2die (6:16:49 PM): okay. now all we need to do is close out file.
avans2die (6:16:54 PM): binFile.close()
avans2die (6:16:55 PM): ;
avans2die (6:17:08 PM): done?
pixelpr0 (6:17:13 PM): yup
avans2die (6:17:24 PM): okay. now we get to test our new function.
avans2die (6:17:31 PM): go to main.cpp
pixelpr0 (6:17:38 PM): so first it writes the levele data and then the player data?
avans2die (6:17:53 PM): yes sir
pixelpr0 (6:17:59 PM): that was easier than i thought
avans2die (6:18:03 PM): haha, yup
pixelpr0 (6:18:16 PM): im in main.cpp
avans2die (6:18:18 PM): player *p = new player(100,100,30,30);
level *lvl = new level();
avans2die (6:18:27 PM): can you find those lines in your main
pixelpr0 (6:18:30 PM): yup
avans2die (6:18:34 PM): you parameters might be diferent
pixelpr0 (6:18:48 PM): now, i dont change the player color
avans2die (6:19:10 PM): okay now make a new level_Loader object just like you would a player or level object
avans2die (6:19:25 PM): level_Loader *LL = new level_Loader();
avans2die (6:19:30 PM): tell me when you are done.
pixelpr0 (6:20:14 PM): yup.. no errors
avans2die (6:20:51 PM): okay
avans2die (6:21:00 PM): now go to the end of your game loop
pixelpr0 (6:21:00 PM): i played some UGH! today and i love it
avans2die (6:21:04 PM): haha good
avans2die (6:21:07 PM): me to
pixelpr0 (6:21:23 PM): hehe... im there
avans2die (6:22:22 PM): just befor SDL_Quit();
and just after the closing bracker "}"

place this line

LL->save_Level(lvl, p, "test.lvl")
avans2die (6:23:11 PM): just change the things that you have thats different. like if you didnt call it LL but something else. and if your level ovbject is not lvl and so on.
you can also call the "test.lvl" annything you like
avans2die (6:23:18 PM): let me know when you are done
avans2die (6:23:28 PM): dont run the program yer
avans2die (6:23:30 PM): yet
pixelpr0 (6:23:51 PM): im done..
avans2die (6:24:57 PM): okay. run the program, then moce the player object some where where it doesent start. ie, just land it on a platform thats not directly below it. then exit the program. dont run it afterwards.
avans2die (6:25:09 PM): tell me when you are done.
pixelpr0 (6:25:12 PM): ok
pixelpr0 (6:25:28 PM): ive opend it in ultraedit
avans2die (6:25:29 PM): okay. go look in the exe directory if you can see your level file
avans2die (6:25:34 PM): send me the file as well
ATTENTION (6:25:42 PM): Transfer complete: test.lvl.
avans2die (6:26:16 PM): okay nice.
avans2die (6:26:30 PM): now comment out the save_Level line in main.
pixelpr0 (6:26:46 PM): ok
avans2die (6:26:58 PM): okay, no we are goint to make our load_Level function
avans2die (6:27:07 PM): and you are gonna tell me what you think we need to do
avans2die (6:27:50 PM): you there?
pixelpr0 (6:28:24 PM): yeah.. we should read in the bytes or momething
avans2die (6:28:30 PM): haha, yeah
avans2die (6:28:53 PM): okay so first we need to make a file handle
avans2die (6:28:54 PM): fstream binGet(fileName, ios::binary|ios::in);
avans2die (6:29:18 PM): binGet is just a variable name, so you can call it whatever you want to
pixelpr0 (6:29:27 PM): binFile.read((char*)lvl, sizeof(level));
pixelpr0 (6:29:41 PM): maybe
avans2die (6:29:42 PM): yes, excelent
avans2die (6:30:09 PM): also remember the order we saved it in, we need to follow that order exactly or it wont work
pixelpr0 (6:30:19 PM): yeas... 
avans2die (6:30:39 PM): okay. did you  do the reading of the player as well yet?
avans2die (6:30:49 PM): and dont forget to close the file once you are done.
avans2die (6:31:41 PM): send me the level_Load function once you are dont
avans2die (6:31:43 PM): done
avans2die (6:32:07 PM): dont run the program yet, or try to. i'll tell you exactly how it needs to be done.
pixelpr0 signed off at 6:32:07 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
avans2die (6:32:20 PM): hello
pixelpr0 signed on at 6:33:05 PM.
pixelpr0 (6:33:15 PM): it was even more easier than i thounght ...
avans2die (6:33:37 PM): dont run the program yet, or try to. i'll tell you exactly how it needs to be done.
avans2die (6:34:06 PM): or have you done it already?
pixelpr0 (6:34:19 PM): you say i should run it?
avans2die (6:34:25 PM): not yet
pixelpr0 (6:34:28 PM): ok
avans2die (6:34:50 PM): vopy and paste load_Level function so i can look over it
avans2die (6:34:53 PM): then go to main.cpp
pixelpr0 (6:35:05 PM): void level_Loader::load_Level(level* lvl, player* p, char* fileName) {
    std::fstream binGet(fileName, std::ios::in|std::ios::binary);
    binGet.read((char*)lvl, sizeof(level));
    binGet.read((char*)p, sizeof(player));
    binGet.close();
}

avans2die (6:35:15 PM): okay good.
avans2die (6:35:21 PM): are you in main.cpp
pixelpr0 (6:35:26 PM): yup
pixelpr0 (6:35:39 PM): i assum we are going to do some loading
avans2die (6:36:06 PM): yeah, but we need to declare out variables a little different
pixelpr0 (6:36:18 PM): huh?
avans2die (6:36:49 PM): comment out all the decalrations like player *p = new player. and so on. you can leave the level variable. so just comment out the player and level variable
pixelpr0 (6:37:16 PM): done
avans2die (6:37:35 PM): the declare the variables like this.
player *p = (player*)malloc(sizeof(player));
level *lvl = (level*)malloc(sizeof(level));
avans2die (6:37:51 PM): that makes space in memory for player p and level lvl
pixelpr0 (6:37:52 PM): what does malloc do?
avans2die (6:38:01 PM): memory allocation
pixelpr0 (6:38:14 PM): oke
pixelpr0 (6:38:26 PM): why are we doing this?
avans2die (6:38:58 PM): because we are going to give LL there as perameter so we have to make sure that they are declaired and have their own memory
pixelpr0 (6:39:15 PM): oh, okey
avans2die (6:39:29 PM): the other way would have worked to, but this is more professional
pixelpr0 (6:39:40 PM): coool
avans2die (6:40:07 PM): also comment out any lines where you have lvl->add_Object or anything liek that. (all the stuff that you used to set up the level)
avans2die (6:40:19 PM): tell me when you are done.
pixelpr0 (6:40:34 PM): done
avans2die (6:41:18 PM): okay. ont more line. place this line after all the declarations of your object.

LL->load_Level(lvl, p, "test.lvl");
avans2die (6:41:28 PM): and run the program and lets see if our level is there.
avans2die (6:42:19 PM): any news?
pixelpr0 (6:42:41 PM): WHAT?!??! ITS WORKOIG!
pixelpr0 (6:42:52 PM): wow... damn thats great!
avans2die (6:43:01 PM): haha, good job. and i didnt write a line of code. you did it all!
pixelpr0 (6:43:32 PM): hheh, yeah.. im a little pround but you gave me all the instructions
avans2die (6:44:25 PM): well its not different than it would have been reading out a book
avans2die (6:45:02 PM): doesent matter how good or how much i know, if you werent capable we would have not been able to do this. so congrats
ATTENTION (6:45:09 PM): Transfer complete: main.cpp.
pixelpr0 (6:45:23 PM): thanks!
pixelpr0 (6:45:35 PM): is that right?
avans2die (6:45:52 PM): just remember that evertime you save it. it append to the file. so its gets bigger.
avans2die (6:46:00 PM): you were suppose to comment that out.
pixelpr0 (6:46:18 PM): yeah i know.. the save thing
pixelpr0 (6:46:39 PM): i just tried it out and forgot to change it back
avans2die (6:46:40 PM): it will still work. but there is data in the file you are not reading. its just basically a duplicate over and over, depending on how manytimes you have run the program
avans2die (6:47:00 PM): well now you are equipt with level loading
pixelpr0 (6:47:12 PM): souldnt the game overwrite it?
avans2die (6:48:01 PM): well we uss ios::app which just appends data
pixelpr0 (6:48:24 PM): yeah
pixelpr0 (6:49:25 PM): but when i remove the comment out of the save line and runs the game and exits and  then starts over again it doesnt save
pixelpr0 (6:49:56 PM): should it do so?
avans2die (6:49:56 PM): i dont understand
avans2die (6:50:08 PM): oaky do this.
avans2die (6:50:48 PM): make the save_Level thing have "level01.lvl" as the level name parameter.
avans2die (6:50:54 PM): run the program only once.
avans2die (6:50:59 PM): tell me when you are done.
pixelpr0 (6:51:23 PM): ok
pixelpr0 (6:51:25 PM): done
avans2die (6:51:42 PM): now comment the save line out (play a "//" infront of it)
pixelpr0 (6:51:51 PM): and change the loading
pixelpr0 (6:51:55 PM): it works...
pixelpr0 (6:51:59 PM): thx
avans2die (6:52:00 PM): then go to the load_Level and change it to "level01.lvl"
avans2die (6:52:03 PM): good
pixelpr0 (6:52:19 PM): so it cant load and save in the same file?
avans2die (6:52:51 PM): no it can. but the problem is that if you load it, then save it again you are just appending it.
avans2die (6:53:11 PM): open up test.lvl and level01.lvl in ultra edit
avans2die (6:53:14 PM): look at them
avans2die (6:54:10 PM): test.lvl should just be like level01.lvl except that it has a loop in it. its like duplicated over and over (deoending on how many times you had run it)
avans2die (6:55:09 PM): you understand?
pixelpr0 (6:55:19 PM): wait...
avans2die (6:55:50 PM): yes
pixelpr0 (6:56:29 PM): yeah.. its the same until the end.. thats where it adds new bytes
avans2die (6:56:51 PM): send me both lvl files
ATTENTION (6:57:02 PM): Transfer complete: test.lvl.
ATTENTION (6:57:07 PM): Transfer complete: level01.lvl.
avans2die (6:58:07 PM): oh, the minor diferences of bytes you see in the files is the position of the player.
avans2die (6:58:48 PM): obviously you didnt exit the game having the player be at the same place. so those bytes are different
pixelpr0 (6:58:50 PM): oh, okey
pixelpr0 (7:00:11 PM): if you finds the memory adress of the playerscoordinates you can edit them in the savestate...
pixelpr0 (7:00:45 PM): thisi is a really smart way of saving&loading....
avans2die (7:02:28 PM): yes. you can. you can write another program that you can load up a level (if you knew how it was stored) and chage values and then load the level with the game and you will see those reflected values.

thats exactly how character editors work for games. like diablo had a bunch of char editors.
pixelpr0 signed off at 7:02:29 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
pixelpr0 signed on at 7:05:06 PM.
avans2die (7:05:29 PM): yes. you can. you can write another program that you can load up a level (if you knew how it was stored) and chage values and then load the level with the game and you will see those reflected values.

thats exactly how character editors work for games. like diablo had a bunch of char editors.
pixelpr0 (7:06:26 PM): oh okey.. ive made programms that changes the values of memory adresses in games
avans2die (7:06:35 PM): cool
pixelpr0 (7:06:45 PM): i got a vid on youtube
avans2die (7:06:54 PM): really. send the link
pixelpr0 (7:07:04 PM): wait then
avans2die (7:07:06 PM): k
pixelpr0 (7:07:45 PM): http://www.youtube.com/watch?v=s978shNelPQ
pixelpr0 (7:07:56 PM): kinda shitty vid but whatever
pixelpr0 (7:08:03 PM): i got alot of devvids
avans2die (7:08:11 PM): i'll check them out
pixelpr0 (7:08:33 PM): itll take like x hours
avans2die (7:09:01 PM): i only see 11 videos
pixelpr0 (7:09:15 PM): hehe, i was kiddign
avans2die (7:09:20 PM): oh
avans2die (7:09:21 PM): hehe
pixelpr0 (7:09:52 PM): dont watch the old ones... they sucks alot
avans2die (7:09:58 PM): well you look like you are very capable. keep up the good work. and always push yourself. dont doubt yourself ever.
pixelpr0 (7:11:01 PM): i dont really know... some times i  just want to die when i sees my code...
pixelpr0 (7:11:23 PM): Ii like to learn and youve been very kind and helped me
avans2die (7:13:11 PM): haha. dont worry. with time you will find a style and get into a rythem. no one just starts programming and is good at it. the people that made games like doom and what not, did not just pick up a keyboard and get it right the first time. the dedicated thousands of man hours. and i love to help, especially when the person wants to learn. so if you ever have a question please feel free to ask.
Wow! thats alot to read (but I did :) ) Nice work, you guys covered alot.
My brain hurts... :lol:
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: anyone wanna make an UGH! remake?

Post by M_D_K »

PixelP wrote:
M_D_K wrote:
avansc wrote:i thought id just post it since we had some following on the thread.

Code: Select all

  
avans2die (5:37:00 PM): hey
pixelpr0 (5:37:16 PM): hi
avans2die (5:37:52 PM): okay. yeah this will be better. i think i'll be able to help more this way. you know you can ask a question about something and get an answer quickly.
avans2die (5:38:05 PM): okay... so we are gonna make a level saver and loader.
pixelpr0 (5:38:11 PM): yeah
avans2die (5:38:29 PM): send me your level.h and your player.h over AIM
pixelpr0 (5:38:43 PM): ok...
ATTENTION (5:39:10 PM): Transfer complete: level.h.
ATTENTION (5:39:10 PM): Transfer complete: player.h.
avans2die (5:39:13 PM): today you are gonna do all the coding. and im just here for advice. so i wanna see that you have.
avans2die (5:40:21 PM): okay awesome. no out design is not the best so we are going to have to get a little creative on how we save an load our levels.
avans2die (5:40:27 PM): but everything will work out fine.
avans2die (5:40:57 PM): we are going to make a class that will handle the saving and loading. what do you think we should call out class?
pixelpr0 (5:41:03 PM): okey.. but before we start check out the forum... i made a new post
avans2die (5:41:09 PM): okay
avans2die (5:41:56 PM): sure. let me comment it for you quickly.
pixelpr0 (5:42:04 PM): thanks man
pixelpr0 (5:42:45 PM): a class name that would fit loading and saving is hard to come up with...
pixelpr0 (5:43:42 PM): mayby log or something
pixelpr0 (5:43:48 PM): record
pixelpr0 (5:44:04 PM): ?
avans2die (5:44:21 PM): how about level_Loader?
pixelpr0 (5:44:53 PM): that will work out fine... is the class for both saving and loading?
avans2die (5:45:51 PM): yeah
pixelpr0 (5:45:58 PM): ok
avans2die (5:46:07 PM): so start making the class and get back to me.
avans2die (5:46:13 PM): i'll finish up the commenting
pixelpr0 (5:46:33 PM): ok
pixelpr0 (5:48:53 PM): what functions and variables should we use?
avans2die (5:49:51 PM): void save_Level(level *lvl, player *p);
void load_Level(level *lvl, player *p);\
avans2die (5:49:59 PM): no variables
avans2die (5:50:24 PM): remember to add

#include <level.h>
#include <player.h>

in level_Loader.h
pixelpr0 (5:51:06 PM): ofcurse
avans2die (5:52:21 PM): i replied to your post.
pixelpr0 (5:53:21 PM): good
avans2die (5:53:23 PM): let me know when you want to start on the level_Save function
pixelpr0 (5:54:10 PM): right away. and thaks for comment it up... ill read it later
avans2die (5:54:18 PM): okay
avans2die (5:55:16 PM): so, what we want to do, is save the level object and the player object at a state that represents a gamestate.
avans2die (5:56:14 PM): so first we want to make the level by putting a bunch of add_object statements like we did, or use a level editor (we might do that after we get through level_saving and loading)
avans2die (5:56:26 PM): okay. so do you have a basic level setup??
avans2die (5:56:44 PM): i mean like i sent it to you last night. with the 4 walls and the 2 platforms
pixelpr0 (5:57:11 PM): yeah.. i have that level but just one platform
avans2die (5:57:14 PM): somthing like this in main.cpp
player *p = new player(100,100,30,30);
level *lvl = new level();
lvl->add_Object(0, 0, 10, 499);
lvl->add_Object(489, 0, 10, 499);
lvl->add_Object(10, 0, 479, 10);
lvl->add_Object(10, 489, 479, 10);
lvl->add_Object(10, 350, 200, 20);
lvl->add_Object(300, 200, 189, 20);
pixelpr0 (5:57:37 PM): yeah... but i got color too!
avans2die (5:57:44 PM): okay thats fine.
pixelpr0 (5:57:59 PM): player *p = new player(100,100,30,30);
level *lvl = new level();

lvl->add_Object(0, 0, 10, 499, 255, 0, 0);
lvl->add_Object(489, 0, 10, 499, 255, 0, 0);
lvl->add_Object(10, 0, 479, 10, 255, 0, 0);
lvl->add_Object(10, 489, 479, 10, 255, 0, 0);

lvl->add_Object(100, 200, 50, 30, 23, 23, 123);
avans2die (5:58:01 PM): okay. go make level_Loader.cpp
avans2die (5:58:23 PM): also make a default constructor for level_Loader()
avans2die (5:58:48 PM): so in level_Loader.cpp you will have something like

level_Loader::level_Loader()
avans2die (5:58:49 PM): {
avans2die (5:58:50 PM): }\
pixelpr0 (5:58:51 PM): ive made level_Loader.cpp
avans2die (5:59:02 PM): did you code the default constructor>?
avans2die (5:59:08 PM): its important we need it
avans2die (5:59:21 PM): not really, but the way i like doing things we do
pixelpr0 (5:59:38 PM): default constructor... i maybe know what it is but not when i see that name?
avans2die (6:00:35 PM): i just mean that in level_Loader.h
do you have a 
level_Loader(); definition

and in level_Loader.cpp
level_Loader::level_Loader()
{
}
pixelpr0 (6:01:12 PM): oh... thats the name for that?? haha... yeah i got one "default constructoir
avans2die (6:01:17 PM): okay good.
avans2die (6:01:56 PM): have you type out

void level_Loader::save_Level(level *lvl, player *p)
{
}\
pixelpr0 signed off at 6:01:56 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
avans2die (6:02:44 PM): you there?
pixelpr0 signed on at 6:03:31 PM.
avans2die (6:03:44 PM): you back?
pixelpr0 (6:03:55 PM): what?
avans2die (6:04:02 PM): AIM said you logged off
pixelpr0 (6:04:04 PM): ive ben here all the time
avans2die (6:04:08 PM): oh.
avans2die (6:04:11 PM): anywaus
avans2die (6:04:28 PM): copy and paste what you have in level_Loader.cpp
pixelpr0 (6:04:43 PM): //level_loader.cpp
#include "level_loader.h"

level_Loader::level_Loader() {
    
}

void level_Loader::save_Level(level* lvl, player* p) {
    
}

void level_Loader::load_Level(level* lvl, player* p) {
    
}

avans2die (6:04:56 PM): okay excelent.
avans2die (6:05:00 PM): now the fun starts
pixelpr0 (6:05:05 PM): !!!
avans2die (6:05:12 PM): make sure these are in level_Loader.h
avans2die (6:05:13 PM): #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
pixelpr0 (6:05:56 PM): done
avans2die (6:06:01 PM): okay
avans2die (6:06:09 PM): fstream binFile(fileName, ios::out|ios::binary|ios::app);

avans2die (6:06:32 PM): thats the first line in savelevel
avans2die (6:06:56 PM): oh shit. we need to make a 3 parameter in out load and save function
avans2die (6:06:59 PM): char *fileName
avans2die (6:07:05 PM): do you understand what i mean?
pixelpr0 (6:07:18 PM): yeah, the file name for the binary file
pixelpr0 (6:07:29 PM): i do 20 elements
avans2die (6:07:38 PM): yeah. tell me when you done with adding the marameters.
avans2die (6:08:03 PM): dont worry about how many you have, out function wont care
avans2die (6:08:08 PM): our**
pixelpr0 (6:08:33 PM): done
avans2die (6:08:54 PM): good. di you add that line to the save_Level function?
avans2die (6:09:15 PM): the fstream line
pixelpr0 (6:09:24 PM): yup
avans2die (6:09:28 PM): okay good.
avans2die (6:09:42 PM): nest we are going to write the level to the file
pixelpr0 (6:10:13 PM): why do we need ios::binary and ios::app?
avans2die (6:10:42 PM): good question, ios::binary makes that we write a binary file
avans2die (6:11:19 PM): ios::app makes that if that file alreade exsists we only append to it. i do that just incase i dont over right important data by accidenty
avans2die (6:11:23 PM): okay
avans2die (6:11:26 PM): next line
avans2die (6:11:41 PM): 
binFile.write((char*)lvl, sizeof(level));
pixelpr0 (6:11:52 PM): of, okey
avans2die (6:12:23 PM): 
that writes the entire lvl variable into the file and know that its the size of the level class
avans2die (6:12:30 PM): got that done?
pixelpr0 (6:12:59 PM): yeah... i think i understand too
avans2die (6:13:14 PM): thats good. please stop and ask me if you have any questions
avans2die (6:13:28 PM): there is no such thing as a dumb question in my book
avans2die (6:13:54 PM): okay. no that we have finished saving out level, we have to save where out player is.
pixelpr0 (6:14:04 PM): yeah... lvl is a class object right..or whatever its called... why do we convert it to a char*
pixelpr0 (6:14:06 PM): ?
avans2die (6:14:24 PM): thats also a good question
avans2die (6:15:19 PM): so (char*) is another way of just saying a byte. and when we want to write binary files we have to write it in bytes.
avans2die (6:15:23 PM): 
binFile.write((char*)p, sizeof(player));
avans2die (6:15:27 PM): thats the next line
avans2die (6:15:37 PM): tell me when you are done
pixelpr0 (6:16:00 PM): oh.. yeah, now i get it
avans2die (6:16:29 PM): oaky.
avans2die (6:16:32 PM): you done?
pixelpr0 (6:16:35 PM): yup
avans2die (6:16:49 PM): okay. now all we need to do is close out file.
avans2die (6:16:54 PM): binFile.close()
avans2die (6:16:55 PM): ;
avans2die (6:17:08 PM): done?
pixelpr0 (6:17:13 PM): yup
avans2die (6:17:24 PM): okay. now we get to test our new function.
avans2die (6:17:31 PM): go to main.cpp
pixelpr0 (6:17:38 PM): so first it writes the levele data and then the player data?
avans2die (6:17:53 PM): yes sir
pixelpr0 (6:17:59 PM): that was easier than i thought
avans2die (6:18:03 PM): haha, yup
pixelpr0 (6:18:16 PM): im in main.cpp
avans2die (6:18:18 PM): player *p = new player(100,100,30,30);
level *lvl = new level();
avans2die (6:18:27 PM): can you find those lines in your main
pixelpr0 (6:18:30 PM): yup
avans2die (6:18:34 PM): you parameters might be diferent
pixelpr0 (6:18:48 PM): now, i dont change the player color
avans2die (6:19:10 PM): okay now make a new level_Loader object just like you would a player or level object
avans2die (6:19:25 PM): level_Loader *LL = new level_Loader();
avans2die (6:19:30 PM): tell me when you are done.
pixelpr0 (6:20:14 PM): yup.. no errors
avans2die (6:20:51 PM): okay
avans2die (6:21:00 PM): now go to the end of your game loop
pixelpr0 (6:21:00 PM): i played some UGH! today and i love it
avans2die (6:21:04 PM): haha good
avans2die (6:21:07 PM): me to
pixelpr0 (6:21:23 PM): hehe... im there
avans2die (6:22:22 PM): just befor SDL_Quit();
and just after the closing bracker "}"

place this line

LL->save_Level(lvl, p, "test.lvl")
avans2die (6:23:11 PM): just change the things that you have thats different. like if you didnt call it LL but something else. and if your level ovbject is not lvl and so on.
you can also call the "test.lvl" annything you like
avans2die (6:23:18 PM): let me know when you are done
avans2die (6:23:28 PM): dont run the program yer
avans2die (6:23:30 PM): yet
pixelpr0 (6:23:51 PM): im done..
avans2die (6:24:57 PM): okay. run the program, then moce the player object some where where it doesent start. ie, just land it on a platform thats not directly below it. then exit the program. dont run it afterwards.
avans2die (6:25:09 PM): tell me when you are done.
pixelpr0 (6:25:12 PM): ok
pixelpr0 (6:25:28 PM): ive opend it in ultraedit
avans2die (6:25:29 PM): okay. go look in the exe directory if you can see your level file
avans2die (6:25:34 PM): send me the file as well
ATTENTION (6:25:42 PM): Transfer complete: test.lvl.
avans2die (6:26:16 PM): okay nice.
avans2die (6:26:30 PM): now comment out the save_Level line in main.
pixelpr0 (6:26:46 PM): ok
avans2die (6:26:58 PM): okay, no we are goint to make our load_Level function
avans2die (6:27:07 PM): and you are gonna tell me what you think we need to do
avans2die (6:27:50 PM): you there?
pixelpr0 (6:28:24 PM): yeah.. we should read in the bytes or momething
avans2die (6:28:30 PM): haha, yeah
avans2die (6:28:53 PM): okay so first we need to make a file handle
avans2die (6:28:54 PM): fstream binGet(fileName, ios::binary|ios::in);
avans2die (6:29:18 PM): binGet is just a variable name, so you can call it whatever you want to
pixelpr0 (6:29:27 PM): binFile.read((char*)lvl, sizeof(level));
pixelpr0 (6:29:41 PM): maybe
avans2die (6:29:42 PM): yes, excelent
avans2die (6:30:09 PM): also remember the order we saved it in, we need to follow that order exactly or it wont work
pixelpr0 (6:30:19 PM): yeas... 
avans2die (6:30:39 PM): okay. did you  do the reading of the player as well yet?
avans2die (6:30:49 PM): and dont forget to close the file once you are done.
avans2die (6:31:41 PM): send me the level_Load function once you are dont
avans2die (6:31:43 PM): done
avans2die (6:32:07 PM): dont run the program yet, or try to. i'll tell you exactly how it needs to be done.
pixelpr0 signed off at 6:32:07 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
avans2die (6:32:20 PM): hello
pixelpr0 signed on at 6:33:05 PM.
pixelpr0 (6:33:15 PM): it was even more easier than i thounght ...
avans2die (6:33:37 PM): dont run the program yet, or try to. i'll tell you exactly how it needs to be done.
avans2die (6:34:06 PM): or have you done it already?
pixelpr0 (6:34:19 PM): you say i should run it?
avans2die (6:34:25 PM): not yet
pixelpr0 (6:34:28 PM): ok
avans2die (6:34:50 PM): vopy and paste load_Level function so i can look over it
avans2die (6:34:53 PM): then go to main.cpp
pixelpr0 (6:35:05 PM): void level_Loader::load_Level(level* lvl, player* p, char* fileName) {
    std::fstream binGet(fileName, std::ios::in|std::ios::binary);
    binGet.read((char*)lvl, sizeof(level));
    binGet.read((char*)p, sizeof(player));
    binGet.close();
}

avans2die (6:35:15 PM): okay good.
avans2die (6:35:21 PM): are you in main.cpp
pixelpr0 (6:35:26 PM): yup
pixelpr0 (6:35:39 PM): i assum we are going to do some loading
avans2die (6:36:06 PM): yeah, but we need to declare out variables a little different
pixelpr0 (6:36:18 PM): huh?
avans2die (6:36:49 PM): comment out all the decalrations like player *p = new player. and so on. you can leave the level variable. so just comment out the player and level variable
pixelpr0 (6:37:16 PM): done
avans2die (6:37:35 PM): the declare the variables like this.
player *p = (player*)malloc(sizeof(player));
level *lvl = (level*)malloc(sizeof(level));
avans2die (6:37:51 PM): that makes space in memory for player p and level lvl
pixelpr0 (6:37:52 PM): what does malloc do?
avans2die (6:38:01 PM): memory allocation
pixelpr0 (6:38:14 PM): oke
pixelpr0 (6:38:26 PM): why are we doing this?
avans2die (6:38:58 PM): because we are going to give LL there as perameter so we have to make sure that they are declaired and have their own memory
pixelpr0 (6:39:15 PM): oh, okey
avans2die (6:39:29 PM): the other way would have worked to, but this is more professional
pixelpr0 (6:39:40 PM): coool
avans2die (6:40:07 PM): also comment out any lines where you have lvl->add_Object or anything liek that. (all the stuff that you used to set up the level)
avans2die (6:40:19 PM): tell me when you are done.
pixelpr0 (6:40:34 PM): done
avans2die (6:41:18 PM): okay. ont more line. place this line after all the declarations of your object.

LL->load_Level(lvl, p, "test.lvl");
avans2die (6:41:28 PM): and run the program and lets see if our level is there.
avans2die (6:42:19 PM): any news?
pixelpr0 (6:42:41 PM): WHAT?!??! ITS WORKOIG!
pixelpr0 (6:42:52 PM): wow... damn thats great!
avans2die (6:43:01 PM): haha, good job. and i didnt write a line of code. you did it all!
pixelpr0 (6:43:32 PM): hheh, yeah.. im a little pround but you gave me all the instructions
avans2die (6:44:25 PM): well its not different than it would have been reading out a book
avans2die (6:45:02 PM): doesent matter how good or how much i know, if you werent capable we would have not been able to do this. so congrats
ATTENTION (6:45:09 PM): Transfer complete: main.cpp.
pixelpr0 (6:45:23 PM): thanks!
pixelpr0 (6:45:35 PM): is that right?
avans2die (6:45:52 PM): just remember that evertime you save it. it append to the file. so its gets bigger.
avans2die (6:46:00 PM): you were suppose to comment that out.
pixelpr0 (6:46:18 PM): yeah i know.. the save thing
pixelpr0 (6:46:39 PM): i just tried it out and forgot to change it back
avans2die (6:46:40 PM): it will still work. but there is data in the file you are not reading. its just basically a duplicate over and over, depending on how manytimes you have run the program
avans2die (6:47:00 PM): well now you are equipt with level loading
pixelpr0 (6:47:12 PM): souldnt the game overwrite it?
avans2die (6:48:01 PM): well we uss ios::app which just appends data
pixelpr0 (6:48:24 PM): yeah
pixelpr0 (6:49:25 PM): but when i remove the comment out of the save line and runs the game and exits and  then starts over again it doesnt save
pixelpr0 (6:49:56 PM): should it do so?
avans2die (6:49:56 PM): i dont understand
avans2die (6:50:08 PM): oaky do this.
avans2die (6:50:48 PM): make the save_Level thing have "level01.lvl" as the level name parameter.
avans2die (6:50:54 PM): run the program only once.
avans2die (6:50:59 PM): tell me when you are done.
pixelpr0 (6:51:23 PM): ok
pixelpr0 (6:51:25 PM): done
avans2die (6:51:42 PM): now comment the save line out (play a "//" infront of it)
pixelpr0 (6:51:51 PM): and change the loading
pixelpr0 (6:51:55 PM): it works...
pixelpr0 (6:51:59 PM): thx
avans2die (6:52:00 PM): then go to the load_Level and change it to "level01.lvl"
avans2die (6:52:03 PM): good
pixelpr0 (6:52:19 PM): so it cant load and save in the same file?
avans2die (6:52:51 PM): no it can. but the problem is that if you load it, then save it again you are just appending it.
avans2die (6:53:11 PM): open up test.lvl and level01.lvl in ultra edit
avans2die (6:53:14 PM): look at them
avans2die (6:54:10 PM): test.lvl should just be like level01.lvl except that it has a loop in it. its like duplicated over and over (deoending on how many times you had run it)
avans2die (6:55:09 PM): you understand?
pixelpr0 (6:55:19 PM): wait...
avans2die (6:55:50 PM): yes
pixelpr0 (6:56:29 PM): yeah.. its the same until the end.. thats where it adds new bytes
avans2die (6:56:51 PM): send me both lvl files
ATTENTION (6:57:02 PM): Transfer complete: test.lvl.
ATTENTION (6:57:07 PM): Transfer complete: level01.lvl.
avans2die (6:58:07 PM): oh, the minor diferences of bytes you see in the files is the position of the player.
avans2die (6:58:48 PM): obviously you didnt exit the game having the player be at the same place. so those bytes are different
pixelpr0 (6:58:50 PM): oh, okey
pixelpr0 (7:00:11 PM): if you finds the memory adress of the playerscoordinates you can edit them in the savestate...
pixelpr0 (7:00:45 PM): thisi is a really smart way of saving&loading....
avans2die (7:02:28 PM): yes. you can. you can write another program that you can load up a level (if you knew how it was stored) and chage values and then load the level with the game and you will see those reflected values.

thats exactly how character editors work for games. like diablo had a bunch of char editors.
pixelpr0 signed off at 7:02:29 PM.
pixelpr0 is offline and will receive your IMs when signing back in.
pixelpr0 signed on at 7:05:06 PM.
avans2die (7:05:29 PM): yes. you can. you can write another program that you can load up a level (if you knew how it was stored) and chage values and then load the level with the game and you will see those reflected values.

thats exactly how character editors work for games. like diablo had a bunch of char editors.
pixelpr0 (7:06:26 PM): oh okey.. ive made programms that changes the values of memory adresses in games
avans2die (7:06:35 PM): cool
pixelpr0 (7:06:45 PM): i got a vid on youtube
avans2die (7:06:54 PM): really. send the link
pixelpr0 (7:07:04 PM): wait then
avans2die (7:07:06 PM): k
pixelpr0 (7:07:45 PM): http://www.youtube.com/watch?v=s978shNelPQ
pixelpr0 (7:07:56 PM): kinda shitty vid but whatever
pixelpr0 (7:08:03 PM): i got alot of devvids
avans2die (7:08:11 PM): i'll check them out
pixelpr0 (7:08:33 PM): itll take like x hours
avans2die (7:09:01 PM): i only see 11 videos
pixelpr0 (7:09:15 PM): hehe, i was kiddign
avans2die (7:09:20 PM): oh
avans2die (7:09:21 PM): hehe
pixelpr0 (7:09:52 PM): dont watch the old ones... they sucks alot
avans2die (7:09:58 PM): well you look like you are very capable. keep up the good work. and always push yourself. dont doubt yourself ever.
pixelpr0 (7:11:01 PM): i dont really know... some times i  just want to die when i sees my code...
pixelpr0 (7:11:23 PM): Ii like to learn and youve been very kind and helped me
avans2die (7:13:11 PM): haha. dont worry. with time you will find a style and get into a rythem. no one just starts programming and is good at it. the people that made games like doom and what not, did not just pick up a keyboard and get it right the first time. the dedicated thousands of man hours. and i love to help, especially when the person wants to learn. so if you ever have a question please feel free to ask.
Wow! thats alot to read (but I did :) ) Nice work, you guys covered alot.
My brain hurts...
:lol:
The pain goes away, soon you won't even get it :)
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
PixelP
Chaos Rift Regular
Chaos Rift Regular
Posts: 153
Joined: Tue Oct 07, 2008 12:23 pm
Programming Language of Choice: c/c++
Location: sweden
Contact:

Re: anyone wanna make an UGH! remake?

Post by PixelP »

M_D_K wrote: The pain goes away, soon you won't even get it :)
i hope so... and im dying of tiredness... *fell asleep*
Post Reply