Hey guys,
I’ve posted here a while ago asking for help, wanted to say thanks! I have a problem though. Recently I’ve encountered a problem in my game, food randomly stops falling. Now I’ve checked my coding and it all seems fine, I’ve gotten a friend to check and he said it’s fine. Problem is that the food SOMETIMES stops and it’s important I get this sorted because I got 2 weeks left to complete this college project.
If ANYONE can help please please please reply here or PM me.
Here is all the coding I have.
Character Following mouse code
fixin._x = Math.random() * Stage.width;
stop();
//set score window to invisible at start
scoreWindow._visible = false;
//timer
var secs:Number = 120;
var millisecs:Number = 60;
function timer_reset(){
secs = 180;
millisecs = 60;
}
function timer(){
if(secs>0 && millisecs>0){
millisecs--
if(millisecs == 0){
millisecs = 30;
secs--;
}
}else{
//display score window
scoreWindow._visible = true;
}
}
//Mouse
char_mc.maxSpeed = 0.6
char_mc.onEnterFrame = function() {
if(scoreWindow._visible != true){ //game will only play if the score window isn't active
Mouse.hide();
//timer
timer();
//HUD
lives_txt.text = "Lives: "+lives;
//everything else
this.moveRL = (_xmouse - this._x) / 13;
this.nowSpeed = Math.sqrt((this.moveRL*this.moveRL)+(this.moveUD*this.moveUD))
if (this.nowSpeed > this.maxSpeed) {
this._rotation = (-Math.atan2(this.moveRL,this.moveUD)/(Math.PI/180))
this.moveRL *= this.maxSpeed/this.nowSpeed;
this.moveUD *= this.maxSpeed/this.nowSpeed;
}
this._x += this.moveRL
}else{
scoreWindow.swapDepths(_root.getNextHighestDepth());
Mouse.show();
}
}
Mouse.hide()
Main Game Code:
var goodItems:Array = ["onion", "cheese", "bread", "tomato", "lettuce", "mayo", "meat", "chicken"];
var badItems:Array = ["moldyCheese", "moldyBread", "moldyMeat", "moldyBacon"];
var speed:Number;
var good:Boolean;
var score:Number = 0;
var lives:Number = 3;
function randomFood() {
// you do not want to call random food twice each time or food will increase exponentially so call this function twice at beginning
var itemPool:Array;
// Number of items to drop
var numOfItems = 2;
// Use a for loop to generate 2 items...
// from either of the 2 arrays
var pick:Number = Math.floor(Math.random()*2);
if (pick == 1) {
itemPool = badItems;
good = false;
} else {
itemPool = goodItems;
good = true;
}
var arrayIndexToUse:Number = Math.floor(Math.random()*itemPool.length);
var itemToUse:String = itemPool[arrayIndexToUse];
//this.getNextHighestDepth()) to update names and give depth as you would have movieClip attaching to same depth and removing each other
var item:MovieClip = _root.attachMovie(itemToUse, "item_"+this.getNextHighestDepth(), this.getNextHighestDepth());
item._x = Math.random()*Stage.width;
// Start each item at a random position above the stage
item._y = Math.floor(Math.random()*-40)+0;
//give each food a val - good or !good so can be used in scoring
item.val = good;
//make speed a property of item so speed can have different values you should play with this equation
item.speed = (Math.random()*6)+1;
item.onEnterFrame = moveFood;
}
function moveFood() {
if(_root.scoreWindow._visible != true){
//move by this property speed
this._y += this.speed;
// hitTest
if (this.hitTest(char_mc.basket)) {
//check if good or bad and update score and set score
if (this.val == true) {
score += 15;
score_txt.text = "Score: "+score;
} else {
score -= 10;
score_txt.text = "Score: "+score;
lives--
if(lives<0){
lives = 0
gotoAndStop("gameover");
}
}
this.removeMovieClip();
randomFood();
}
if (this._y>(Stage.height-20)) {
this.removeMovieClip();
delete this.onEnterFrame;
randomFood();
}
}
}
// call random food twice to start game
for (i=0; i<2; i++) {
randomFood();
}
//set score at beginning
score_txt.text = "Score: "+score;
I also have another question. Is there a way I can get the character to go to frame 2 when I move the mouse?