Skip to content

Commit

Permalink
Update pred
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinShadewing committed Oct 5, 2020
1 parent 8d331b9 commit 214bbd8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
Binary file added res/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/bird.nut
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
visible = 1;
break;
case 50:
visible = 0;
break;
case 60:
newActor(Bird, x, y);
deleteActor(id);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/gmplay.nut
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

if(cerealTimer > 0) cerealTimer--;
else{
newActor(Cereal, 400, randInt(240));
cerealTimer = 10 + randInt(20);
newActor(Cereal, 320, randInt(240));
cerealTimer = 10 + randInt(10);
};

runActors();
Expand Down
4 changes: 0 additions & 4 deletions src/menus.nut
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@
name = function(){ return "Multiplayer"; },
func = function(){ gvPlayers = 2; gvDual = 0; startPlay(1); }
},
{
name = function(){ return "Dual Stick"; },
func = function(){ gvPlayers = 2, gvDual = 1; startPlay(2); }
},
{
name = function(){ return "Options"; },
func = function(){ cursor = 0; menu = meOptions; }
Expand Down
58 changes: 43 additions & 15 deletions src/pred.nut
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const predMiss = 3;
bite = 0;
miss = 0;
gulp = 0;
anim = [];

//Frame numbers
fHead = 0;
Expand All @@ -50,6 +51,8 @@ const predMiss = 3;
bite = sprPred[config.pred].anim.bite;
miss = sprPred[config.pred].anim.miss;
gulp = sprPred[config.pred].anim.gulp;

anim = idle;
};

function step(){
Expand All @@ -72,39 +75,64 @@ const predMiss = 3;
};

//Find target
local target = 0;
foreach(i in actor){
//If no player was found, search for birds
if(target == 0) foreach(i in actor)
{
if(typeof i == "Bird")
{
target = i.id;
};
};

local target = -1;
foreach(i in actor)
{
if(typeof i == "Prey")
{ //See if any players exist
if(target == 0){ //If a target was not already found
if(target == -1)
{ //If a target was not already found
target = i.id;
} else
}
else
{
if(i.x < actor[target].x){ //If the other player is closer
if(i.x < actor[target].x)
{ //If the other player is closer
target = i.id; //Change target to closer player
};
};
};
}; //End foreach


//If no player was found, search for birds
if(target == -1) foreach(i in actor)
{
if(typeof i == "Bird")
{
target = i.id;
break;
};
};

//Move after target
if(target != -1)
{
if(actor[target].y > y && yspeed < 2) yspeed += 0.2;
if(actor[target].y < y && yspeed > -2) yspeed -= 0.2;
if(actor[target].x < x && xspeed > -4) xspeed -= 0.2;
if(actor[target].x > x && xspeed < 1); xspeed += 0.2;
};

//Draw
fBody += 0.5;
fHead += 0.5;
if(fHead > anim[1]) switch(anim)
{
case idle:
fHead = idle[0];
break;
case gulp:
fHead = idle[0];
anim = idle;
break;
}
drawSprite(body, fBody, x, y);
drawSprite(head, fHead, x, y);
if(debugMode)
{
setDrawColor(0xff0000ff);
drawCircle(x, y, 8, false);
if(target != -1) drawCircle(actor[target].x, actor[target].y, 32, false);
}

}; //End step()
Expand Down

0 comments on commit 214bbd8

Please sign in to comment.