I have finalized my game idea now, It'll be a timed game where instead of the score going up every time you're hit that 'score' will be how much time it took to get through all the levels. I decided I want three levels and the purpose of each is to get back to your island by building a raft
Codes:
360 degree rotation using <- and -> arrow keys
Push forward and gradually slow down when up key is pressed
pick up knocked out penguins when walked into
automatically build raft when you have 6 penguins
random movement
timer
scoreboard
shooting
timer if you stand still too long, melt ice, dead.
Wednesday, 19 October 2011
Sprite designs
Today I started the making images for my game.
This is my image for my penguin but I realised that for the movement I want to have in my game (rotation) it would look bad. So I decided to change the view of my game to birds eye.
These are the final images I came up with, being ariel veiw they look a lot better. Next I started work on the backgrounds, three of them, one for each level.
I decided I wanted a low opacity blue overlay over the top of the penguins instead of my first idea to keep them on the ice, so I made a version two of each background with the shape of the water in blue and where the ice is transparent, my plan was to add this into the file last to if you go off the ice the blue ontop makes it look like they're underwater.
Finally I made my intro scene, game over screen, play and play again buttons and a three-stage health bar.
With all my resources made I could now start coding my game.
Thursday, 13 October 2011
Arrays and Hit tests
Today we made something called an Array in flash. An Array is like a big list, each line in the list has a specific number and each line holds information. In our code we used an Array to repeat a code to make a box so we have more than one but we don't have to write the whole code out.
var blockArray:Array=new Array();
//make a new array called blockArray
for (var i:int = 0; i < 15; i++) {
//Add a line until it has 15
var cube:MovieClip = new box();
//make a varible called cube using box from the library
cube.x=Math.random()*550
//random position along the x axis untill 550 (document size)
cube.y=Math.random()*400
//random position along y axis
addChild(cube);
//adds cube
blockArray[i]=cube;
//fills list with 15 cubes
}
Next we made a quick hit test code
stage.addEventListener(Event.ENTER_FRAME, checkHit);
//listen to the stage on all frames, run a function called checkhit
function checkHit(myevent:Event):void {
for (var i:int = 0;i<15; i++) {
if (blockArray[i].hitTestPoint(mouseX,mouseY, true)) {
//if the cubes in the blockArray get's hit by the mouse either on the x axis or y axis
blockArray[i].alpha=.3;
//the alpha (transparency) goes down to 0.3
}
}
}
We also made a code for two objects on the stage hitting each other.
stage.addEventListener(Event.ENTER_FRAME, checkHit);
//listen to the frame and run a function called checkHit
function checkHit(myevent:Event):void {
Cube1.x+=3
//set cube1 to move right at a speed of 3 pixels
Cube2.x-=3
//Same with cube2 but left
if (Cube2.hitTestPoint(Cube1.x,Cube1.y,true)) {
//if cube 2 gets hit by cube 1 along either the x or y axis
Cube1.alpha=.3;
//The alpha of cube 1 goes down to 0.3
}
}
var blockArray:Array=new Array();
//make a new array called blockArray
for (var i:int = 0; i < 15; i++) {
//Add a line until it has 15
var cube:MovieClip = new box();
//make a varible called cube using box from the library
cube.x=Math.random()*550
//random position along the x axis untill 550 (document size)
cube.y=Math.random()*400
//random position along y axis
addChild(cube);
//adds cube
blockArray[i]=cube;
//fills list with 15 cubes
}
Next we made a quick hit test code
stage.addEventListener(Event.ENTER_FRAME, checkHit);
//listen to the stage on all frames, run a function called checkhit
function checkHit(myevent:Event):void {
for (var i:int = 0;i<15; i++) {
if (blockArray[i].hitTestPoint(mouseX,mouseY, true)) {
//if the cubes in the blockArray get's hit by the mouse either on the x axis or y axis
blockArray[i].alpha=.3;
//the alpha (transparency) goes down to 0.3
}
}
}
We also made a code for two objects on the stage hitting each other.
stage.addEventListener(Event.ENTER_FRAME, checkHit);
//listen to the frame and run a function called checkHit
function checkHit(myevent:Event):void {
Cube1.x+=3
//set cube1 to move right at a speed of 3 pixels
Cube2.x-=3
//Same with cube2 but left
if (Cube2.hitTestPoint(Cube1.x,Cube1.y,true)) {
//if cube 2 gets hit by cube 1 along either the x or y axis
Cube1.alpha=.3;
//The alpha of cube 1 goes down to 0.3
}
}
Tuesday, 11 October 2011
Game idea development
For this module we have to design a game based on the classic arcade game Asteroids using similar coding that we pick up as we re-create the game in flash. Personally the controls of the original game (left and right for rotating and up for thrust) seem very erratic and hard to control for me, a bit like when your ice skating. This idea caught on as I came up with the idea of a shipwrecked man stuck on a sheet of ice trying not to fall into the water. Originally I was going to have polar bears and penguins on the ice with you, the penguins would be moving randomly like the asteroids in the original and the polar bears would move towards you, but talking to my lecturer about it I realised this would be really hard to do so I decided on having the ice beneath the player melt if he stands there too long. I also decided on a slightly perspective screen where the player gets smaller the further away from the screen is, this may cause problems with seeing where your going at the back so I might change it to a birds eye view instead.
Smoother movement and library attachment
Today we looked at a smoother way to move the 'Ship' around the stage.
var moveRight:Boolean = false
var moveLeft:Boolean = false
var moveUp:Boolean = false
var moveDown:Boolean = false
//First we made a variable for each key we will use for movement, then we set the boolean (a statement that can only be true or false) to false
stage.addEventListener(Event.ENTER_FRAME,moveShip);
//We then listen to the frame and set up a function called moveShip
function moveShip(event:Event) {
if (moveRight==true) {
ship.x+=3;
}
//We then tell it that if move right becomes true, move right, this is repeated with the other 3 directions.
if (moveLeft==true) {
ship.x-=3;
}
if (moveUp==true) {
ship.y-=3;
}
if (moveDown==true) {
ship.y+=3;
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN,pressKey);
//A new function for when a key is pressed down
stage.addEventListener(KeyboardEvent.KEY_UP,stopShip);
//A new function for when a key is not being pressed
function stopShip(myevent:KeyboardEvent):void{
moveLeft=false;
moveRight=false;
moveUp=false;
moveDown=false;
}
//When stopShip is happening (no keys being pressed) all the move values in function moveShip are false, therefore there is no movement
function pressKey(myevent:KeyboardEvent):void{
if(myevent.keyCode==Keyboard.RIGHT){
moveRight=true;
}
//If the right key is pressed then the value of moveRight in moveShip becomes true and it will move. This is repeated for the other keys.
if(myevent.keyCode==Keyboard.LEFT){
moveLeft=true;
}
if(myevent.keyCode==Keyboard.UP){
moveUp=true;
}
if(myevent.keyCode==Keyboard.DOWN){
moveDown=true;
}
}
To add a file to the stage from the library is quite simple but first when your making the movie clip you have to go advanced settings we clicked 'export for ActionScript' and called it 'Ship' and set the class to 'Ship', we then deleted it from the stage.
var ship:MovieClip=new Ship();
//This basically pulls the thing in the library called Ship and puts it on the stage, renaming it ship
ship.x=275
ship.y=200
//we then positioned the ship in the middle of the stage
addChild(ship);
//then we added the final bit of code.
var moveRight:Boolean = false
var moveLeft:Boolean = false
var moveUp:Boolean = false
var moveDown:Boolean = false
//First we made a variable for each key we will use for movement, then we set the boolean (a statement that can only be true or false) to false
stage.addEventListener(Event.ENTER_FRAME,moveShip);
//We then listen to the frame and set up a function called moveShip
function moveShip(event:Event) {
if (moveRight==true) {
ship.x+=3;
}
//We then tell it that if move right becomes true, move right, this is repeated with the other 3 directions.
if (moveLeft==true) {
ship.x-=3;
}
if (moveUp==true) {
ship.y-=3;
}
if (moveDown==true) {
ship.y+=3;
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN,pressKey);
//A new function for when a key is pressed down
stage.addEventListener(KeyboardEvent.KEY_UP,stopShip);
//A new function for when a key is not being pressed
function stopShip(myevent:KeyboardEvent):void{
moveLeft=false;
moveRight=false;
moveUp=false;
moveDown=false;
}
//When stopShip is happening (no keys being pressed) all the move values in function moveShip are false, therefore there is no movement
function pressKey(myevent:KeyboardEvent):void{
if(myevent.keyCode==Keyboard.RIGHT){
moveRight=true;
}
//If the right key is pressed then the value of moveRight in moveShip becomes true and it will move. This is repeated for the other keys.
if(myevent.keyCode==Keyboard.LEFT){
moveLeft=true;
}
if(myevent.keyCode==Keyboard.UP){
moveUp=true;
}
if(myevent.keyCode==Keyboard.DOWN){
moveDown=true;
}
}
To add a file to the stage from the library is quite simple but first when your making the movie clip you have to go advanced settings we clicked 'export for ActionScript' and called it 'Ship' and set the class to 'Ship', we then deleted it from the stage.
var ship:MovieClip=new Ship();
//This basically pulls the thing in the library called Ship and puts it on the stage, renaming it ship
ship.x=275
ship.y=200
//we then positioned the ship in the middle of the stage
addChild(ship);
//then we added the final bit of code.
Tuesday, 4 October 2011
Classic keyboard navigation
Today we made a simple code for basic keyboard navigation.
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveShip);
//This tells the program to look at the stage and listen out for any key pressed down, and if it is pressed down use function moveShip
function moveShip(myevent:KeyboardEvent):void {
//Name of the function
if (myevent.keyCode==Keyboard.RIGHT){
Ship.x+=5;
Ship.rotation=90;
//If the right key is pressed move the Ship 5 pixels along the x axis and rotate it to 90 degrees so it looks like this >
if (myevent.keyCode==Keyboard.LEFT){
Ship.x-=5;
Ship.rotation=270;
}
//The same code but for when the left key is pressed but Ship moves to 270 degrees so it looks like this <
if (myevent.keyCode==Keyboard.UP){
Ship.y-=5;
Ship.rotation=0;
}
//Same code again but now it's rotated to 0 degrees which is default position ^
if (myevent.keyCode==Keyboard.DOWN){
Ship.y+=5;
Ship.rotation=180;
}
}
//And finally for down
stage.addEventListener(Event.ENTER_FRAME, bounds);
//Now we ask the program to 'listen' to the enter frame
function bounds(event:Event) {
if (Ship.x>=550) {
Ship.x=0;
}
//This tells the program that if 'Ship' is 550 or over pixels along the x axis (going off screen to the right) to move the ship back to 0 on the x axis (the far left)
if (Ship.x<0) {
Ship.x=550;
}
if (Ship.y>=400) {
Ship.y=0;
}
if (Ship.y<0) {
Ship.y=400;
}
}
//We then use the same code for the other sides so that when you move the Ship off the screen in any direction it re-appears at the opposite side
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveShip);
//This tells the program to look at the stage and listen out for any key pressed down, and if it is pressed down use function moveShip
function moveShip(myevent:KeyboardEvent):void {
//Name of the function
if (myevent.keyCode==Keyboard.RIGHT){
Ship.x+=5;
Ship.rotation=90;
}
//If the right key is pressed move the Ship 5 pixels along the x axis and rotate it to 90 degrees so it looks like this >
if (myevent.keyCode==Keyboard.LEFT){
Ship.x-=5;
Ship.rotation=270;
}
//The same code but for when the left key is pressed but Ship moves to 270 degrees so it looks like this <
if (myevent.keyCode==Keyboard.UP){
Ship.y-=5;
Ship.rotation=0;
}
//Same code again but now it's rotated to 0 degrees which is default position ^
if (myevent.keyCode==Keyboard.DOWN){
Ship.y+=5;
Ship.rotation=180;
}
}
//And finally for down
stage.addEventListener(Event.ENTER_FRAME, bounds);
//Now we ask the program to 'listen' to the enter frame
function bounds(event:Event) {
if (Ship.x>=550) {
Ship.x=0;
}
//This tells the program that if 'Ship' is 550 or over pixels along the x axis (going off screen to the right) to move the ship back to 0 on the x axis (the far left)
if (Ship.x<0) {
Ship.x=550;
}
if (Ship.y>=400) {
Ship.y=0;
}
if (Ship.y<0) {
Ship.y=400;
}
}
//We then use the same code for the other sides so that when you move the Ship off the screen in any direction it re-appears at the opposite side
Subscribe to:
Posts (Atom)