tirsdag 16. november 2010

Case 6

The enemy.




Finally it’s case 6, the last case this autumn. This case was about making an enemy in my game. The enemy was supposed to be made in its own class, have an animation and behave individually no matter what the player is doing. But when the character hits the enemy, something should happen. 

I started this case with the part I knew I could do: the animations. I decided I’d have a squirrel as the enemy because it’s not a natural enemy of a fox, and they’re mostly thought of as cute, but they’re rather cool animals who won’t stand down from a fight if something is in their way. So I thought it could be funny.

 Of course, it did not turn out the way I intended and it looks awfully off, but I figured that as long as it moved I’d be happy. I decided to make it move in a pattern that made it possible for the player to move the character past the enemy when the enemy was somewhere else. Basically I made it possible to win the game. 

Making that happen and fitting it in my game was not much of a problem. Neither was the HitTest part when the character hit the enemy. But of course it can never be that easy. We were told that it was just needed a few sentences in the enemy class to make it work, but I couldn’t seem to make it work. When I showed up Friday to get some answers we were suddenly told that we could use a class that our teacher had made. That was fine by me, but it wouldn’t teach me anything.

 I looked through the class to see if I could understand what’ve been done. But as the idiot at scripting I am, it might as well have been a plan for making an airplane. I didn’t get anything from looking at the class, so I decided that “it’s just the way it is”. But it made me think that I’ll eventually fail at this subject.

After I settled down with my failure, it was to the part of making it actually work. After changing the name in our new class and adding a few functions (move,turn) it could walk, in theory. Of course, things weren’t just going to be easy now, so it decide to spin back and forth on the spot instead of moving. I changed some values here and there and then the squirrel moved nicely left…finally. But then it also had to stop and turn. The teacher showed us a way to make it walk to the edge of the scene before it turned around and walk to the other edge and turn again. All was functioning nicely. If I only had a game that worked that way.

 My scene “moves” so that the character has a bigger areal to move in. Basically it’s the environment that moves and not the character, but it looks like the character is moving though the environment. This made it harder because I couldn’t have the squirrel moving back and forth between the edges, because then it’d never leave the scene. Luckily for me, I still had a clear memory of HitTest and If-sentences. I figured that if I made objects in the scene, like two green balls matching the ground and making them invisible, that I’d make move forward with the environment, it’d work. Sort of.

I made my two green balls on the ground, pretty far out in the environment, and had them moved in as my character walked. I made them with a red outline so that I’d see where they were. When they were moving as they should, I added my squirrel. Of course it started spinning again once it hit the green ball, but a little fixing with some values randomly around my script finally made it look less…utterly stupid. I’ll add a little screenshot of what my little invention looked like.

After my squirrel was moving happily around in the scenery, I made a hitTest of what would happen if the character should hit the squirrel. I decided to make the squirrel a Sprite and added a onHit animation, or rather a picture. I also added a blank frame in the characters Sprite that I’d activate once it hit the squirrel, so that it’d disappear. 

I also removed all Listeners to make everything freeze once the hit. All of this I put into my If/hitTest-sentence. I actually like If-sentences because I think it makes sense. If something happens then { something else happens }. 

One thing I was not so happy about was that I can’t get my RemoveChild to work, it only gives me loads of errors and ruins everything. So I used a lot of Alpha all over the place. Both to make things disappear and appear, like points and text, but it still feels a bit like cheating although we’ve not learned how to do it differently. I hope it won’t be a big deal in the end. 

All in all I’m satisfied with how this case turned out. But I’m still quite disappointed that our teacher doesn’t teach us what we need to know in order to complete the task, and instead gives us a script that I at least have no idea of how actually work, I just know that it does. I thought it’d be interesting to learn scripting, and I think it would’ve been if we were taught differently, but right now I’m just happy to be done with it for now. I wouldn’t have been able to complete these cases if it hadn’t been for good classmates and some helpful advice at the lab. I hope things will be different in spring, when things get harder. Right now I’m feeling like I have to learn a new language and I’ve been given a short text in order to write a novel, without knowing half of the words I have to use. It’s really frustrating and I hope that things will change for the better. Mostly because I think scripting could be really interesting and actually fun! Sometimes when I did these cases I found that I enjoyed it and wanted to know how things worked. Sometimes I’d sit down and try to do things that we weren’t told to do, just for fun, but because I do not know the words I can’t write the sentence. Even if I know what I’d need. I actually made my character jump without help, but it only jumped while I pressed the button so it was quite annoying. Still I made the jump and I made the character move while it jumped and I made it pick up points while it jumped. Just to see if it could work the way I thought it would. But I removed all of it, because it wasn’t good enough or part of a case.  I’ve decided to not make any more of this subject than I have to. Just be done with it. It has taken most of my time when I’ve done my homework, and I’ve decided not to let it anymore.

Click to enlarge pictures.



tirsdag 9. november 2010

Case 5


 Activating animations and hitting the ground

In this case it’s still all about the scripting. This time I’m going to trigger specific animations of my character at the right place. I also have to make points for the character to pick up, I have to make it stay on the ground and I had to place some of my objects with the aid of an entirely new class.

After I was done with my previous blog, but had not been given the next case I tried to work with flipping my character. After I had asked my classmates and looked over what they’d done I realized that the only thing I had done wrong previously was that I hadn’t put a block around the scaleX part. Although annoyed with how scripts work, I was happy with making the character flip before we got the next case, only to be disappointed that I didn’t need it. Because we were to use the sprite instead.

 I began the case with making the Sprite I needed to make my character animations. I had already tried and failed in making myself a sprite and we got no indication on how we should activate it. I had managed to make it, but I couldn’t activate it without playing all the animations at the same time. I figured that I couldn’t do it on my own so I poked someone in my group who had managed to do it perfectly (Yngvar: itsketchup.blogspot.com). He managed to explain it to me so that I actually understood what was happening. And then the sprite was finished.

To do what the assignment asked, I put the closest trees on a new class of their own, making me able to add more of them than I would by merely adding them as objects alone. I also changed the way the scene looked to make it more alike the scene I had made in the animation part. To make that happen I had to make the background move instead of the character. It wasn’t particularly hard, but it took a bit of time and space (in my actionscript).

Secondly I made the points that the character was to pick up. I made them first with a class of their own, but I figured that when the character picked up one all the others would disappear as well. I ended up with making only two which were objects which I had placed on my scene. Making the character hit them with hitTest wasn’t hard, but what would happen to them when it hit? I tried just moving the points out of the scene, but I sort of thought of it as cheating. Mostly because it was way too easy. 

I ended up with only reducing alpha to zero, making them invisible instead, although I have the feeling there is some other smarter way of picking the points. I also tried removeChild and it sort of worked, but there was a whole lot of error/warning type of messages appearing on my output window so I figured I’d leave it with alpha until further notice.

I saved the hardest part for last as I always do. I’d never thought my joke about Mount Everest would be taken so literally. I spent most of the time we had on this case to try to figure out how to make my character “hit” the ground. We were told that we were to use a while function and a hitTest. Other than that we were left to think for ourselves. People who understand scripting probably found it easy, but I certainly had no idea on how to do this. I’d almost given up when I got help from a classmate, Kristiane (dornick.wordpress.com). Her group had gone through it and she helped me put the right things at the right places. It was a lovely mess of functions which I really don’t know how our teachers had expected us to understand by ourselves.

I just hope that it doesn’t get any harder that this, because then I’m not sure I’ll be able to do it. At least when we don’t get it explained properly.

tirsdag 2. november 2010

Case 4

Making stuff happen.


     Finally back after too many weeks off. In this case my assignment was to write code in flash to make stuff happen. I had to take the same symbols as before into my scene, but this time I was not allowed to drag them there manually. I had to write it in Actionscript to make it happen. I also had to make my character walk left and right with the arrow keys, without it walking out of the scene, all with the help of actionscript.

     And so my life as a living question mark begins. Luckily we were shown scripts for something similar in class so that I could see roughly were to start and stop, and how certain things happened. So when I put my own symbols in the already existing script, but with the appropriate names, it actually worked in the end. 
     But that was after Flash had finally decided to work with me. First my scene went completely white when I tried to run it. The most annoying part was that it didn’t show any errors, so I couldn’t see where the mistake was. I checked that my two files (.fla & .as) were saved the same place, I checked that the .as had the right target and that the .fla had the right class and I checked if I had saved it recently, but it was in fact correct. I let it go for then, and when I decided to try again the scene was not white, but still not the way it was supposed to be.  
      My symbols were thrown all across the scene, but luckily it wasn’t anything that was not capable of fixing. It turned out that the scripts that my teacher used to place the symbols didn’t work for me because I had my center points of the symbols a different place. I would, of course, not have been able to understand that unless I had been told. I had to write the exact pixels that the point was to be placed in, but it was a whole lot more logical, not to mention easier, than what we’d been shown earlier. 

     After the symbols finally were back at ground level I realized that a background was missing. I poked my finger in my eye until I was finally told that the only mistake was that I had written something wrong one place in the script. I had one letter that was bigger than the others. I fixed it. It worked. I hate scripts. 
     When all was back at its rightful place the character could walk left and glide right at the press of the arrow keys, but it could also disappear out of the scene. Half the work was done, only the worst left.

     Since I’m clueless about scripting I tried to google what I needed, but without luck. I wrote a whole lot of stuff in my script, none of which made any difference except from a few errors now and then. 
     Friday I asked for help in class because I really did not have a clue of what I was doing, what I had done or what I was supposed to do. I asked what I had to do to make my character stop at the edge of the scene. He had to explain it to me several times, but finally I kind of got what he was talking about. I really appreciated his patience. The answer he had was annoyingly logical. “Decide between which pixels your character is to be allowed to move, and the character will stop when it gets outside of them.” I will add a screenshot at the end.

     In theory I was now done with what the assignment asked, because it did not say that the character had to turn and walk in the opposite direction when I pushed the arrows, but it said “move across the screen with the help of the right and left arrow keys” so I decided I would wait with doing stuff I didn’t know how to do until we’re asked to do it.
      I tried to make the character turn with various methods but it ended up with the character walking backwards. I tried several times with the scaleX command but most of the time nothing happened, and when it finally did, it stretched my character across the entire scene. 

     After I resigned in my attempts of a moon landing, I decided I’d try to fix something which had annoyed me for a long time. The cloud. In the script I had it showed how the cloud would move over the scene without having to control it. But it moved across the scene, out of the scene and did not come back. I almost scratched a hole in my head trying to figure out how to make my cloud loop.
      I thought about what I had been told about the character not being able to move out of the scene and figured it had to be much the same. I decided that the cloud should move across the scene until it hit 0 pixels on x. Then it was to be back at 550 pixels, which is the width of my scene, and then move on. 
It actually worked, to my great surprise. The cloud looped. 
To myself I had just invented the wheel. I’ll add a picture of my great invention of cloud looping at the end of my wall of text.
I decided to call it enough for this case, since I had done what was described in the assignment, and I wanted to stop with a good feeling about scripting. 

Now I can do anything. Mount Everest next! But first I have to figure out which way is upwards, of course.


 The coordinates are a bit off on the cloud because the center point was not where it was supposed to, but it worked :)