Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 27 28 [29] 30 31 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 817512 times)

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #420 on: January 12, 2012, 04:07:22 pm »

That's Project #3, you'll have to wait for it.

No, just to forestall anything stupid, I'm actually going to gear it towards a roguelike-ish interpretation of Super Mario Bros 2.  Why?  Because it was my favorite, it had a really cool design style, and more than anything, years ago when I made DIY plug-in games, I would recreate Shyguys for placeholder enemies.  I really like them for some reason.


Ok I'll bite...
Project 2?

EDIT:
Holy fuck! So before I had an inheritance hierarchy for my tiles, seemed like a fun idea at the time, but new understanding of scope and what would be the most possible implementation lead me to scrap this in favour of a flat structure. I mean I'm not updating the tiles any more, so why not!


Spoiler (click to show/hide)

God a mother fucking 50% improvement on performance... That is with a map of 1,000 by 1,000 by 5. Hell yes!

EDIT 2: Oh wait, turns out I had FPS capped at 125 for some reason. Having removed that, turns out I'm in the 160's...
Level gen is slower, but at this stage I would say well within an acceptable level.

EDIT 3: So... Running the exe in the bin folder is yielding speeds hitting the 200 fps mark. Mother fucking fps Christmas over here. Took all of five minutes to implement, and made my day. Imma gonna go reward myself with a cup of tea!

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #421 on: January 12, 2012, 05:15:17 pm »

And all that being said, I'm writing a new MapTile class right now, which will save me loads of work and headache and duplication of effort in the future, and then I'll make a RoomObject class.  This shouldn't take more than a hour or two of grunt work.

Okay, the MapTile rewrite took an hour, but even that was with distractions.  It was definitely good to do it now, before I had to hunt through a billion lines of code for every related operation.  I've got a pretty good idea for how to implement Rooms as Objects, but I have this feeling its going to take me the rest of the afternoon, and I still won't get started on the corridor drawing until tomorrow.

And this is the point where I realize the last eleven days of my life have been totally consumed by programming.  I have so much crap I'm supposed to be doing right now.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #422 on: January 12, 2012, 05:30:01 pm »

What is this is?

I am programmer. I have brain hurt today. But I would really love to code something fun and silly.

Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #423 on: January 12, 2012, 05:37:04 pm »

Okay, so I'm doing a Perl tutorial now, as if we didn't have enough going on here already. Whatever. Let's go!

First some background information:
You know what, I'll just show you how Perl works and you imagine what it can be used for. Only thing I'll say: Perl is used much more than you hear of.

How to get a Perl interpreter:
If you're running Windows, go to http://www.perl.org/get.html and download one of the provided Perl distributions for Windows (I recommend ActivePerl). Install.
If not, you already have Perl.

How to create a Perl program:
Open your favourite plain text editor and write some Perl code. Save as YOUR_PROGRAM_NAME_HERE.

How to run a Perl program:
Open a shell, navigate to your program and enter "perl YOUR_PROGRAM_NAME_HERE". Hit the large generally non-convex key normally to be found on the right of your keyboard. Lean back and have fun.
If you have Windows, you may run programs whose names end with .pl just by double-clicking them, but the window that appears will vanish as soon as Perl exits, either after successfully running or after finding syntax errors. In that case, you won't get to see the syntax error messages.
If you don't have Windows, you should be competent enough to find other ways of running your programs on your own.
Spoiler: Hint: (click to show/hide)

How to be able to write programs in Perl:
Simple, just read on!

Now, most people would start a programming tutorial with a simple example program like a Hello World!.
We'll start even simpler, because I can.
Code: [Select]
# This is a comment.This program, when executed, successfully does nothing at all. Comments start with a # and end at the end of the line.

Did you see that program? Did you remember what it looked like? Yes? Well, that's good, because you won't see another program example in a looong time.
The reason: Every time I learn a language using a quick start guide, I am able to use the language up to the points covered in the quick start guide, and then nothing. So we'll start very slowly. Before you can read and write, you need to learn the alphabet.

So we'll start by looking at some basic data values, called scalars.

First, numbers. I'll just pile all possible forms of numbers on you, and you'll understand.
Code: [Select]
3 # An integer, exactly what it looks like.
42 # A different integer.
-5 # A negative integer.
3.7 # A floating-point number.
-3.9 # A negative floating-point number.
0b10010 # 18 in binary (starts with 0b).
0100 # 64 in octal (starts with 0).
0x1f # 31 in hexadecimal (starts with 0x).
1234567890 # A large integer.
1_23_456_7890   # Same as above. You can put underscores anywhere you like.
0x49_96_02_D2 # Same as above. Non-decimal representations can also have underscores.
1.36e29 # A very large floating-point number.
13.6E28 # Same as above. The E can be uppercase.
-13.42e-34 # A very small negative number.
I won't tell you how Perl internally handles numeric values. But don't worry, they always do exactly what you want them to do.

Second, strings. Yes, strings are a basic data value. Never underestimate Perl again.
There are insanely many different types of string literals. Remember: Perl was designed as a language to handle large amounts of data efficiently and easily. Oh, I didn't tell you that yet. But now you know.

I'll start with the most basic type: the single-quoted string literals. The contents of such a string are exactly what they look like, with two necessary exceptions:
Code: [Select]
'Urist' # A string consisting of five characters: U, r, i, s and t.
'MAGMA' # Those five characters.
'' # An empty string. Guess how many characters it has.
'Hello\n' # Hello followed by a backslash followed by a n.
'abc\'xyz' # If you want a single-quoted string literal to contain single quotes,
# just use a backslash to stop Perl from thinking that the string literal is already over.
'wtf\\' # If you want a single-quoted string literal to end with a backslash, then typing only one backslash
# isn't a good idea, as Perl will think you wanted it to stop thinking that the string literal is already over.
# So just backslash the backslash.
'\'\\' # Therefore, the contents of this string are a single quote followed by a backslash.
That's all there is to them.

Now we'll move on to double-quoted string literals. Watch:
Code: [Select]
"Urist" # A string consisting of five characters: U, r, i, s and t. Same as with single quotes.
"" # Also an empty string.
"Hello\n" # Hello followed by a newline. Backslash-character combinations have special meanings here.
"foo\tbar" # foo, a tab, and bar.
"\"\\" # A double quote followed by a backslash.
"\x41" # An ASCII value in hexadecimal (here: a capital A).
There is much more to these double quotes, which will all come later. And remember the insanely many different types of string literals? Those will probably also have to wait.

There are two more scalar value types: references and undef. Have patience, they will be covered.

Now, let's talk operators! There are much more, here are the basic algebra and string operators.

Numeric operators:
Code: [Select]
3 + 4 # Addition: 7
4 - 1 # Subtraction: 3
3 * 6 # Multiplication: 18
6 / 2 # Division: 2
10 / 3 # 3.33333333..., there is no integer division.
3 ** 4 # Exponentiation: 81
26 % 7 # Modulus: 5
26.1 % 7.8 # Still 5. Modulus only supports integers. Non-integers are rounded down.
'3' * "4" # 12
"0.5" * " 6foo" # 3

String operators:
Code: [Select]
"abc" . "def" # Concatenation: "abcdef".
"abc" . 'def' # Same as above: "abcdef".
'Hello world' . "\n" # "Hello world\n".
"foo" x 4 # String repetition: "foofoofoofoo"
5 x 4 # 5555
4 x 5 # 44444

Did you notice the last two examples in each code block? Yes, that's correct: Perl will automatically convert numbers to strings and back, depending on how they need to be used. Yeah, that's awesome. Numbers are converted to strings canonically, and strings are converted to numbers by cutting off leading whitespace and trailing non-digits and interpreting what's left. Perl does a really good job of reading your mind.

Next time: Scalar variables and example programs!
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #424 on: January 12, 2012, 05:49:28 pm »

I've got a pretty good idea for how to implement Rooms as Objects, but I have this feeling its going to take me the rest of the afternoon, and I still won't get started on the corridor drawing until tomorrow.

If you want you can borrow some of my boiler plate code and fit it to your needs. You might want to do it yourself for the experience, but this is pretty standard stuff, so take it or leave it.

Spoiler (click to show/hide)

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #425 on: January 12, 2012, 06:01:48 pm »

...this is pretty standard stuff...

Clearly I have a lot to learn about what qualifies as boilerplate in this business.  Get{}? Virtual? Protected? Return !(...)?  Competency is still a long way off for me.  I didn't even know you could put more than two qualifiers in a parenthesis.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #426 on: January 12, 2012, 06:18:39 pm »

I'm curious as to what get{} does as well.  Sounds like some c# voodoo!  :D

The virtual and the protected stuff you can pretty much ignore for now.  Protected is for people who like to not make a mess of their code (whereas I love making a mess) and virtual is for some fancy class inheritance stuff that you probably don't care to much about yet.  :)
« Last Edit: January 12, 2012, 06:20:44 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #427 on: January 12, 2012, 06:22:05 pm »

Ok, umm... Shit. What you are looking at must seem like pretty much magic, but I will do my best to explain some of the things here, but that class was built to be extended, so unless I explain all of inheritance, it might be a bit tricky, but still I will do what I can.

get{}: This is something c# does that is really cool. But, sort of tricky to explain. Basically I declared a method without use of (), and when other things look at it, they see an attribute. All in all, it works exactly the same as if I had used the following instead.
Code: [Select]
        public virtual int GetTop()
        {
            return x;
        }

*Virtual: This changes almost nothing. Seriously, it will work the same with or without this keyword. This is so that later on, other classes are allowed to replace this method with their own. It basically means it is polite enough to step aside should something else want to take its place.
*Protected: Almost the exact same thing as private, but this means that other sort of rooms can also see it, but nothing else.
Return!(...): This is three things put together, and that is why it looks sort of alien. The long way to write it would be...
Code: [Select]
        public virtual bool Intercepts(Room r)
        {
            if (this.Right < r.Left || this.Left > r.Right || this.Top > r.Bottom || this.Bottom < r.Top)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
But anyway.
The first bit is just a return, you know how that works, right? Well the next bit is '!', that explanation mark means 'not' or 'the opposite of what ever comes right after me', so !true means 'not' true, and there for false. As you can imagine, it only works for things that are true/false.
The next bit inside the brackets is exactly the same thing you use when ever you use a loop or an if, but it has || included. This means 'or', so you can have (condition or otherCondition) and it would be expressed as (condition || otherCondition). Similar to this is the 'and' operator, and that is pretty much the same, but used && instead.

*These things relate to inheritance. Would you like a full lesson on that? It can be useful.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #428 on: January 12, 2012, 06:24:04 pm »

I'm curious as to what get does as well.  Sounds like some c# voodoo!  :D

If it is c#, and there isn't anything there that isn't c#, then get is used to define the getter method for a property of an object.


in java you might access a rooms top like so: room.getTop()
in c# you can do: room.Top
and still be able to avoid exposing the objects member variables.

Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #429 on: January 12, 2012, 06:26:51 pm »

Return!(...): This is three things put together, and that is why it looks sort of alien. The long way to write it would be...
Code: [Select]
        public virtual bool Intercepts(Room r)
        {
            if (this.Right < r.Left || this.Left > r.Right || this.Top > r.Bottom || this.Bottom < r.Top)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
But anyway.
The first bit is just a return, you know how that works, right? Well the next bit is '!', that explanation mark means 'not' or 'the opposite of what ever comes right after me', so !true means 'not' true, and there for false. As you can imagine, it only works for things that are true/false.
The next bit inside the brackets is exactly the same thing you use when ever you use a loop or an if, but it has || included. This means 'or', so you can have (condition or otherCondition) and it would be expressed as (condition || otherCondition). Similar to this is the 'and' operator, and that is pretty much the same, but used && instead.

*These things relate to inheritance. Would you like a full lesson on that? It can be useful.
Not to rain on your parrade, but !(!a || !b || !c || !d) == a && b && c && d, so by inverting your comparison operators you could make that line somewhat more readable.
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #430 on: January 12, 2012, 06:27:33 pm »

I see, neat!
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #431 on: January 12, 2012, 06:29:57 pm »

Not to rain on your parrade, but !(!a || !b || !c || !d) == a && b && c && d, so by inverting your comparison operators you could make that line somewhat more readable.
Well... Shit.
I was sitting down with a pencil and paper trying to figure out the easiest way to make sure I covered all overlap, and decided it was just easier to make sure they don't overlap in all four directions, then do the opposite... So I programmed that.  :P
Well I can change that now.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #432 on: January 12, 2012, 06:31:48 pm »

Not to rain on your parrade, but !(!a || !b || !c || !d) == a && b && c && d, so by inverting your comparison operators you could make that line somewhat more readable.
Well... Shit.
I was sitting down with a pencil and paper trying to figure out the easiest way to make sure I covered all overlap, and decided it was just easier to make sure they don't overlap in all four directions, then do the opposite... So I programmed that.  :P
Well I can change that now.
It's just De Morgan's theory, you can always switch from AND to OR by liberal application of NOT.
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #433 on: January 12, 2012, 06:33:03 pm »

The first bit is just a return, you know how that works, right? Well the next bit is '!', that explanation mark means 'not' or 'the opposite of what ever comes right after me', so !true means 'not' true, and there for false. As you can imagine, it only works for things that are true/false.
The next bit inside the brackets is exactly the same thing you use when ever you use a loop or an if, but it has || included. This means 'or', so you can have (condition or otherCondition) and it would be expressed as (condition || otherCondition). Similar to this is the 'and' operator, and that is pretty much the same, but used && instead.

*These things relate to inheritance. Would you like a full lesson on that? It can be useful.

Yeah, I figured that was what's going on after looking at it.  Every conditional is ultimately a boolean anyway, and I know how the program interprets "yes" as "true" automatically.  I just didn't know you could pack that much stuff into one statement.

The Get{} I don't really see the point of, when it does the exact same thing as a normal method, but I'm sure there's some larger system where it makes perfect sense.  The Virtuals and Protecteds I might start using myself in this case.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #434 on: January 12, 2012, 06:35:43 pm »

The trick behind Get{} is that you can have two attributes where one of the attributes is derived from the other. This means that if we define B as a getter that returns A+1, then changing A will also change b. Of course you could use a function for the same purpose, but then you would have a different syntax for two components that may conceptually be the same. The one implementing your class should not have to know what variables are derived variables and need to be accessed via a function.
Logged
Pages: 1 ... 27 28 [29] 30 31 ... 795