After completing flash games research I had to come up with an idea for flash game and then I remembered a game called Missile Game 3D in which you control a missile flying through tunnel in first person view with obstacles that you have to avoid.
In my game I wanted to have 3D feeling that Missile Game has. So I decided to mix three games in one: Missile Game 3D, Space Invaders and Asteroids. The place where game will take place will be space and maybe some deserted planets. The objective of the game would be to get as far as you can by avoiding asteroids rogue planets or other hostile ships. I would like to add some story to the game with animations if there will be enough time left till dead line.
After some experimentation with idea I decided to change my game in order to make it to the dead line. After some thinking i decided to create a maze game. The maze would have mooving parts and the main character would be a cube shaped character. The style of the game will be partialy inspiried by movie tron this will be wisible in games visuals.
Wednesday, 16 November 2011
collision detection script
after creating two cubes and adding instance names cube1 and cube2 added this code
stage.addEventListener(Event.ENTER_FRAME, checkhit);
//movement
function checkhit(myevent:Event):void {
cube1.x+=3
cube2.x-=3
//
if (cube1.hitTestPoint(cube2.x,cube1.y,true)) {
cube2.alpha=.3;
}
}
also if you change cube2.alpha=.3; with cube2.play(); and after colision will play what ever is inside that movieclip (cube2) .
stage.addEventListener(Event.ENTER_FRAME, checkhit);
//movement
function checkhit(myevent:Event):void {
cube1.x+=3
cube2.x-=3
//
if (cube1.hitTestPoint(cube2.x,cube1.y,true)) {
cube2.alpha=.3;
}
}
also if you change cube2.alpha=.3; with cube2.play(); and after colision will play what ever is inside that movieclip (cube2) .
code to bring object from library to stage
first I created a shape and converted it to symbol with Export for action script ticked. And the deleted shape from stage and used this code
code:
import flash.display.MovieClip;
var ship:MovieClip = new Ship ();
ship.x=275
ship.y=200
addChild(ship);
code:
import flash.display.MovieClip;
var ship:MovieClip = new Ship ();
ship.x=275
ship.y=200
addChild(ship);
smoother movement
score:
import flash.events.KeyboardEvent;
var moveRight:Boolean = false
var moveLeft:Boolean = false
var moveUp:Boolean = false
var moveDown:Boolean = false
stage.addEventListener(Event.ENTER_FRAME,moveShip);
function moveShip(event:Event) {
if (moveRight==true){
ship.x+=3;
}
if (moveLeft==true){
ship.x-=3;
}
if (moveUp==true){
ship.y-=3;
}
if (moveDown==true){
ship.y+=3;
}
}
//listens to keyboard being pressed
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKey);
stage.addEventListener(KeyboardEvent.KEY_UP, stopShip);
//if not pressed set move ship to false.
function stopShip(myevent:KeyboardEvent):void{
moveLeft=false;
moveRight=false;
moveUp=false;
moveDown=false;
}
//if pressed set move ship to true.
function pressKey(myevent:KeyboardEvent):void{
if(myevent.keyCode==Keyboard.RIGHT){
moveRight=true;
}
if(myevent.keyCode==Keyboard.LEFT){
moveLeft=true;
}
if(myevent.keyCode==Keyboard.UP){
moveUp=true;
}
if(myevent.keyCode==Keyboard.DOWN){
moveDown=true;
}
}
import flash.events.KeyboardEvent;
var moveRight:Boolean = false
var moveLeft:Boolean = false
var moveUp:Boolean = false
var moveDown:Boolean = false
stage.addEventListener(Event.ENTER_FRAME,moveShip);
function moveShip(event:Event) {
if (moveRight==true){
ship.x+=3;
}
if (moveLeft==true){
ship.x-=3;
}
if (moveUp==true){
ship.y-=3;
}
if (moveDown==true){
ship.y+=3;
}
}
//listens to keyboard being pressed
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKey);
stage.addEventListener(KeyboardEvent.KEY_UP, stopShip);
//if not pressed set move ship to false.
function stopShip(myevent:KeyboardEvent):void{
moveLeft=false;
moveRight=false;
moveUp=false;
moveDown=false;
}
//if pressed set move ship to true.
function pressKey(myevent:KeyboardEvent):void{
if(myevent.keyCode==Keyboard.RIGHT){
moveRight=true;
}
if(myevent.keyCode==Keyboard.LEFT){
moveLeft=true;
}
if(myevent.keyCode==Keyboard.UP){
moveUp=true;
}
if(myevent.keyCode==Keyboard.DOWN){
moveDown=true;
}
}
movement with keys
code for movement
import flash.events.Event;
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveShip);
//kompas klausos klavieturos down paspaudimo
function moveShip (myevent:KeyboardEvent):void {
if (myevent.keyCode==Keyboard.RIGHT) {
ship.x+=10;
ship.rotation=90;
}
if (myevent.keyCode==Keyboard.LEFT) {
ship.x-=10;
ship.rotation=270;
}
if (myevent.keyCode==Keyboard.UP) {
ship.y-=10;
ship.rotation=0;
}
if (myevent.keyCode==Keyboard.DOWN) {
ship.y+=10;
ship.rotation=180;
}
}
//key code=button name --> <-- judejimas x y asyje. ruller padeda. rotation tiesiog laipsniai
stage.addEventListener(Event.ENTER_FRAME,bounds);
function bounds(event:Event) {
if(ship.x>=550) {
ship.x=0
}
if(ship.x<0) {
ship.x=549
}
}
// nustatai kur stage ribos/boundarys ir jei pasiekia boundarys gali nustatatyt kur object teleportuosis.
import flash.events.Event;
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveShip);
//kompas klausos klavieturos down paspaudimo
function moveShip (myevent:KeyboardEvent):void {
if (myevent.keyCode==Keyboard.RIGHT) {
ship.x+=10;
ship.rotation=90;
}
if (myevent.keyCode==Keyboard.LEFT) {
ship.x-=10;
ship.rotation=270;
}
if (myevent.keyCode==Keyboard.UP) {
ship.y-=10;
ship.rotation=0;
}
if (myevent.keyCode==Keyboard.DOWN) {
ship.y+=10;
ship.rotation=180;
}
}
//key code=button name --> <-- judejimas x y asyje. ruller padeda. rotation tiesiog laipsniai
stage.addEventListener(Event.ENTER_FRAME,bounds);
function bounds(event:Event) {
if(ship.x>=550) {
ship.x=0
}
if(ship.x<0) {
ship.x=549
}
}
// nustatai kur stage ribos/boundarys ir jei pasiekia boundarys gali nustatatyt kur object teleportuosis.
Subscribe to:
Comments (Atom)
