Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, April 14, 2009

Playing Around With ActionScript 3

Recently inspired by a series of tutorials in AS Gamer, I spent about 3 days to put together my first flash game in action script 3. Here's the end result:



The game is quite short, but it is a complete game. It's my first time to code something in action script 3, so there were many problems that I encountered. I like to put down some notes here to serve as a future reference for myself:
  • Frame-based animation vs Time-based animation: In Flash, there are primarily two types of animation: first is the frame-based, which has a smoother result when run on different frame rates. However, its playback speed will vary depends on the frame rate. Second is the time-based animation, which has constant playback speed regardless the frame rate, but sometime it causes loss of frames if the machine cannot run on the specified frame rate.

    Usually, time-based animation will be preferred due to its unified performance. However, I couldn't fine-tune my game objects to have desired movement in a time-based manner while keeping the keyboard controlling mechanics. After some tests and trails, I decided to switch the controlling mechanics to mouse only. Also, I used the frame rate as denominator for the movement speed in a frame-based manner for the game objects. This solution worked out rather nicely. The animations look similar with either 24 fps or 60 fps. It's certainly not perfect, but hey, it works! :)

  • Central game engine: There is a Main class that serves as the entry point for the program and it is intended to act like a game engine as well. However, I didn't end up utilizing this class enough, and later when I tried to add in intro screen, game over screen, and a pause feature, it turned out to be a mess because I had to sparkle code all over different places. Then I decided to cut the pause feature because it will require a lot of changes in the other codes. I realize the same-old "big game loop" will work better than the different initialization code that I added in the constructor.

    Also, the flash library become quite crowdy when I kept adding in different movie clips. A better resource management could be implemented with the engine as well. Next time I'll try to plan ahead of what my engine should do.

  • Class inheritance: I was surprised to find out at the end that most of my game objects, which are usually movie clip subclasses, have many properties and methods to share in common. It would be nice to have a parent class or interface for all these objects. It would make the code more neat and clean.

  • Music, arts, and dedication: A lot of time was spent on making my ship look nicer or finding the appropriate sound effect for firing bullet. Then I just again realize that I'm not an artist or musician in any shape or form. I should have network more with some artists/musicians in the GDC 09. :P

    Then it's the final note: if one wants to become a game developer, making game on his/her own time is necessary. Not only it looks nicer on the portfolio or resume, but also it shows one's dedication for gaming. It doesn't really matter the quality of the game, what really matters is the lessons learned from making the game.

Monday, June 30, 2008

Handle Chinese in Python while using Pydev and Pygame

I never really try to program anything that has to deal with the Chinese before, even though I'm a 100% Chinese. However, I recently came accross a problem of renaming some of my files, which have Chinese in them. I decided to write a little script to do the task in order to practice my Python skill. Very soon I encountered the unicode problem. After some searching and hacking, I was able to solve the problem. To avoid forgetting the solution, I put down this sample program as my note for future reference.

To display the string correctly in the eclipse console, set the encoding to UTF-8 under "Run Dialog => Common". Also in the project properties, set the "Text file encoding" to UTF-8.

# -*- coding: UTF-8 -*-

import sys
import pygame
from pygame.locals import QUIT

pygame
.init()

# This string contains both simplified Chinese and traditional Chinese.
unicode_string
= u'Hello Unicode String!简体!繁體!'
# Test the string in Eclipse console.
print unicode_string

# Must use a font that is capable of displaying Chinese.
string_font
= pygame.font.SysFont('simsun&nsimsun', 16, True, False);
string_surface
= string_font.render(unicode_string, True, (0, 255, 0))

# Display the string to the pygame screen.
screen
= pygame.display.set_mode((300, 40), 0, 32)

while True:
# Missing this event handle loop will cause the pygame window freezes somehow.
for event in pygame.event.get():
if event.type == QUIT:
exit()

screen
.fill((0, 0, 0))
screen
.blit(string_surface, (10, 10))
pygame
.display.update()


Monday, March 17, 2008

Hudson - My first impression of continuous integration

Things I learned about continuous integration that I did not know before
The Hudson is running on the CSDL telemetry wall since the semester began, and I kind of grab the idea of what it is doing by looking it so often since my project requires me to look on that wall every now and then. What I didn’t notice, however, is that it not only does compile and build the project, but also runs various QA tools, such as checkstyles, PMD, findbugs, JUnit, etc. Also I didn’t know that Hudson is so automated that once you set it up, you can almost forget about it. The features that Hudson offers are far more than I expected.

Problems I had to resolve in order to get the informative workspace system to build under Hudson
I have encountered various problems while I was trying to getting my informative workspace system to work under Hudson, but the real problem that took me quite a while to figure out was to make the system deploy in tomcat by Hudson. First of all, since the system is deployed in tomcat, it requires the tomcat to be running first. And since tomcat is using the default 8080 port, I have to somehow change the port for Hudson. (Well, actually now I think about it, maybe deploying Hudson in tomcat would also solve the problem.) Anyways, what I did was putting the "--httpPort=8081" parameter. However, changing the port didn't solve my problem. I still got the error of deploying the war file into tomcat, and it is a http response 505 error. After some googling, I guessed the problem was caused by the "C:\Documents and Settings" folder, which was the default home directory for Hudson to store a local copy of the SVN files. Since the way I deploy my war file is using ant script, and ant doesn't like the spaces, it simply refused to work. After I set up a variable HUDSON_HOME and points it to a folder without space, things went very smooth. (I still haven't set the emma up, but I was thinking to exclude it from my normal build routine anyways, so I will just leave it as it is for now.)

Update: Later I tried to create a new job with space in the name and the deployment also failed. This could be the original reason for the failure in the deployment. But since ant doesn't like space anyways, I would rather to keep things simple by eliminating both the spaces in HUDSON_HOME and in the job name.

Steps Philip has to carry out in order to get the informative workspace system running using the CSDL Hudson server
Other than setting HUDSON_HOME to a folder without space (which I assume is already been done), I don't see there are any extra steps needed for getting the informative workspace system running in the CSDL Hudson server.