diff --git a/levels/chickeninvadersmultiplayer/STVchickeninvadersmultiplayer.j2as b/levels/chickeninvadersmultiplayer/STVchickeninvadersmultiplayer.j2as index 49fe776..41c9b63 100644 --- a/levels/chickeninvadersmultiplayer/STVchickeninvadersmultiplayer.j2as +++ b/levels/chickeninvadersmultiplayer/STVchickeninvadersmultiplayer.j2as @@ -102,20 +102,51 @@ class Chicken } }; +enum SpaceshipWeapon { + BORONRAILGUN = 0, +}; + +int SpaceshipWeaponBehave(SpaceshipWeapon weapon, int x, int y, int energy) { + int firerate = 0; + + switch (weapon) + { + case BORONRAILGUN: + if(energy == 1) + bullets.insertLast(Bullet(x, y, false)); + else if(energy == 2) { + bullets.insertLast(Bullet(x - 5, y, false)); + bullets.insertLast(Bullet(x + 5, y, false)); + } + + firerate = 0; + + break; + + default: + break; + } + + return firerate; +} + class SpaceshipPlayer { AnimatedSprite@ sprite; jjPLAYER@ player; bool animatingDirection = false; int prevmx; bool isAnimating = false; + SpaceshipWeapon weapon = BORONRAILGUN; + int energy = 2; + int canShootAt = 0; + bool canShoot = true; SpaceshipPlayer(jjPLAYER@ player) { @this.player = player; @this.sprite = AnimatedSprite(0, 4, 150, 150, 0.2, false); this.sprite.animate = false; this.sprite.setAnimSet(ANIM::CUSTOM[ASSETS_SPACESHIP]); - this.sprite.xScale = 0.5; - this.sprite.yScale = 0.5; + this.sprite.xScale = 0.5; this.sprite.yScale = 0.5; @this.sprite.animfinishcallback = function(dictionary@ args) { SpaceshipPlayer@ spaceship; args.get("spaceship", @spaceship); @@ -134,9 +165,9 @@ class SpaceshipPlayer { @this.sprite.animfinisharguments = {{"spaceship", @this}}; } - string predictMouseDirection(int prevX) { - int deltaX = jjMouseX - prevX; - int tolerance = 1; // Tolerance threshold for movement detection + string predictMouseDirection(int currX, int prevX) { + int deltaX = currX - prevX; + int tolerance = 0; // Tolerance threshold for movement detection if (deltaX > tolerance) return "Right"; @@ -146,24 +177,41 @@ class SpaceshipPlayer { return "None"; } + void shoot() { + if(canShoot || jjGameTicks >= canShootAt) { + canShootAt = jjGameTicks + SpaceshipWeaponBehave(this.weapon, this.sprite.x - 3, this.sprite.y - 20, this.energy); + canShoot = false; + } + } + void update() { - string mouseDirection = predictMouseDirection(prevmx); - this.prevmx = jjMouseX; + string mouseDirection = predictMouseDirection(this.sprite.x, prevmx); + this.prevmx = this.sprite.x; + + if(this.player.keyLeft) + this.sprite.x -= 1; + if(this.player.keyRight) + this.sprite.x += 1; + if(this.player.keyUp) + this.sprite.y -= 1; + if(this.player.keyDown) + this.sprite.y += 1; + if(this.player.keyFire) + this.shoot(); if (!animatingDirection) { - // jjConsole(mouseDirection); + this.sprite.xScale = 0.5; this.sprite.yScale = 0.5; + if (mouseDirection == "Left") { this.sprite.frame = 0; - this.sprite.angle = 0; this.sprite.setId(0); } else if (mouseDirection == "Right") { this.sprite.frame = 0; - this.sprite.angle = 180; + this.sprite.xScale = -0.5; this.sprite.setId(0); // this.sprite.setId(1); } else { this.sprite.frame = 4; - this.sprite.angle = 0; this.sprite.setId(0); } @@ -180,8 +228,9 @@ class SpaceshipPlayer { } } - this.sprite.x = jjMouseX; - this.sprite.y = jjMouseY; + + // this.sprite.x = jjMouseX; + // this.sprite.y = jjMouseY; this.sprite.update(); } @@ -190,8 +239,29 @@ class SpaceshipPlayer { } }; +class Bullet +{ + float x, y; + bool isEgg; + + Bullet(float x, float y, bool isEgg) { + this.x = x; + this.y = y; + this.isEgg = isEgg; + } + + void update() { + this.y -= 4; + } + + void draw(jjCANVAS@ canvas) { + canvas.drawRectangle(int(this.x), int(this.y), 2, 4, 15); + } +}; + array chickens(); array players(); +array bullets(); void onLevelBegin() { jjConsole("Started!"); @@ -225,6 +295,15 @@ void onMain() { { players[playerIndex].update(); } + + for (uint bulletIndex = 0; bulletIndex < bullets.length(); bulletIndex++) + { + bullets[bulletIndex].update(); + + if(bullets[bulletIndex].y <= 0) { + bullets.removeAt(bulletIndex); + } + } } bool onDrawAmmo(jjPLAYER@ player, jjCANVAS@ canvas) { @@ -248,5 +327,10 @@ bool onDrawAmmo(jjPLAYER@ player, jjCANVAS@ canvas) { players[playerIndex].draw(canvas); } + for (uint bulletIndex = 0; bulletIndex < bullets.length(); bulletIndex++) + { + bullets[bulletIndex].draw(canvas); + } + return true; } \ No newline at end of file diff --git a/levels/chickeninvadersmultiplayer/STVchickeninvadersmultiplayer.j2l b/levels/chickeninvadersmultiplayer/STVchickeninvadersmultiplayer.j2l index 78de377..fd4282b 100644 Binary files a/levels/chickeninvadersmultiplayer/STVchickeninvadersmultiplayer.j2l and b/levels/chickeninvadersmultiplayer/STVchickeninvadersmultiplayer.j2l differ diff --git a/scripts/STVutil.asc b/scripts/STVutil.asc index 7f85777..d6c1118 100644 --- a/scripts/STVutil.asc +++ b/scripts/STVutil.asc @@ -286,8 +286,8 @@ class AnimatedSprite { if (this.visible) { - int x = 0; - if(direction != SPRITE::FLIPNONE) x = direction; else x = angle; + int x = angle; + if(direction != SPRITE::FLIPNONE) x = direction; canvas.drawRotatedSprite( this.x, this.y,