ZeldariaLvl 41
kkkk
kkkk
Here's some more info: The BROKEN[0] sprite is created when you finish the tutorial and when you touch it, after 2 seconds or so it destroys BROKEN[0] but for some reason it won't get destroyed!
I even tried a lifetime thing but nooooooo it didn't work;
And when I try player.isTouching(BROKEN[0]) or player.isTouching(BROKEN) in the console it always says false!
Ok, im back, my school actually hand a jog a thon I forgot about and then I had to go to martial arts practice.
anyways, I think this error is because either
-broken[0] is not defined yet or
-your collision thingy moves the player's y when it touches the platform
so here is What you should try, tell me if it works or not.
for(var indx = 0; indx < BROKEN.length; indx++){
if(player.isTouching(BROKEN[indx])){
BROKEN[indx].velocityY = 5;//or whatever you want to happen
}
}
it works hooray!!
And now it doesn't again hmmmmmmmmmmmm
Here is the code currently:
//ALL the boring stuff
!<
camera.on();
var availableCLOUDS = 3;
var level = "tutorial";
var BACKGROUND_MUSIC = "sound://category_background/repitition.mp3";
var LIVES = 10;
var INFOtext = 5;
var spawnX = 200;
var spawnY = 200;
var player = createSprite(60, 360);
var cLoUdS = createGroup();
player.setAnimation("player_idle");
var ground = createGroup();
var OBSTACLEs = createGroup();
var ENDs = createGroup();
var TExt = createSprite(200, 200);
var BROKEN = createGroup();
TExt.setAnimation("text_1");
TExt.scale = 1.5;
playSound("sound://category_background/repitition.mp3", true);
ground.add(createSprite(60,365));
ground.add(createSprite(200, 230));
ground.setAnimationEach("ground_grass_1");
createEdgeSprites();
//declares the functions and makes sure stuff is animated good I guess
function draw() {
background("white");
ENDs.setAnimationEach("END_portal_thing");
ground.setAnimationEach("ground_grass_1");
ground.setScaleEach(0.3);
BROKEN.setScaleEach(0.3);
BROKEN.setAnimationEach("ground_grass_broken_1");
drawSprites();
move();
collide();
DIE();
clouds();
infoTEXT();
LEVELup();
CAMERAA();
}
function CAMERAA() {
if (player.y>=400&&level==1) {
camera.y=600;
}
}
//for the levels, when you advance
function LEVELup() {
if (player.isTouching(ENDs)) {
playSound("sound://category_jump/cartoon_synth_warp_jump.mp3", false);
stopSound(BACKGROUND_MUSIC);
ground.destroyEach();
ENDs.destroyEach();
cLoUdS.destroyEach();
availableCLOUDS = 3;
if (level=="tutorial") {
level = 1;
} else {
level = level+1;
}
if (level==1) {
BROKEN.add(createSprite(200, 200));
ground.add(createSprite(200, 80));
spawnX = 200;
spawnY = 40;
player.x = spawnX;
player.y = spawnY;
BACKGROUND_MUSIC = "sound://category_background/stride.mp3";
playSound(BACKGROUND_MUSIC, true);
}
}
}
//spawning clouds
function clouds() {
if (mouseWentDown("leftButton")&&availableCLOUDS!=0) {
cLoUdS.add(createSprite(World.mouseX,World.mouseY));
cLoUdS.setLifetimeEach(175);
availableCLOUDS = availableCLOUDS-1;
} else {
}
cLoUdS.setAnimationEach("cloud_1");
}
//tutorial text
function infoTEXT() {
if (INFOtext==4) {
TExt.setAnimation("text_2");
TExt.x = 125;
TExt.y = 300;
}
if (INFOtext==3) {
TExt.setAnimation("text_3");
TExt.x = 200;
TExt.y = 200;
}
if (INFOtext==2) {
TExt.setAnimation("text_4");
}
if (INFOtext==1) {
TExt.setAnimation("text_5");
}
if (INFOtext==0) {
TExt.setAnimation("text_6");
ENDs.add(createSprite(300, 300));
}
textFont("Garamond");
textSize(24);
text("LIVES: "+LIVES, 0, 15);
if (keyWentDown("enter")) {
INFOtext = INFOtext-1;
}
}
//ways of death and stuff
function DIE() {
if (player.isTouching(bottomEdge)&&level!=1) {
LIVES = LIVES-1;
player.x = spawnX;
player.y = spawnY;
player.visible = false;
stopSound(BACKGROUND_MUSIC);
console.log(("Oof! The player has died from FALLING! Now has "+LIVES)+" lives left!");
playSound("sound://category_alerts/comedy_game_over_1.mp3", false);
setTimeout(function(){
setTimeout(function(){
player.visible = true;
playSound(BACKGROUND_MUSIC, true);
}, 1000);
}, 1000);
}
}
//moving
function move() {
if (keyDown("right")) {
player.x = player.x+2;
player.setAnimation("player_walk");
player.mirrorX(+1);
} else if ((keyDown("left"))) {
player.x = player.x-2;
player.setAnimation("player_walk");
player.mirrorX(-1);
} else {
player.setAnimation("player_idle");
}
if (keyDown("up")){
player.y = player.y + 3 ;
player.setAnimation("player_jump");
if (player.isTouching(ground)| |player.isTouching(cLoUdS)| |player.isTouching(BROKEN)) {
playSound("sound://category_digital/boing_1.mp3", false);
player.y = player.y - 8;
player.velocityY = -15 ;
} else {
player.y = player.y - 3 ;
}
}
}
//collision and special platforms
function collide() {
player.collide(BROKEN);
player.collide(ground);
player.collide(cLoUdS);
while ((player.isTouching(ground))) {
player.velocityY = 0 ;
player.y = player. y - 0.1 ;
}
for(var indx = 0; indx < BROKEN.length; indx++){
if(player.isTouching(BROKEN[indx])){
BROKEN[indx].velocityY = 5;
}
}
player.velocityY = player.velocityY + 1.5;
}
*note: the | | is || but it would hide it if I put it in 'code way' so yeah :/
Including what Ackvonhuelio reccomended
https://studio.code.org/projects/gamelab/BPUrQxTqqQuMnCi_0kJ1I9Eui7uHN_oxqIJ9saZGQcA/view
here is the fixed code
I fixed the falling block which you can adjust if you want, and made it so each cloud has an individual lifetime(whenever you used to place a cloud It would reset the lifetimes of all the clouds)
Thx!
Also fixed a bug where you were creating a new portal every frame
yeah that is annoying XD