A Taste Of RF2 Scripting

Discuss the development of Reality Factory 2
Post Reply
User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

A Taste Of RF2 Scripting

Post by AndyCR »

Well, I have begun work on the RF1-style menu system using Python. I thought I might give a taste of what RF2 scripting is like; here is the script for menu backgrounds.

Code: Select all

import rfwindow, rfobjects
import menuelement

class menubackground(menuelement.menuelement):
	def __init__(self, filename):
		self.id = 'background'
		
		self.image = rfobjects.image(filename)
		
		self.centered = rfobjects.position()
		self.centered.x = (rfwindow.getresolution().width - self.image.getsize().width)/2
		self.centered.y = (rfwindow.getresolution().height - self.image.getsize().height)/2
		
		self.image.setposition(self.centered)
		
		del self.centered
I'm going to run this by again, line by line, telling you what each line does:

Code: Select all

import rfwindow, rfobjects # Imports the RF2 built-in stuff needed by this script
import menuelement # Imports the very simple menuelement script, which this element is based off of

class menubackground(menuelement.menuelement): # Makes a new menu element, inheriting from menuelement
	def __init__(self, filename): # This method is executed whenever a new background is made, filename is a string used to identify what image to use
		self.id = 'background' # Tells the menu system that this element is a background
		
		self.image = rfobjects.image(filename) # Make a member variable of this background called 'image', and load the image from disk
		
		self.centered = rfobjects.position() # Make a new temporary position object
		self.centered.x = (rfwindow.getresolution().width - self.image.getsize().width)/2 # Calculate the x position that will center the background
		self.centered.y = (rfwindow.getresolution().height - self.image.getsize().height)/2 # Calculate the y position that will center the background
		
		self.image.setposition(self.centered) # Move the background image to the center of the screen (which we just calculated)
		
		del self.centered # Delete the temporary position object. Not needed, just tidyness
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

....And we can customize that all? Wow, it really IS flexible. :D

I can almost feel the power of customizing the whole engine for my needs. It doesn't look too hard to learn, either.
Pain is only psychological.
User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

Post by AndyCR »

Yep. :) Not even Ini files are hardcoded, the ini reader code is in python, the code that reads realityfactory.ini is in python, etc. So if you want to hardcode game startup values and forgo realityfactory.ini, go right ahead. If you want to skip realityfactory.ini and open a dialog box where options can be selected instead, go right ahead. Heck, if you want a 3d menu, its right there. The menu is treated no differently in RF2 to the game itself, so you can do anything in the menu you would do in the game - slide-in effects, scrolling credits, etc. You can even load levels into the menu, ala half-life 2.
Last edited by AndyCR on Tue Jul 04, 2006 8:32 pm, edited 1 time in total.
User avatar
steven8
Posts: 1487
Joined: Wed Aug 24, 2005 9:08 am
Location: Barberton, OH

Post by steven8 »

Andy, you and Irrlicht and Python are awesome!!
MakerOfGames
Posts: 866
Joined: Fri Jul 08, 2005 4:27 am
Location: PA, USA

Post by MakerOfGames »

Amazing!!!!:shock: Looks awesome... Keep up the great work Andy!
Think outside the box.
To go on an adventure, one must discard the comforts and safety of the known and trusted.
User avatar
steven8
Posts: 1487
Joined: Wed Aug 24, 2005 9:08 am
Location: Barberton, OH

Post by steven8 »

I tried some python scripting with the Panda Engine awhile back. I liked it very much. That is why I am so excited about the direction Andy is taking with the new RF. As Flounder said in Animal House, "This is gonna be great!!" :lol:
MakerOfGames
Posts: 866
Joined: Fri Jul 08, 2005 4:27 am
Location: PA, USA

Post by MakerOfGames »

I am dreaming up some killer menu ideas... Now I hope there will some kind of help out there to get the cool stuff like drop down menus and fully 3D backgrounds when RF2 releases.
Think outside the box.
To go on an adventure, one must discard the comforts and safety of the known and trusted.
Post Reply