Friday 19 June 2015

Aliens


I have created 4 aliens. One red, one orange, one pink and one blue and on the sprite image I have erased the background of the aliens and the height and width is 32x32. I have created an object for all the aliens but I have also created a parent alien object because there are alot of actions in the aliens movement so it is easier to have a parent alien and have all the actions there and make the normal alien object have a parent of parent alien object so all the action will be for each alien without having to copy and paste the actions in each alien. The parent alien object i have the wall sprite as the sprite for this object so that the aliens wont go through the walls.

In the parent alien object I have added a create event and in that event i have set the alien_speed variable to 0 and the which_way varaible to 0. theses varaibles that i have set up are used in the other events that control the speed of the aliens and which direction they will go. I have also got the alien to move left, right, up and down fixed moving. 



I have set an alarm event and in that I have set the variable alien_speed to a value of 4 which is what the aliens speed will be when they move. 


I have made another event which is an End step so this will be used last out of the process. In this event I have alot of actions which is starting off to check the aliens are on the grid and testing the global.can_move variable to see if the aliens are able to move which is set to true so they should be able to move.
The next set of actions are moving freely in the direction with a speed of alien_speed. I have set the variable which_way to 0 and then tested the variable vspeed (vertical speed) is equal to 0.
First off I am going to do the horizontal direction, the vertical will be almost identical but it will have different values for the direction.
I have checked the object wall and i have set it up so it's x is x + hspeed (horizontal speed) and the y is just y. I then have set a variable for which_way set to 3. I then check the wall object again but with an x of x and a y of y + alien_speed. I then have the which_way variable set to 1. Next I have done the checking wall object with an x of x and a y of y - alien_speed and the variable which_way is set to 5. These positions all decide which way the alien goes. I then exit the event. I then set a variable direction to an angle of 270 and exit the event if which_way is equal to 1. If it is equal to 5 it will do the same but the direction will be 90.  If which_way is equal to 4 it will test the chance and choose 1 out of 2 directions to go and check the barrier object and set the direction to 270 and then exit the event.




If which_way is equal to 8 then it will do the test chance of 2 sides, set the variable direction to 90 and exit the event. If which_way is equal to 6 it will test the chance of 2 sides,set the variable direction to 270 or else it will set the direction to 90 and exit the event. If it is equal to 9 it will test chance of 2 sides and exit the event otherwise it will test the chance of two sides and set the direction to 90 or else it will set the direction to 270 and exit the event. If it is equal to 0 it will set the direction to 180 and exit the event. This is the end of the horizontal movements.
I have put in an else action. The vertical movements are exactly the same apart from the angle will be different so the check wall object will have an x of x and a y of y + vspeed. The second check wall object will have a of x + alien_speed and a y of y. The last check wall object will have x of x - alien_speed and a y of y. The rest is exactly the same as horizontal but some of the angle have changed for example the which_way equal to 0 rather than 270. Which_way equal to 5 will be 180 instead of 90. which_way equal to 4 will be 0 instead of 270. Which_way equal to 8 will be 180 instead of 90.
Which_way equal to 6 will be 0 else 180 rather than 270 else 90. Equal to 9 will be 0 else 180 rather than 90 else 270. Equal to 0 will stay as 180. I have then put some end blocks. I have put these in blocks so i don't get terribly confused on what is what and for which direction. That is the movements decision making complete.


For the aliens not to go into the wall along with making the parent the wall i also need to have a collision with the wall object to make the alien go either left,right, up or down when it hits the wall so in other words if it hits a wall it will go in a different direction.

The last one is the outside room event so if the alien goes out the room i have the action wrap in both directions so the aliens will come back onto the maze in a different area (through the tunnels).


No comments:

Post a Comment