o.o
|
|
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
|
|
Baddie Core
Back on Ruins I was attempting to make a baddie system. At the time I saved it to use/finish in the future but I doubt I'll get a chance to. The only thing missing are wall/water checks because I was having trouble with them, as well as dealing damage, taking damage, and healing since we didn't have a health or damage system on Ruins. Enjoy an almost complete baddie system.
Core:
PHP Code:
/* This is the core system of baddies. No scripts but those that are a baddie class should be linking to this. -Switch */
/* this.bname -> baddie name this.range [0] -> aggro [1] -> attack this.speed this.damage this.freeze -> freeze time after an attack this.health [0] -> current [1] -> max */
enum { IDLE, WALK, ATTACK, DEAD }
function onCreated() { cancelEvents("PlayerAggro"); this.spawn_coords = {this.level.name, this.x, this.y}; this.mode = IDLE; this.showCharacter(); this.dir = 2; this.nick = this.bname; setCharAni("baddie_" @lowercase(this.bname)@ "-idle", null); if (findNearestPlayer(this.x, this.y) != null) { //begin loop onTimeout(); } }
function onPlayerEnters() { if (this.mode == IDLE) { //begin loop onTimeout(); } } function onTimeout() { temp.pl = findNearestPlayer(this.x, this.y); temp.dx = temp.pl.x-this.x; temp.dy = temp.pl.y-this.y; temp.dist = (temp.dx^2+temp.dy^2)^0.5; if (temp.dist <= this.range[0]) { this.dcount = 0; this.mode = ATTACK; onPlayerAggro(temp.pl); return; }
if (this.dcount == 20) { temp.rand = int(random(0, 100)); if (temp.rand in |0, 80|) { this.mode = IDLE; } else if (temp.rand in |81, 100|) { this.mode = WALK; } } if (this.mode == IDLE) { setCharAni("baddie_" @lowercase(this.bname)@ "-idle", null); if (this.dcount == 20) { this.dcount = 0; this.dir = int(random(0, 3)); } } else if (this.mode == WALK) { setCharAni("baddie_" @lowercase(this.bname)@ "-walk", null); if (this.dcount == 20) { this.dcount = 0; for (temp.i=0; temp.i<359; temp.i++) { temp.angle = random(0, pi*2); temp.dx = cos(temp.angle)*this.speed*20; temp.dy = -sin(temp.angle)*this.speed*20; if (this.x+temp.dx in |0, 64| && this.y+temp.dy in |0, 64|) { this.dir = (temp.angle in |0, pi*0.25|?3:(temp.angle in |pi*0.25, pi*0.75|?0:(temp.angle in |pi*0.75, pi*1.25|?1:(temp.angle in |pi*1.25, pi*1.75|?2:3)))); move(temp.dx/20, temp.dy/20, 0.1, 0); this.wdx = temp.dx/20; this.wdy = temp.dy/20; break; } } } else { move(this.wdx, this.wdy, 0.1, 0); } } this.dcount++; setTimer(0.1); }
function onPlayerAggro(pl) { if (this.mode != ATTACK) { //stop walk ani setCharAni("baddie_" @lowercase(this.bname)@ "-idle", null); onTimeout(); return; } //get distance to player temp.dx = pl.x-this.x; temp.dy = pl.y-this.y; temp.dist = (temp.dx^2+temp.dy^2)^0.5; //in hurt range if (temp.dist <= this.range[1]) { //so that you can see the attack setCharAni("baddie_" @lowercase(this.bname)@ "-idle", null); attackPlayer(pl); return; } //out of aggro range (plus a quarter of it, to make it harder to get out of) if (temp.dist > this.range[0]*1.25) { //stop walk ani setCharAni("baddie_" @lowercase(this.bname)@ "-idle", null); onTimeout(); return; } //walk setCharAni("baddie_" @lowercase(this.bname)@ "-walk", null); //return dx and dy to a distance of 1, then add in its speed temp.angle = getangle(temp.dx, temp.dy); temp.movex = cos(temp.angle)*this.speed*2; temp.movey = -sin(temp.angle)*this.speed*2; //change dir this.dir = (temp.angle in |0, pi*0.25|?3:(temp.angle in |pi*0.25, pi*0.75|?0:(temp.angle in |pi*0.75, pi*1.25|?1:(temp.angle in |pi*1.25, pi*1.75|?2:3)))); //move baddie towards player move(temp.movex, temp.movey, 0.1, 0); scheduleEvent(0.1, "PlayerAggro", pl); } function attackPlayer(pl) { setCharAni("baddie_" @lowercase(this.bname)@ "-attack", null); //hurt stuff goes here scheduleEvent(1.5, "PlayerAggro", pl); }
function onRespawn() { cancelEvents("PlayerAggro"); setTimer(0); warpto(this.spawn_coords[0], this.spawn_coords[1], this.spawn_coords[2]); this.x = this.spawn_coords[1]; this.y = this.spawn_coords[2]; setCharAni("baddie_" @lowercase(this.bname)@ "-idle", null); this.mode = IDLE; if (findNearestPlayer(this.x, this.y) != null) { onTimeout(); } }
function onPlayerLeaves() { if (findNearestPlayer(this.x, this.y) == null) { this.mode = IDLE; //end loop setTimer(0); setCharAni("baddie_" @lowercase(this.bname)@ "-idle", null); } }
Baddie Class (example):
PHP Code:
/* This is an example of a baddie class that would link to the baddie core. */
function onCreated() { this.bname = "Slug"; this.range = {5, 1}; this.speed = 0.4; this.damage = 9001; this.freeze = 0.3; this.health = {9001, 9001}; this.join("baddie-core"); }
// It's over 9000!!!!!!
|
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
|
|