Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinShadewing committed Oct 30, 2020
2 parents d7503fc + 627a704 commit 33b8a55
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 142 deletions.
2 changes: 2 additions & 0 deletions fld.brx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/brux

/*======================================*\
| FLY, LITTLE DRAGON! |
| |
Expand Down
28 changes: 14 additions & 14 deletions src/globals.nut
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
//Predator legend: head, body, wings, bodytype

::config <- {
safe = 0,
difficulty = 0,
con0 = {
up = k_up,
down = k_down,
left = k_left,
right = k_right
},
con1 = {
up = k_w,
down = k_s,
left = k_a,
right = k_d
},
safe = 0,
difficulty = 0,
con0 = {
up = k_up,
down = k_down,
left = k_left,
right = k_right
},
con1 = {
up = k_w,
down = k_s,
left = k_a,
right = k_d
},
prey0 = "Hida",
prey1 = "Passy",
pred = "Comito"
Expand Down
17 changes: 11 additions & 6 deletions src/gmplay.nut
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
::cerealTimer <- 30;

::gmPlay <- function(){
::gmPlay <- function()
{
drawBackground();

if(cerealTimer > 0) cerealTimer--;
else{
else
{
newActor(Cereal, 320, randInt(240));
cerealTimer = 10 + randInt(10);
};
Expand All @@ -13,18 +15,21 @@

//Draw stamina
local p = findActor("Prey0");
if(p != -1){
if(p != -1)
{
drawText(font, 8, 8, (round(actor[p].energy)).tostring());
} else drawText(font, 8, 8, (0).tostring());
};

::startPlay <- function(playmode){
switch(playmode){
::startPlay <- function(playmode)
{
switch(playmode)
{
case 0:
gvPlayers = 1;
gvDual = 0;
newActor(Prey0, 200, 120);
newActor(Predator, 0, 120);
newActor(Predator, 64, 120);
break;
case 1:
gvPlayers = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/main.nut
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
gvQuit = 0;

//Start the music
playMusic(music, -1);
//playMusic(music, -1);

//Main game loop
while(!gvQuit){
Expand Down
248 changes: 128 additions & 120 deletions src/pred.nut
Original file line number Diff line number Diff line change
Expand Up @@ -13,128 +13,136 @@ const predMiss = 3;
//Wings need only increment.

::headFrames <- {
comito = {
open = [0, 0],
bite = [0, 0],
gulp = [0, 0],
miss = [0, 0]
}
comito = {
open = [0, 0],
bite = [0, 0],
gulp = [0, 0],
miss = [0, 0]
}
};

::Predator <- class extends Actor{
//Sprite parts
head = 0;
body = 0;
wing = 0;
idle = 0;
bite = 0;
miss = 0;
gulp = 0;
anim = [];

//Frame numbers
fHead = 0;
fBody = 0;
fWing = 0;

xspeed = 0;
yspeed = 0;

state = predOpen;

constructor(_x, _y){
base.constructor(_x, _y);
body = sprPred[config.pred].body;
head = sprPred[config.pred].head;
wing = sprPred[config.pred].wing;
idle = sprPred[config.pred].anim.idle;
bite = sprPred[config.pred].anim.bite;
miss = sprPred[config.pred].anim.miss;
gulp = sprPred[config.pred].anim.gulp;

anim = idle;
};

function step(){
base.step();

//Movement and bounds
x += xspeed;
y += yspeed;

if(y > 240)
{
y = 240;
yspeed = 0;
};

if(y < 0)
{
y = 0;
yspeed = 0;
};

//Find target
local target = -1;
foreach(i in actor)
{
if(typeof i == "Prey")
{ //See if any players exist
if(target == -1)
{ //If a target was not already found
target = i.id;
}
else
{
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()
//Sprite parts
head = 0;
body = 0;
wing = 0;
idle = 0;
bite = 0;
miss = 0;
gulp = 0;
anim = [];

//Frame numbers
fHead = 0;
fBody = 0;
fWing = 0;

xspeed = 0;
yspeed = 0;

state = predOpen;

constructor(_x, _y){
base.constructor(_x, _y);
body = sprPred[config.pred].body;
head = sprPred[config.pred].head;
wing = sprPred[config.pred].wing;
idle = sprPred[config.pred].anim.idle;
bite = sprPred[config.pred].anim.bite;
miss = sprPred[config.pred].anim.miss;
gulp = sprPred[config.pred].anim.gulp;

anim = idle;
};

function step(){
base.step();

//Movement and bounds
x += xspeed;
y += yspeed;

//Find target
local target = -1;
foreach(i in actor)
{
if(typeof i == "Prey0" || typeof i == "Prey1")
{ //See if any players exist
if(target == -1)
{ //If a target was not already found
target = i.id;
}
else
{
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.5;
if(actor[target].y < y && yspeed > -2) yspeed -= 0.5;
if(actor[target].x < x && xspeed > -2) xspeed -= 0.2;
if(actor[target].x > x && xspeed < 0.05); xspeed += 0.05;
};

//Limits
if(xspeed > 0.05) xspeed = 0.05;
if(xspeed < -2) xspeed = -2;
if(y > 240)
{
y = 240;
yspeed = 0;
};

if(y < 0)
{
y = 0;
yspeed = 0;
};
if(x < 0)
{
x = 0;
xspeed = 0;
};

//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()

}; //End Predator
2 changes: 1 addition & 1 deletion src/prey.nut
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@
};
};

function _typeof(){ return "Prey0"; };
function _typeof(){ return "Prey0"; };
};

0 comments on commit 33b8a55

Please sign in to comment.