quarta-feira, 19 de agosto de 2009

Introduction to cocos2d

In preparation for the pyweek I'm studying about the cocos2d library. cocos2d is a high-level framework that is good for game development since it provides good abstractions like Scenes, Layers, Sprites and Scene transitions. It gives you some default classes like ColorLayer and TiledLayer (rectangular and hexagonal) and a very good set of samples, but enough talking. I'll show how to initialize the library, create a sprite on the screen and control it with the arrow keys (it allows diagonal movements too :)
First install the cocos2d library (pre-requisites:pyglet 1.1.2 and python setuptools). Just go to the respective pages and follow the instructions. They are pretty clear, but if you need any help don't hesitate to ask.
Lets begin importing all the necessary stuff.

from cocos.director import *
from cocos.scene import *
from cocos.layer import *
from cocos.sprite import *

The director is the singleton class of cocos that controls the flow of your aplication. It can run scenes and change between them (among other tasks). Scenes are different parts of the game and layers are drawable parts of the screen that can be pilled up to form the visuals of the application. A simple example: a game could have 4 scenes (the menu, win, game over and the game itself) and each level could be a layer of the game scene. In our example we will have only one scene with one layer.
So we will create a ColorLayer, a type of layer that has a color background.

class TutorialLayer (ColorLayer):
def __init__(self):
super(TutorialLayer, self).__init__(0, 0, 100, 255)

Now we will instruct the director initialize and run a Scene object. Since there's only one scene in our application and it does not have any logic in it, we won't create a subclass of it, we will simply intanciate a new Scene and add our custom layer to it.

director.init()
director.run(Scene(TutorialLayer()))

Now run this code. You should see a 640x480 blue screen. We will ad now a sprite (a simple image that can do actions live move, rotate, etc) to it. Add this line in the __init__ method of the TutorialLayer (image here):

self.ship = Sprite('ship.png', position=(320,240))
self.add(self.ship)

If you run it you should see a ship in the center of the screen. Now were going to handle key events to finish our example. First we will let cocos know that our layer wants to receive events. To do this just add the following line below the class declaration:
is_event_handler = True
Now that we can receive events, we need to create a listener to the key press and key release functions and a character set to store wich characters are pressed. The event listener for the key press event is defined by the on_key_press(self, key, modifiers) function. The modifiers parameter shows if any modifier key like control or alt is pressed. A similar event is defined for the release of a key. First we will initialize our character pool in the constructor using

self.chars_pressed = set()

Then we add the on_key_press and on_key_release methods:

def on_key_press(self, key, modifiers):
self.chars_pressed.add(key)

def on_key_release(self, key, modifiers):
self.chars_pressed.remove(key)

What we do here is keep track of the currently pressed keys by storing them on a set. Now we just check if the keys are in our set in every frame. To do this we will schedule a function to be called every frame.

self.schedule(self.update)

And we will define the following constants:

LEFT = 65361
UP = 65362
RIGHT = 65363
DOWN = 65364

Now the the update method:

def update(self, dt):
x, y = self.ship.position
if LEFT in self.chars_pressed:
x -= 2
if UP in self.chars_pressed:
y += 2
if RIGHT in self.chars_pressed:
x += 2
if DOWN in self.chars_pressed:
y -= 2
self.ship.position = (x, y)

Notice that the (0,0) point of the screen is the left-bottom one. Now test the program and verify that the ship really moves in every direction, including diagonals. The complete file can be found here.
That's my introduction to cocos2d :) I hope you liked it. See you next time!

quarta-feira, 12 de agosto de 2009

Pyweek 9

Hi!
Do you want to make a game and have one week available? If your answer is YES why don't you enter in the next Pyweek?

The Pyweek is a contest that challenges you to write a game (in Python) from scratch in one week. It is intended to be fun and to drive innovation from game developers. It will be my first time in the contest and I'm really hoping to finish it with something that's fun to play. I'll be using the cocos2d library and I'll post more about it when the competition is nearer. If you have the time and will to make a game happen in one week then join me at 00:00 UTC 2009-08-30 :)

See you there!

segunda-feira, 10 de agosto de 2009

My first completed deal in FGL

Today I completed my first deal in FGL: a primary sponsorship with playtowerdefensegames. Everything went smoothly and I'm really looking forward to make more flash games. Also, I began to work in my new game, but I'm not telling what it's about... yet. I'll post my experiences and achievements in this blog for everyone to know what I'm working into. Also, I'll post some videos of the gameplay once it's close to the real thing :) I hope I'll get more attention to my games this way.

segunda-feira, 3 de agosto de 2009

News and more FGL

Hi!
I'm happy to say that I got a second offer on my game on FlashGameLicense! Now I have a bigger offer and I will explain the Buy It Now and Last Call options of FGL (the things that got me the new bid)

Buy It Now:

This options appears only to more experienced developers OR to games that are waiting for a sponsorhip for some time. It allows you to set a fixed price to your game in a Primary Sponsor that allows Ads and don't have gameplay changes. This way the sponsor can simply buy your game with your price on it, but you have to accept any deals from Buy it Now. This is why this option is dangerous: you can underprice your game and there's no auction system to let anyone give you a higher bid! Use with caution

Last Call:

When you're about to close a deal you should activate the Last Call option. This makes sponsors aware that you are going to sell the game and attracts last minute sponsorships. Your game will have a mark saying that is on Last Call. That means: "If you want to bid, do it NOW!". I think it's always a good idea to activate this option, since my bigger offer came after I did it.

That's it. Later in this week I'll post my delicious bookmarks about flash games development and resources for games. See ya.

quinta-feira, 30 de julho de 2009

What is Flash Game License?

Have ever wondered how those big games like Sony and Desktop Tower Defense actually earn something? They probably sold a license or got sponsored by a big game portal and this is where Flash Game License comes in.

Flash Game License (FGL) is a website that sells licenses and sponsorships to various game portals all over the web. The idea behind it is that the developer puts his game on their site to get a license on the game. The selling process is like an auction: every interested sponsor leaves a bid in the game with a value and the type of the license/sponsorship. The developer chooses what bid to accept and when. Great games get bids for thousands, while smaller games get the attention of the smaller portals. The fee to the site is that if you got a deal from them you should pay a commission of 10%. IMHO it's fair, since you probably wouldn't get much from Ads and self-sponsoring.

There are three types of licenses avaiable:
Exclusive sponsorship
The sponsor gets the right to distribute a branded version of your game everywhere and this version must be the only one on the net. Tend to pay a more, but you won't earn anything from this game anymore, since most sponsors don't allow ads on this.

Primary sponsorship
The sponsor will distribute a branded version of your game all around the web, but it will not be site locked. You will be able to sell site locked versions of your game, although the game must remain exclusive on the Primary sponsor' site for some time.

Non-Exclusive sponsorship

The sponsor will get a site locked version of your game with their branding and APIs. You can sell many licenses of this type as long as you don't sell an Exclusive.

Besides being a good way to monetize Flash Games, FGL also has a great community. You can post about everything on its forums and get game feedback from developers. There are some experienced guys that can give very good tips. There are forums to find people to work with too! Overall, it's a pretty good environment and I recommend to anyone who's willing to develop some good flash games.

That's it. Thanks for the audience :p

quarta-feira, 29 de julho de 2009

Introduction and News

Hi!
I'm igordsm, a newbie hobby game developer. In this blog I'll post updates about the games that I'm starting to develop and some other related projects that come into my mind. The name MontaGames is a joke with my last name and is intended to be used as a brand for my games and other related projects, no matter if they're open source or have the code locked down with seven keys :p

Right now I'm happy because my first game got a bid on FlashGameLicense (I'll post about it later). Although the bid is low, it's my first! When I get the link to the released version I'll post it here.

I'll go to sleep now. See ya!