Author Topic: My physics game  (Read 23018 times)

0 Members and 2 Guests are viewing this topic.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
My physics game
« on: February 01, 2011, 02:10:23 pm »
I am currently making a physics game using some of the techniques in this thread http://ourl.ca/4279 I am writing it in python because it is the only language I know well enough to do something like this in. I have a few questions about some things so any help would be appreciated. right now I just finished my skeleton code and am starting on the game engine. I am currently using pygame for graphics, I also have python 2.6.2

My first Question is how could I code Cellular Automata in python for a large/full screen?
« Last Edit: February 01, 2011, 03:10:48 pm by ruler501 »
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline leafy

  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1554
  • Rating: +475/-97
  • Seizon senryakuuuu!
    • View Profile
    • keff.me
Re: My physics game
« Reply #1 on: February 01, 2011, 03:08:36 pm »
What graphical package are you planning on using with python?
In-progress: Graviter (...)

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: My physics game
« Reply #2 on: February 01, 2011, 03:09:44 pm »
I'm using pygame for graphics. I don't really know any of the other ones

EDIT: if it matters I'm using python 2.6.2
« Last Edit: February 01, 2011, 03:11:12 pm by ruler501 »
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: My physics game
« Reply #3 on: February 01, 2011, 03:35:12 pm »
Do you have any screenshots?

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: My physics game
« Reply #4 on: February 01, 2011, 03:36:27 pm »
I'm using pygame for graphics. I don't really know any of the other ones

EDIT: if it matters I'm using python 2.6.2
The following code will do pixel placement:
Code: [Select]
screen.set_at((x, y), (red, green, blue))
Similarly, you can get a pixel's color too:
Code: [Select]
thecolor = screen.get_at((0,0))
The var screen is defined as:
Code: [Select]
screen = pygame.display.set_mode((width, height))
Pixels values range from 0 to either height - 1, or width - 1. (Like TI-Basic and Axe! :D)

I'm hoping that you are very fluent in Pygame and the physics concept, because it's a must! ;)
I got those snips from http://www.ida.liu.se/~ETE257/timetable/LecturePythonPygame.html and http://lorenzod8n.wordpress.com/2007/12/16/pygame-tutorial-5-pixels/, so you can read over the mini tutorials there if needed. :)
« Last Edit: February 01, 2011, 03:38:10 pm by alberthrocks »
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: My physics game
« Reply #5 on: February 01, 2011, 03:37:30 pm »
Are your questions about how to make the graphics full screen?  How to actually code the cellular automata?  How to store the data?

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: My physics game
« Reply #6 on: February 01, 2011, 03:42:16 pm »
I wanted to know how to do the cellular automata. I also need to be able to do good collision detection and gravity.
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: My physics game
« Reply #7 on: February 01, 2011, 03:44:03 pm »
I wanted to know how to do the cellular automata. I also need to be able to do good collision detection and gravity.
First off - have you made the concept on your calculator, and does it work?
Second, are you well versed with Python and Pygame?
Third, can we see some sample code? :)
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: My physics game
« Reply #8 on: February 01, 2011, 03:46:28 pm »
The physics lessons go over how to control the cellular automata quite thoroughly, do you mean the actual concept behind them or the code?

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: My physics game
« Reply #9 on: February 01, 2011, 03:51:14 pm »
I wanted to know how to do the cellular automata. I also need to be able to do good collision detection and gravity.
First off - have you made the concept on your calculator, and does it work?
Second, are you well versed with Python and Pygame?
Third, can we see some sample code? :)

I don't get the first one This is a comp program
I'm well versed with python and have done all right with pygame
I'm still making up the code, but if you want to see some code I'll post it later.

@Builderboy I want to know how to optimize that code and some of the concept
« Last Edit: February 01, 2011, 03:52:51 pm by ruler501 »
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: My physics game
« Reply #10 on: February 01, 2011, 03:57:24 pm »
I wanted to know how to do the cellular automata. I also need to be able to do good collision detection and gravity.
First off - have you made the concept on your calculator, and does it work?
Second, are you well versed with Python and Pygame?
Third, can we see some sample code? :)

I don't get the first one This is a comp program
I'm well versed with python and have done all right with pygame
I'm still making up the code, but if you want to see some code I'll post it later.

@Builderboy I want to know how to optimize that code and some of the concept

What you want to do is a computer program, but you should immerse yourself with a calculator implementation to really get how it works, then try attempting it in Pygame. ;)
I will try sometime this week (if not today) to implement a simple example (much like BuilderBoy's screenshot) in Pygame. :)

I'd still like to see some code to make sure you're on the right track.
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: My physics game
« Reply #11 on: February 01, 2011, 04:06:11 pm »
My only calculator is a Nspire so i can't do much on calc testing.
I have not done much with my code yet right now I only have a background. As soon as I start doing much with it I will post my code.
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: My physics game
« Reply #12 on: February 01, 2011, 04:28:46 pm »
Implementing cellular automata is not too hard.  You will want to start with two arrays.  These arrays will hold the pixels that represent your element you want to simulate, like water.  They will both have the length of the ammount of pixels you want to simulate, and one will hold the X value of a pixel, while the other array will hold the Y value for the pixels.  After that, you will want to loop through the array, applying your physics to each pixel as you go along.  Remember, physics is as simple as a set of rules like I explained in the other thread :)

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: My physics game
« Reply #13 on: February 01, 2011, 04:54:18 pm »
Could i have an example of some python code for that please. I'm trying to figure out a way to optimize this it would be slow i think if i have to go through most pixels in a nearly if not full screen game.

The only reason i might not do full screen is because i want this to be a very fast game that won't glitch up. i think it would be easier if i had a slightly smaller screen size.
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline alberthrocks

  • Moderator
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 876
  • Rating: +103/-10
    • View Profile
Re: My physics game
« Reply #14 on: February 01, 2011, 06:18:30 pm »
Implementing cellular automata is not too hard.  You will want to start with two arrays.  These arrays will hold the pixels that represent your element you want to simulate, like water.  They will both have the length of the ammount of pixels you want to simulate, and one will hold the X value of a pixel, while the other array will hold the Y value for the pixels.  After that, you will want to loop through the array, applying your physics to each pixel as you go along.  Remember, physics is as simple as a set of rules like I explained in the other thread :)
Hehe, I had the same thought! :D I didn't read the tutorial at all - just stared at words briefly and found a nice screenshot. ;)
I thought about how you would do it - did you do pixel testing? No, since the water itself is "black". The next idea was an array of pixel colors, but that didn't make any sense either. Finally, 2 different arrays to compare "water pixels" with "obstacle pixels" was my final planned implementation idea... which turned out to be your implementation method too! :)

Were you thinking multidimensional arrays:
Code: [Select]
[0, 1, 2,
 3, 4, 5
 6, 7, 8]
...or just regular arrays?
Code: [Select]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
Could i have an example of some python code for that please. I'm trying to figure out a way to optimize this it would be slow i think if i have to go through most pixels in a nearly if not full screen game.

The only reason i might not do full screen is because i want this to be a very fast game that won't glitch up. i think it would be easier if i had a slightly smaller screen size.
I said above that I will try myself in getting that implemented. ;)
Python is pretty powerful at array management. I'm not too sure myself how to attack this, but it might be using a multidimensional array.
This can be done with below:
Code: [Select]
a = [[v]*n for x in xrange(n)]...where v is an int for an initial value, first n is the width, last n is the height.

Accessing the values (and of course, assigning them) is even simpler! :D Simply:
Code: [Select]
a[y][x] = 1
print a[y][x]

I still don't believe you are that well versed in Python.... otherwise you would've known about numpy and numarray! :D
Those are both true multidimensional array handlers, and can probably be better (and faster?) than the method described above.
NumPy and numarray are out of my scope of knowledge though... and so I'll redirect you to the official manual/tutorial:
http://www.scipy.org/Tentative_NumPy_Tutorial

If you search "Multi-dimensional arrays: However, numarray does support true multi-dimensinoal arrays" on the page below, there is another perspective on numarray/numpy:
http://www.astro.ufl.edu/~warner/prog/python.html

Hope this helps! :D
Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/


Proud member of ClrHome!

Miss my old signature? Here it is!
Spoiler For Signature:
Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! :( Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. :)

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler For "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it :P)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it :P)
wxWabbitemu: 40% done (NEED MOAR FEATURES :P)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming :P)