Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: runeazn on February 25, 2012, 10:24:00 am

Title: How do you make games with coding???
Post by: runeazn on February 25, 2012, 10:24:00 am
I still dont get how you can make games with coding after getting a little taste of coding language python :P
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 10:27:03 am
Basically, what most games do is repeat one or more loops to get everything done (with routines and stuff).

btw you better make your questions more closed. (like "how do i code feature x as seen in game y")
Title: Re: How do you make games with coding???
Post by: runeazn on February 25, 2012, 10:28:09 am
how the heck can a loop show something?
ok itll loop the draw comment everytime.

but ho wdoes it pickup if lets say a picture bumps onto another picture, and this results into a movement of the other picture?
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 10:31:15 am
In a modern programming language, you have a display routine that draws stuff to the screen. (for example called void draw{ } ). This routine is called every frame.
Title: Re: How do you make games with coding???
Post by: runeazn on February 25, 2012, 10:32:00 am
display routine?
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 10:37:35 am
Yeah, its a routine that does display stuff. Like displaying pictures or text.
Title: Re: How do you make games with coding???
Post by: runeazn on February 25, 2012, 10:39:35 am
but how does it detect that a pictures collides with another picture and that the other picture needs to move.

lets say, user, bumps against a box and box needs to move.

what i think you do:
 do you code that if that picture is within this area of this picture than this will happen?

is this true?
and whats maa more efficient way to do this?
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 10:41:42 am
It does not. It's got coordinates of both things and checks if they are close enough if so, move the box.
Title: Re: How do you make games with coding???
Post by: runeazn on February 25, 2012, 10:45:45 am
aha ok,
how do you store the said "picture"

in a variable?


and how can it read the said picture? I dont think it cant read jpg or something can it?
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 10:50:15 am
All modern programming languages can read jpg. (png is used more)
And they "store" those pictures by telling the program that "this file is a picture"
Title: Re: How do you make games with coding???
Post by: runeazn on February 25, 2012, 10:56:38 am
so it calls a img everytime ok.

how does it get continuously the "keys" of movement?

all i have worked up till now is the input command but it will wait till something is inputted and after that it would continue.
This would be no plausible solution to use right?
how do we do it now?
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 11:01:16 am
Programs take keycodes. Every key on a keyboard has a different signal. The program reads the signal every loop and just continues when there's no key pressed.
Title: Re: How do you make games with coding???
Post by: BlakPilar on February 25, 2012, 11:07:43 am
All games come down to the basic game life cycle. I recommend watching this video (http://create.msdn.com/en-US/education/tutorial/2dgame/design). Though it's for XNA (.NET) and not Python, it gives a pretty detailed overview and explanation of the life cycle.
Title: Re: How do you make games with coding???
Post by: runeazn on February 25, 2012, 11:22:56 am
lets say pong, how do you let the ball move from direction?

or better said how do you move a object without user input.
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 11:25:04 am
Do (ballpos)+1->ballpos every loop.
Title: Re: How do you make games with coding???
Post by: BlakPilar on February 25, 2012, 11:29:51 am
Did you watch the video? To do what you asked, you would just update everything that needs to be updated when your update method is called. Here's some pseudocode to demonstrate what I mean:

update:
    move ball based on travelling direction
    if ball collides with wall or paddle
        method to make ball bounce off of surface
    if ball has passed some paddle
        add point to winner
        reset ball location
    if user presses a key we will use (i.e. Up, Down, W or S)
        update player's paddle location
    update AI
draw:
    clear background
    draw scores
    draw walls
    draw ball

Basically after each draw method is done, the update method will be called, and when each update method is done the draw method will be called.
Title: Re: How do you make games with coding???
Post by: runeazn on February 25, 2012, 11:29:53 am
thats no explanation D:
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 11:32:16 am
Do you know what you should do? get a 84+ and learn programming in BASIC and then in Axe. I'm not rude, but that REALLY helps A LOT. In fact, w/o my 84 i would never have been programming stuffs.
Title: Re: How do you make games with coding???
Post by: Munchor on February 25, 2012, 11:33:22 am
OP, if you don't have much experience, I don't recommend you to try out coding games just yet. However, in the near future, try pygame, it's great for making games with Python. I don't recommend C# or XNA because it's not cross-platform :)
Title: Re: How do you make games with coding???
Post by: Spyro543 on February 25, 2012, 11:36:13 am
If you're doing pong, you're going to want four variables for the ball: x, y, x velocity, and y velocity. To start the ball going to the lower right, we'd set the x vel. and y vel. both to 1. Then we'd increase x by x vel. and y by y vel. each loop iteration to make the ball move. To flip the direction of movement do
velocity variable *= -1
Title: Re: How do you make games with coding???
Post by: runeazn on February 25, 2012, 11:47:48 am
how do you make the bal move?
yes let it draw every frame but how do we let it add the x and y coordinates?

as the spot where the ball hits the uhh stick it will decide the movement the ball will make.
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 11:49:11 am
You define more variables. Just like 1->x and stuff. ITS EASY BRO.
Look up a python tutorial for dummys.
Title: Re: How do you make games with coding???
Post by: BlakPilar on February 25, 2012, 11:58:29 am
I'm going to go with aeTIos on this and say read a Python tutorial. A lot of games do basic math and updating, which are covered in tutorials.
Title: Re: How do you make games with coding???
Post by: aeTIos on February 25, 2012, 12:00:54 pm
My experience:
90% of programming is saying "calculate x+24c+6-f*2(55y)" and stuff. Not a joke.
Title: Re: How do you make games with coding???
Post by: AngelFish on February 25, 2012, 12:00:59 pm
I still dont get how you can make games with coding after getting a little taste of coding language python :P

Eck, this question sure is vague...

A nice analogy might be "I still don't understand how they predict the weather after using an iPhone app." :P

Here's a high level overview of how games work though:

Title: Re: How do you make games with coding???
Post by: BlakPilar on February 25, 2012, 12:03:33 pm
My experience:
90% of programming is saying "calculate x+24c+6-f*2(55y)" and stuff. Not a joke.

Yes games also have a lot of complex math, but even games like Crysis have simple math in them.

I still dont get how you can make games with coding after getting a little taste of coding language python :P

Eck, this question sure is vague...

A nice analogy might be "I still don't understand how they predict the weather after using an iPhone app." :P

^ This. One does not simply know all the programming after a "little taste."
Title: Re: How do you make games with coding???
Post by: AngelFish on February 25, 2012, 12:32:43 pm
Games like Crysis are largely an exercise in "How simple can we make the code to do this?" I've used some of the published algorithms from games including Crysis before and it's amazing just how simple some of the things are. In crysis II, for example, a lot of the stuff they use are best described as hacks. Were you a bit disappointed when you saw that Deep Thought's fruit ninja used a bunch of static sprites to make the fruit "rotate?" Turns out, that's what Crysis does for some of its plant shading. Complete rubbish as far as true realism goes, but who can argue with the results? Being able to simplify things tremendously like that is part of the Art of Game Programming. It's also a very advanced topic in places :P

EDIT: I love Deep Thought's way of rotating the fruit, if it's not clear. Great job, Hal!
Title: Re: How do you make games with coding???
Post by: BlakPilar on February 25, 2012, 12:46:40 pm
Personally I wasn't surprised when I saw it. That's exactly the way I would've done something like that. In fact, it is the way I do things. For animations I just use a bunch of sprites and loop them together based on the game's time. Plus I'd imagine that's the fastest way to do that kind of thing, especially with shading and in large games like Crysis. I always love finding out how things that seem complex are actually really simple. It all comes down to whether or not you're over-thinking something or not.
Title: Re: How do you make games with coding???
Post by: Spyro543 on February 25, 2012, 01:40:52 pm
I know quite a bit of Python already: all of the basic built-in functions, how to do GUIs, and how to connect to the internet with it. However, I still don't have enough knowledge to make a decent game. It takes quite a lot of programming knowledge to make good graphical games.
Title: Re: How do you make games with coding???
Post by: epic7 on February 25, 2012, 01:41:59 pm
The program enters what is referred to as a "big honkin' loop." This loop is where the entire game happens.
Lol, people call it the big honkin' loop? :P
Title: Re: How do you make games with coding???
Post by: runeazn on February 25, 2012, 02:11:33 pm
little taste as completed one tutorial on python :) http://www.khanacademy.org/
the tutorial wasnt long though, i followed the tutorial on khan academy
, and now i am following the tutorial called "LearnPythonTheHardway" on http://learnpythonthehardway.org haha
any other good tutorials?
Title: Re: How do you make games with coding???
Post by: lkj on February 25, 2012, 02:24:30 pm
I'm learning Python with this tutorial (http://www.swaroopch.com/notes/Python).
Title: Re: How do you make games with coding???
Post by: LincolnB on February 25, 2012, 09:27:16 pm
Not sure if it's been mentioned yet but IMO the best way to display graphics using Python is Pygame (pygame.org) and the best way to package and distribute is as a .EXE file is Py2exe (py2exe.org)
Title: Re: How do you make games with coding???
Post by: Link on August 29, 2012, 02:29:40 pm
Basically games are made up with a main loop. What happens is this:

1. Game starts
2. All the windows are set up and so on.
3. You enter the main game loop
4. The loop continually does the following:
   a. Get input, and process it
   b. All game logic (i.e. move sprites, updates positions, and checks collisions.)
   c. Update the screen
   d. Goto [a].
5. Thats it :)

Here is some Pseudo-code of the main loop.
Code: [Select]

while(running){
while(SDL_PollEvent(&Event)) // Get key-presses and process them
currentState->Event(&Event);
currentState->Loop(); // Check gamelogic
currentState->Render(); // Update screen
}
Title: Re: How do you make games with coding???
Post by: Munchor on August 29, 2012, 03:00:57 pm
Basically games are made up with a main loop. What happens is this:

1. Game starts
2. All the windows are set up and so on.
3. You enter the main game loop
4. The loop continually does the following:
   a. Get input, and process it
   b. All game logic (i.e. move sprites, updates positions, and checks collisions.)
   c. Update the screen
   d. Goto [a].
5. Thats it :)

Here is some Pseudo-code of the main loop.
Code: [Select]

while(running){
while(SDL_PollEvent(&Event)) // Get key-presses and process them
currentState->Event(&Event);
currentState->Loop(); // Check gamelogic
currentState->Render(); // Update screen
}

What a necropost, nice!
Title: Re: How do you make games with coding???
Post by: ruler501 on August 29, 2012, 05:36:58 pm
and isnt that C/++ code...

But good summary of how making games works
Title: Re: How do you make games with coding???
Post by: Link on August 29, 2012, 07:54:38 pm
Thanks, and yes it's C++ code from my project, but for all purposes it's Pseudocode, as long it illustrates the concept.
Title: Re: Re: How do you make games with coding???
Post by: Scipi on August 30, 2012, 08:23:25 pm
Something I've always found with games, is that you can split them into three main parts. Input, processing, output.

For something like having a picture collide with another, you'd do as what was said earlier and store the coordinate data and use them during processing. You'd store the picture in an object and you'd use a reference to that object, basically variables. What that object is depends on the library you use or a class you write yourself.


Edit: Using tapatalk, didn't realize this was an old thread :P My apologies.