Client Tech 4

Posted by Leroy on Jul 2, 2010 in Client Technologies 4 |

Ct4 Assignment 1

Going into the first assignment, I still wasn’t happy with learning flash actionscript, my personal feeling regarding it weren’t very positive. However, when we started the lectures it became clear that adobe had made some major changes to accommodate more traditional programmers with ActionScript 3, and this turned out to be a good thing for me.

Going through the week one tutorial was actually rather nice. I felt immediately at home with actionscript3 due to it’s similarities with javascript, so working on assignment one was more or less a pleasant surprise!

One thing I wondered, though, was if Actionscript had pointers or not, and the short answer was “sort of”.

In this first week we learned how to set up a class file association with the flash project file, and have it use that as what we know as the “main” in C++, I then found that the C++-like programming style could further be used by using the onEnterFrame eventlistener and attaching it to a method of the main class instance; effectively acting as a main loop.

The whole event thing was way beyond me, though, and I’ll need to pay close attention when it’s finally explained in the working class.

Another thing that I’m wondering about is.. Since a lot of things are being instantiated with new, do these also need to be removed? It would seem to me that they are allocated dynamically, and thus, would need to be deleted after use.

Making frugal walk for the extended exercise was a breeze. I simply populated an array with cos and sin values, generating a nice arc for frugal to follow while jumping. Nice and simple.

Result

FlowChart

Click for larger view

Click for larger view

Ct4 Assignment 2

The second week, I started off with a more positive attitude due to the experience with the first one. We worked on creating a particle system of sorts, with the main document class generating and killing bees, which would then move from one spot to another using a motion tween, which seemed handy, but I’d rather write myself (C++ programmer mentality?)

I found the design patterns to be extremely familiar, which seems to be a recurring theme that I’ve come across ever since I signed up for A&T.

I was also happy to not be forced to re-use last weeks work, as I’ve had rather bad experiences with that in IGAD where you can’t follow the lecture because you had a problem in last weeks’ code and this weeks’ builds on top of that.

Other things I’ve been messing with this week were alpha, scale, and dynamically creating a textfield on each bee so you’d be able to see their names. As it turns out, you can simply new a TextField object and set some properties. The only thing to note is that you’ll also need to create a TextFormat object and set it’s properties in order to be able to set the TextField’s text style, which seems a bit weird to me. Finally, to assign the style to the field, you simply assign your TextFormat Object to the TextField’s .defaultTextFormat attribute.

One thing I found particularly.. Unprofessional.. Let’s put it like that, was the use of named array elements. This makes iteration through the array cumbersome if you don’t have access to it’s contents names, on top of the fact that the Array implementation in ECMAscript is anything but safe and optimized. Rather the opposite; it adds attributes to a generic object and let’s you grab those using the [ n ] format, according to my research on the subject.

result



Get Adobe Flash player


flowchart

Click for larger view
Click for larger view

Ct4 assignment 3

Just when I thought we weren’t going to re-use previous assignments, the 3rd assignment popped it’s head around the corner. I wasn’t amused by this stunt, to say the least.

Anyhow, for assignment 3, we were going to message the bees, make them grow old, get sick, and die completely using the eventlistener, and eventdispatchers. This was different for me than the other assignments, because following ken’s assignment didn’t give me working eventlisteners for some reason. The listeners were registered, which you can check by calling the hasEventListener method on any subclass of Sprite. The method to be called, however, refused to co-operate with me, and it wasn’t until the exam week where I had some one-on-one time with ken, when we were finally able to find out what was going wrong, and the concept of eventlisteners and dispatchers became clear to me.

Using the eventlisteners, the bees were eventually able to message requests to the environment for their removal, as they were ready to die from illness.

Assignment 3 was rather short, which cut me some slack. How nice!

result

flowchart

result  flowchart

result flowchart

Ct4 assignment 4

With the 4th assignment, I think ken set out to poke fun at me, once again building on top of the previous assignment, like we did last week. Fortunately, everything I needed for this week’s work did function in last weeks’ assignment, so I was able to get busy with the work  relatively quickly.

Moving forward from assignment 3, we’re off doing evil, creating a killer bee that actually eats the nice and the sick bees (really, it just eats anything it comes across). Talking code, this means checking collision between the evil bee and the others, mirroring it’s sprite, and  removing the bees from the stage.

New bees are also generated at random intervals, so if you stick around for a while, you’ll have the entire screen absolutely packed with bees; easy targets for lots of points.

I decided to go all out with assignment 4, and actually create a game as suggested in the extended exercise. What I added was a textfield with modified text style (using TextField and TextFormat), which would display the number of bees eaten. This information would always be displayed below the killer bee, as you moved him around using the mouse.

I also added a timer, in order to create an arcade-style game, using the Timer object, and set it to fire a method of the main document class at regular intervals and count down the time using that. The objective of the game is to eat as many bees as possible within 15 seconds.

result

flowchart

result  flowchart

result flowchart

Ct4 final assignment

Once I got to the final assignment, I felt I had a pretty good understanding of basic Actionscript 3, and I was actually able to create the entire game in one evening; after creating assignment 4 on the very same day. I started out thinking about structures; what kind of data to I need to store for my game to be able to function? A pickup class and a SnakeSegment class were created, and a document “Main” class also joined the ranks shortly after. In the Pickup and SnakeSegment classes, which I made by extending the MovieClip class, I create the visuals in the constructor.

I then thought about my approach for the snake’s trail, and decided to create 2 Arrays; one which would hold the snake’s tail, and one which would hold the trail of the snake’s head. I would then only need to put the tail on the trail, and keep inserting new snake segments into the tail when it would need to grow in length, and push a new head trail in the trail array every time the head moved. I then shift (instead of pop) the first element of the array out of the trail, using the first-in-first-out model, whereas the snake’s tail simply uses a first-in-last-out model, because it doesn’t matter in which order the snake’s segments are in the array.

Using this system, I was able to create the snake with it’s trailing body succesfully. I did, however need to create something that would allow me to pass the snake’s x and y variables to the trail (which I named path) for storage, and so another class was born: Position. Position was a simple container class, but turned out to be a great thing to use, and I had absolutely no trouble getting everything to work.

Lastly, I used a timer with an eventlistener attached to regulate the game’s speed, and attached a listener to KeyboardEvents for my game’s controls.

The score is calculated when the snake does a hitTestObject collisioncheck with the item pickup, after which the pickup is simply relocated, not destroyed, and points are added to the score.

Custom fonts are also used in this game, and after some research online, I found an easy way to implement them; add them to the flash library and instantiate an object of it’s linkage classname, and subsequently assigning it’s fontName to the TextField’s (TextFormat) .font property and setting the fontEmbed to true, after which it just seemed to work!

Video

Result

Flowchart

ct4-flowchart-final

Click for larger view

Tags: , , ,

Comments are closed.

Copyright © 2010   Art & Technology   @ NHTV All rights reserved. Theme by Laptop Geek.