아이가 코딩 에러 못찾아서 잠을 못자네요
봐주실분 있으실까요?
// Create your variables here
var ground = createSprite(211, 409);
ground.setAnimation("ground_grass_1");
ground .scale = 2;
var bear = createSprite(40, 267);
bear.setAnimation("cuteanimals_bear_1");
bear.scale = 0.3;
// Create your sprites here
var x = 0;
function draw() {
x = randomNumber(1, 500) + 1;
// draw background
background("skyblue");
fill("orange");
rect(0, 314, 400, 100);
var x_velocity_of_bear = 3;
var y_velocity_of_bear = 0;
// update sprites
fill("black");
textSize(20);
text("Hello, I am a Bear!", 120, 50);
text("I love carrot and banana and I hate bugs!", 60, 75);
text("Press space to jump, and right to move!", 25, 100);
if (x <= 3) {
carrot();
} else if ((x >= 4 && x <= 10)) {
banana();
} else if ((x == 100)) {
x = 0;
}
if (keyWentDown("space")) {
bear.velocityY = bear.velocityY - x_velocity_of_bear;
}
if (keyDown("up")) {
bear.velocityY = -3;
bear.y = bear.y - x_velocity_of_bear;
}
if (keyDown("down")) {
bear.y = bear + x_velocity_of_bear;
}
if (keyDown("left")) {
bear.x = bear.x - x_velocity_of_bear;
}
if (keyDown("right")) {
bear.x = bear.x + x_velocity_of_bear;
}
if ((bear.y) <= 120) {
bear.velocityY = y_velocity_of_bear;
}
if (bear.y >= 320) {
bear.velocityY = y_velocity_of_bear;
}
drawSprites();
var score = 0;
var health = 100;
if (health < 0) {
background("black");
fill("green");
textSize(50);
text("Game Over!" , 40, 200);
}
if (score >= 50) {
background("black");
fill("green");
textSize(50);
text("You Win!" , 40, 200);
}
fill("white");
textSize(20);
text("Health:", 280, 30);
text (health, 350, 30);
text("Score:", 280, 50);
text (score, 350, 50);
if (health == 0) {
background("black");
textSize(20);
text("You lose...", 200, 200);
}
if (score > 100) {
background("black");
textSize(20);
text("You win!", 200, 200);
}
if (bear.isTouching(banana)) {
score = score + 1;
}
if (bear.isTouching(carrot)) {
score = score + 1;
}
if (bear.isTouching(bug)) {
health = health - 1;
}
drawSprites();
}
function carrot() {
var food7 = createSprite(700, randomNumber(150, 300));
food7.setAnimation("carrot_1");
food7.scale = 0.7;
food7.velocityX = -2;
}
function banana() {
var food1 = createSprite(900, randomNumber(150, 300));
food1.setAnimation("banana_1_1");
food1.scale = 0.1;
food1.velocityX = -2;
}
function bug() {
var bug = createSprite(1000, randomNumber(150, 300));
bug.setAnimation("bug");
bug.scale = 0.15;
bug.velocityX = -2;
}
첫댓글 잘은 모르지만..
네번째줄
ground .scale = 2; 이줄은 ground.scale = 2; 스페이스 붙이시고
if (keyDown("down")) {
bear.y = bear + x_velocity_of_bear;
}
여기는
if (keyDown("down")) {
bear.y = bear.y + x_velocity_of_bear;
}
같네요..
네째줄 ground 뒤에 공백?
Your code has a few issues that need to be corrected. Below are the identified issues along with their fixes:
1.Bear's Downward Movement: The down arrow key logic should update the bear.y property correctly.
2.Random Generation of Carrot, Banana, and Bug: The bug function needs to be called in the draw function.
3.Collision Detection: Collision detection needs to be improved to actually detect the collisions with created objects (carrot, banana, bug).
4.Variable Declaration Scope: score and health should be declared outside of the draw function to retain their values across frames.
5.Duplicate drawSprites() Call: drawSprites() is called twice, it should only be called once.
6.Creating and Removing Sprites: There should be a mechanism to remove off-screen sprites and maintain a list of current food items and bugs for collision detection.
챗gtp 돌리니 이렇게 답 주네요. 코딩할 때 챗gtp 아주 유용하다고하니 한번 챗gtp 이용해보세요. 수정된 코드까지 알려줬는데 답글에 올릴 수가 없어서 메세지만 올렸습니다.
@뽀롱이~ 고맙습니다~~