I use an object graphic cause I felt it's the best way. I'm trying to replicate a mode7 effect similar to the one in final fantasy 3 in SNES at the intro. With the difference that it will be playable by keyboard (you know moving ahead).
How the code works:
-It gets the viewport of the scrolling background and sets it into a dynamic sprite. Then cuts that sprite in 12 pieces (sections). Resizes pieces accordingly by an individual rate for width and height(ratew and rateh) pastes the pieces together on a dynamic sprite and sets that sprite onto an object.
The problem seems to be that ratew isn't a value independent of the number of sections. Ideally, a certain ratew value should produce the same transformation regardless of the number of sections.
parts[ad].Resize(parts[ad].Width-((sections-ad)*ratew), parts[ad].Height-((sections-ad)*rateh));
This part fails as soon as (section-ad)*ratew is greater than Width or (sections-ad)*rateh is greater than height.
The biggest value for sections-ad is right at the the start at the loop when ad is 0: sections
So in essence, this produces the error:
240/sections < sections*rateh
240 < rateh*sections²
With 12 sections, rateh is already limited to 0 and 1: 240 < 144*rateh.
Similar for the width:
320 < ratew*sections
With 12 sections, ratew mustn't be greater than 26. (26*12 = 312, 27*12 = 324)
If you increase the sections though, this limit shrinks rapidly.
The why is addressed, now how to solve this?
First of all, indent your code ;D
The } above fx.Release(); is the one from the while loop, and the one below is the one closing the function body, so object[0].Graphic=res.Graphic; ends up being outside the function. probably a C+P mistake.
To solve this, use floats for the rates and divide them by the number of sections before resizing the sprite.
Thus a specific rate produces a specific transformation and you can also adjust the rates much more precisely.
Maybe you can also learn something useful from Easy3D.
That's mode7 completely written in AGS Script:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=26130.0
Thanks, Khris, now it works, I updated the code on the first post, cleaning it up a bit. I like not to indent my code, i feel it looks prettier that way. It's just a personal preference. And I fixed the bracket issue.
Quote from: abstauber on Mon 06/06/2011 10:07:49
Maybe you can also learn something useful from Easy3D.
That's mode7 completely written in AGS Script.
I know, but I pretty much want to do this on my own, that's all. I'm a stubborn dick, what can I say?
EDIT: And here comes an issue i didn't guess. No wonder what, I can't get the image to update based on value of integer
AX. integer d is the rate in which it should increase/decrease. Weirdly enough when i change the ax on the beginning(that means on the header) it changes the image, but not in-game. I tried deleting sprites and stuff, but no go. :(
Quote from: Dualnames on Mon 06/06/2011 14:10:13I like not to indent my code, i feel it looks prettier that way.
Sorry, but that's where I draw the line.
I don't indent my code because I think it looks prettier that way (it still does though), I do it so my code isn't an unreadable mess. Did you already forget about the brackets being messed up?
Good luck.
Quote from: Khris on Tue 07/06/2011 08:03:19
Quote from: Dualnames on Mon 06/06/2011 14:10:13I like not to indent my code, i feel it looks prettier that way.
Sorry, but that's where I draw the line.
I don't indent my code because I think it looks prettier that way (it still does though), I do it so my code isn't an unreadable mess. Did you already forget about the brackets being messed up?
Good luck.
I totally fail to see the point here.
You didn't indent a single line, you just rearranged the brackets ;)
int ax, ox,fxx=25, fyy=0, fww, sections=20, d=20, ad;
DynamicSprite*scale, res, parts[];
DrawingSurface*bg, fx;
float rw=5.0, rh=1.0;
function room_Load()
{
bg=Room.GetDrawingSurfaceForBackground();
object[0].Clickable=false;
parts=new DynamicSprite[sections];
}
function room_RepExec()
{
if (ax>Room.Height-240)
{
ax=Room.Height-240;
}
while (ad!=sections)
{
int sze=(240/sections);
float ratew=rw/IntToFloat(sections);
float rateh=rh/IntToFloat(sections);
scale=DynamicSprite.CreateFromDrawingSurface(bg, 0, ax, 320, 240);
parts[ad]=scale;
parts[ad].Crop(0, (sze*ad), 320, sze);
parts[ad].Resize(parts[ad].Width-((sections-ad)*FloatToInt(ratew)), parts[ad].Height-((sections-ad)*FloatToInt(rateh)));
fx=res.GetDrawingSurface();
if (ad>0)
{
fww=(parts[ad].Width-parts[ad-1].Width)/2;
}
fx.DrawImage(fxx-fww, fyy+parts[ad].Height-1, parts[ad].Graphic);
fyy=fyy+parts[ad].Height-1;
fxx=fxx-fww;
ad++;
}
ad=0;
fx.Release();
object[0].Graphic=res.Graphic;
object[0].SetPosition(0, 240);
}
function on_key_press(int keycode)
{
if (keycode==eKeyUpArrow) ax+=d;
if (keycode==eKeyDownArrow) ax-=d;
}
I'm totally with Khris here, unindented code is way to messy to even bother with.
Quote from: Matti on Tue 07/06/2011 14:29:20
I'm totally with Khris here, unindented code is way to messy to even bother with.
I totally fail to see the point here.
EDIT:
Are you serious!?
You do see that indenting isn't just putting {}s in their own lines but actually INDENTING the lines, as in, move them to the right?
Seeing the point isn't the only thing you're failing at here I'm afraid.Thanks for indenting the code Matti :)
Dualnames:
I hope you see my point now :)
When I test this,
fx=res.GetDrawingSurface();
throws a null pointer error because res doesn't point to a DynamicSprite. That didn't happen before and isn't the problem with the code though so I won't focus on that.
One problem is that although you did turn the rates into floats, it's pointless if you use them like that.
You're setting rw to 5.0, then divide it by 20.0. So far so good.
Then you're turning the result (0.25) into an int though before multiplying it with (sections-ad); FloatToInt(0.25) is 0 though.
The first part should be:
parts[ad].Width-FloatToInt(IntToFloat(sections-ad)*ratew, eRoundNearest)
Going from float back to int is always the very last step, otherwise rounding errors accumulate or distort the result.
Dear Khris,
I believe that indentation, regardless of the fact that it is considered, by a very great percentage of people worldwide (and this community), as integral and user-friendly, when it comes to debugging and sharing the code, is the single most useless and annoying thing in the universe, next to kazoo and Friday by Rebecca Black.
However, more annoying is the fact that you so bravely fight in favor of the indentation, failing to see the forest and looking at the trees. As much as i'd like anyone's help, it's not my personal fight to force anyone to help me out against HEARTLESS conditions, such as the lack of indentation.
I look forward to your answer,
James T. Kirk.
Look, I made a compressed version. It saves space and is err.. good to be shared ???
int ax, ox,fxx=25, fyy=0, fww, sections=20, d=20, ad;DynamicSprite*scale, res, parts[];
DrawingSurface*bg, fx;float rw=5.0, rh=1.0;function room_Load(){ bg=Room.GetDrawingSurfaceForBackground();
object[0].Clickable=false; parts=new DynamicSprite[sections];}function room_RepExec(){
if (ax>Room.Height-240) {ax=Room.Height-240; } while (ad!=sections) {
int sze=(240/sections); float ratew=rw/IntToFloat(sections);
float rateh=rh/IntToFloat(sections); scale=DynamicSprite.CreateFromDrawingSurface(bg, 0, ax, 320, 240);
parts[ad]=scale; parts[ad].Crop(0, (sze*ad), 320, sze);
parts[ad].Resize(parts[ad].Width-(sections-ad)*FloatToInt(ratew)), parts[ad].Height-((sections-ad)*FloatToInt(rateh)));
fx=res.GetDrawingSurface(); if (ad>0){fww=(parts[ad].Width-parts[ad-1].Width)/2;}
fx.DrawImage(fxx-fww, fyy+parts[ad].Height-1, parts[ad].Graphic);
fyy=fyy+parts[ad].Height-1;fxx=fxx-fww;ad++;} ad=0;
fx.Release(); object[0].Graphic=res.Graphic; object[0].SetPosition(0, 240);}function on_key_press(int keycode)
{if (keycode==eKeyUpArrow) ax+=d;if (keycode==eKeyDownArrow) ax-=d;}
I'm sorry that this didn't help at all, but
Quotewhen it comes to debugging and sharing the code, is the single most useless and annoying thing in the universe,
equals
QuoteThe world's a disc
@abstauber: AMAZING point.
"single most useless and annoying thing" ???
It's quite the opposite, cause the one reading the code has to either indent it himself or go through it and count/compare all the brackets which is quite annoying. Also, not indenting the code generally makes it quite error prone which has been the case here (in the tech forums) countless times. I understand that you're used to not indenting code and may have trouble changing that, but I don't at all get why you don't see its great advantage.
In your case the indentation was easy, otherwise I wouldn't have bothered..
Btw, you know that instead of
if (ad>0)
{
fww=(parts[ad].Width-parts[ad-1].Width)/2;
}
you can just write
if (ad>0) fww=(parts[ad].Width-parts[ad-1].Width)/2;
Makes things even shorter and more readable ;)
It's not just indenting, also putting spaces around operators, putting brackets on new lines and choosing a programming style and then sticking to it. I simple refuse to read code that isn't properly indented, for some people I make exceptions, then I will first indent their code and then read it. But seriously, the compiler doesn't give a rats arse about indentation (not talking about python) or comments, but humans do.
itsforthesamereasonwhywedonttypelikethisbecauseitmakesitallnotveryreadableeventhoughitmightsafesomespaceey
But you are special Dualsie :-*
If someone actively refuses to indent their code properly, I will simply refuse to read it, or help them with any problem they might have. So good luck with your problem, hope you figure it out for yourself.
Dualnames:
I couldn't care less about what you think of the usefulness of indentation.
You want help with your code, and after I politely mentioned that you should indent your code - not just because I think it's useful but because you actually screwed up the placement of the brackets which proper indentation helps prevent - you keep being an ass about it even though other people chimed in how it's common courtesy not to dump messy code here when asking for help.
The irony is that you call indentation the "single most useless and annoying thing" when that's precisely what best describes the attitude you're displaying here.
So again, good luck.
Sorry, I can't get it to work. I created a sample project and pasted Matti's version of your code in it. But it crashes as this line, as soon as I hit a key:
scale=DynamicSprite.CreateFromDrawingSurface(bg, 0,ax, 320, 240);
This is because ax can have a negative value by pressing down and the drawing surface immediately gets out of bounds.
It's a bummer that you've edited your posts, so that I can't access a working version.
Quote from: Snarky on Tue 07/06/2011 16:04:11
If someone actively refuses to indent their code properly, I will simply refuse to read it, or help them with any problem they might have. So good luck with your problem, hope you figure it out for yourself.
Let me quote myself.
QuoteAs much as i'd like anyone's help, it's not my personal fight to force anyone to help me out against HEARTLESS conditions, such as the lack of indentation.
Unless you're some kind of genius Rainman who can identify exactly what's in between each of your ninja braces. Or you're relying heavily on Ctrl+B to point out where the closing brace is, or just simply counting every brace until you find where you want to insert your code. I couldn't program like that. It's unbelievably time consuming and, as everyone keeps saying, Very prone to errors. It has nothing to do with 'looking pretty', it's simply just to make it organized and easier on you and anyone else who looks at your code.
I have a hard enough time finding the closing brace on my indented lines when there's tons of lines of code. I'd hate to imagine programming in your style. Seriously. We're not trying to convert you to the darkside or something.
When I first started programming back in grade 9, I never used indentation either. I refused to use it. I thought the teacher was trying to teach us some stupid method to waste time. But a couple years later, once I started using it, I found my code unbelievably clear and easy to read and now laugh at people like you (who used to be like me) who think it's a waste of time.
But no, seriously. Stick with your style if it really makes you happy spending all that time counting your braces and putting the code between the wrong ones and having to cut and paste several times. :P
Dualnames, please fuck the fuck off. Proper indentation is crucial for writing clear and readable code. Your brain is broked.
lol at dualnames, seriously.
You're all being ridiculously unhelpful. Dualnames raises a very valid point. Indentation, like any type of spacing in code other than between identifiers and keywords, is completely pointless. Here's a corrected version of the code for you Dual:
int ax,ox,fxx=25,fyy=0,fww,sections=20,d=20,ad;DynamicSprite*scale,res,parts[];DrawingSurface*bg,fx;float rw=5.0,rh=1.0;function room_Load(){bg=Room.GetDrawingSurfaceForBackground();object[0].Clickable=false;parts=new DynamicSprite[sections];}function room_RepExec(){if(ax>Room.Height-240){ax=Room.Height-240;}while(ad!=sections){int sze=(240/sections);float ratew=rw/IntToFloat(sections);float rateh=rh/IntToFloat(sections);scale=DynamicSprite.CreateFromDrawingSurface(bg,0,ax,320,240);parts[ad]=scale;parts[
ad].Crop(0,(sze*ad),320,sze);parts[ad].Resize(parts[ad].Width-((sections-ad)*FloatToInt(ratew)),parts[ad].Height-((sections-ad)*FloatToInt(rateh)));fx=res.GetDrawingSurface();if(ad>0){fww=(parts[ad].Width-parts[ad-1].Width)/2;}fx.DrawImage(fxx-fww,fyy+parts[ad].Height-1,parts[ad].Graphic);fyy=fyy+parts[ad].Height-1;fxx=fxx-fww;ad++;}ad=0;fx.Release();object[0].Graphic=res.Graphic;object[0].SetPosition(0,240);}function on_key_press(int keycode){if(keycode==eKeyUpArrow)ax+=d;if(keycode==eKeyDownArrow)
ax-=d;}
Unfortunately stupid AGS makes you have lines only 500 characters long so I had to split it to three lines for it to compile, but this is the prettiest code ever, and anybody who disagrees is a douchebag faggot who can screw off and die. Keep up the amazing work Dualnames.
You know, what really pisses me off is when people have a script that only has like less than 200 characters but spans across like 150 lines!! WTF?!? KEEP YOUR CODE CLEAN PEOPLE! KEEP IT ALL ON ONE LINE WITH NO SPACES UNLESS NECESSARY!!!
LOL, don't listen to monkey!!!111
I maded you the prettiestest code:
int
ax
,
ox
,
fxx
=
25
,
fyy
=
0
,
fww
,
sections
=
20
,
d
=
20
,
ad
;
DynamicSprite
*
scale
,
res
,
parts[
]
;
DrawingSurface
*
bg
,
fx
;
float
rw
=
5.0
,
rh
=
1.0
;
function
room_Load
(
)
{
bg
=
Room.GetDrawingSurfaceForBackground
(
)
;
object[
0
].Clickable
=
false
;
parts
=
new
DynamicSprite[
sections
]
;
}
function
room_RepExec
(
)
{
res
=
DynamicSprite.Create
(
320
,
240
)
;
if
(
ax
>
Room.Height
-
240
)
ax
=
Room.Height
-
240
;
while
(
ad
!=
sections
)
{
int
sze
=
(
240
/
sections
)
;
float
ratew
=
rw
/
IntToFloat(
sections
)
;
float
rateh
=
rh
/
IntToFloat(
sections
);
scale
=
DynamicSprite.CreateFromDrawingSurface
(
bg
,
0
,
ax
,
320
,
240
)
;
parts[
ad
]
=
scale;
parts[
ad
].Crop
(
0
,
(
sze
*
ad
)
,
320
,
sze
);
parts[
ad
].Resize
(
parts[
ad
].Width
-
(
(
sections
-
ad
)
*
FloatToInt
(
ratew
)
)
,
parts[
ad
].Height
-
(
(
sections
-
ad
)
*
FloatToInt
(
rateh
)
)
)
;
fx
=
res.GetDrawingSurface
(
)
;
if
(
ad
>
0
)
fww
=
(
parts[
ad
].Width
-
parts[
ad
-
1
].Width
)
/
2
;
fx.DrawImage
(
fxx
-
fww
,
fyy
+
parts[
ad
].Height
-
1
,
parts[
ad
].Graphic
)
;
fyy
=
fyy
+
parts[
ad
].Height
-
1
;
fxx
=
fxx
-
fww
;
ad++
;
}
ad
=
0
;
fx.Release
(
)
;
object[
0
].Graphic
=
res.Graphic
;
object[
0
].SetPosition
(
0
,
240
)
;
}
void
on_key_press
(
eKeyCode
keycode
)
{
if
(
keycode
==
eKeyUpArrow
)
ax
+=
d
;
if
(
keycode
==
eKeyDownArrow
)
ax
-=
d
;
}
You fucking maniacs! You've killed the forum formatting! I'm typing this in a message box that's half-way across the fucking screen!
I hate you all!
...
What's indentation, and why should I care?
Slightly less seriously (*gasp*), Dual, I'm sure you're aware, but I want to point something out regarding indentation. In AGScript, as with most programming languages, whitespace is completely ignored by the compiler/interpreter, except as a delimiter between keywords and/or data types and the identifier associated with the variable/function being declared, defined, or referenced. Beyond that, AGS doesn't give a leprechaun's left testicle about how much or little whitespace you choose to put in your scripts.
So why then do we do these horribly infuriating things like indentation? Because we, as humans, tend to think a bit differently than machines do. There's an entirely separate point to take into consideration here than just indentation, which is the brace/bracket depth of any given line of code. By that I mean how deeply nested within a function and any conditions or loops that a given statement may be.
For example, a global variable within a script is declared outside of any functions, conditions, or loops, so we could say that the following has a brace depth of 0 (zero):
int ax;
A variable that is local to a function could be said to have 1 or more as the brace depth, depending on the contents of the function:
function on_key_press(eKeyCode keycode)
{ // open brace, first level
int var = 5; // brace depth: 1
if (keycode == 65)
{ // open brace, second level
int i = 0; // brace depth: 2
while (i < var)
{ // open brace, third level
i++; // brace depth: 3
} // close brace, third level
Display("%d", i); // brace depth: 2
} // close brace, second level
else Display("Pressed key %d (%c).", keycode, keycode); // brace depth: 1
} // close brace, first level
As you can see, in this "properly" indented example, the indentation level directly correlates to the brace depth. This means that the end-user can, at-a-glance, almost immediately tell the brace depth of any given command/statement. We've already gone over the fact that AGS doesn't care about this indentation one way or the other, but it's a tool you can use to help yourself, and others, more quickly determine how deeply nested a certain line of code is.
The alternative (or, one of many) would be to use something probably between my post and Khris'. There are many indentation styles that work the same as my code here, but the ultimate key is consistency. As long as your indentation within a single function is consistent, then the purpose can be maintained. However, if you opt out of using indentation whatsoever, then you lose these described benefits.
Unless you have some massive, dynamically updated table that tells you the brace depth for every given line, then I don't see how else you're even reading and writing your own code. Short of manually counting from the beginning of each function every time you need to edit or try and debug your code..which you have to recognize is less efficient than something that allows an at-a-glance approach to the same thing.
So, in short, do what's best by you, but if you're remotely serious about a request for help in these or any programming-related forums, please just understand that indentation could quite well be the deciding factor whether you get the help you need. ;)
Should we care about whether Dualnames wants our help or not at this point? {
I don't think so.
But if you do, {
remember that he hasn't earned it yet.
Humoring him encourages his obnoxious behavior.
}
If you don't, {
I'm with you.
}
}
We don't need to explain to him why indentation is beneficial, it's obvious.
>:( STOP humiliating each other for their habits on formating. This is OT for this topic and pointless. I'll consider locking this or deleting posts if this continues.
@Khris: your code doesn't work too for exactly the same error I'm experiencing. I can't believe that I've reformatted that code block :=
@Duals: Look at this thread. Steve's code is pretty close to what you're trying to achieve.
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=42122.0
I wonder which is more ridiculous, really.
My refusal to indent the code, or your inability to get out of this topic and bother with something else.
Even more ridiculous is Snarky's comment. For a number of reasons.
I apologize for being a brain-dead idiot and asking for help. You're not required to tell me how much i should indent my code and why.
If you can't read the code, I apologize, don't help me. There's absolutely no need for retarded jokes.
Again, you've all proved how awesome you are. Thanks for all the great help, my problem is solved.