Skip to content

Commit

Permalink
좋아요를 지불하여 게임 초반에 무적 아이템을 구매할 수 있도록 기획 수정 및 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
HK416 committed Jun 5, 2024
1 parent 291f78e commit 24bb573
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
package com.hk416.fallingdowntino.scene;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.util.Log;

import com.hk416.fallingdowntino.DataLoader;
import com.hk416.fallingdowntino.GameView;
import com.hk416.fallingdowntino.R;
import com.hk416.framework.audio.Sound;
import com.hk416.framework.object.GameObject;
import com.hk416.framework.object.UiButtonObject;
import com.hk416.framework.object.UiImageObject;
import com.hk416.framework.object.UiRectObject;
import com.hk416.framework.object.UiTextObject;
import com.hk416.framework.scene.GameScene;
import com.hk416.framework.scene.SceneManager;
import com.hk416.framework.transform.Anchor;

public class BoostGameScene extends GameScene {
private enum Tags { Background, Dialog, Button, Icon, Text }
private enum Tags { Background, Button, Icon, Text }

private static final String TAG = BoostGameScene.class.getSimpleName();
private static final Anchor ENERGY_BTN_ANCHOR = new Anchor(
0.4f, 0.1f, 0.596875f, 0.45f
0.4f, 0.325f, 0.596875f, 0.675f
);
private static final Anchor SPANNER_BTN_ANCHOR = new Anchor(
0.4f, 0.55f, 0.596875f, 0.9f
private static final Anchor ENERGY_ICO_ANCHOR = new Anchor(
0.45f, 0.375f, 0.546875f, 0.625f
);
private static final Anchor SKIP_BTN_ANCHOR = new Anchor(
0.8f, 0.1f, 0.9f, 0.9f
);
private static final Anchor SKIP_TEXT_ANCHOR = new Anchor(
0.82f, 0.1f, 0.87f, 0.9f
);
private static final Anchor INFO_TEXT_ANCHOR = new Anchor(
0.62f, 0.1f, 0.68f, 0.9f
);
private static final Anchor LIKE_ICO_ANCHOR = new Anchor(
0.72f, 0.35f, 0.78f, 0.48f
);
private static final Anchor LIKE_TEXT_ANCHOR = new Anchor(
0.72f, 0.5f, 0.77f, 0.68f
);

public static final long COST = 30;

private final DataLoader.DataBlock block;


Expand All @@ -46,30 +69,76 @@ private GameObject createEnergyButton() {
45.0f,
45.0f,
ENERGY_BTN_ANCHOR,
null
() -> {
block.numLikes -= COST;
GameView.setDataBlock(block);
SceneManager.getInstance().cmdChangeScene(new InGameScene(true));
}
);
}

private GameObject createSpannerButton() {
private GameObject createEnergyButtonIcon() {
return new UiImageObject(R.mipmap.item_energy, ENERGY_ICO_ANCHOR);
}

private GameObject createSkipButton() {
return new UiButtonObject(
Color.argb(218, 250, 250, 250),
Color.argb(218, 218, 218, 218),
45.0f,
45.0f,
SPANNER_BTN_ANCHOR,
null
SKIP_BTN_ANCHOR,
() -> {
SceneManager.getInstance().cmdChangeScene(new InGameScene());
}
);
}

private GameObject createSkipButtonText() {
return new UiTextObject(
R.string.boost_btn_skip_text,
SKIP_TEXT_ANCHOR,
UiTextObject.Pivot.Vertical
);
}

@SuppressLint("DefaultLocale")
private GameObject createInfoText() {
String costText = GameView.getStringFromRes(R.string.boost_cost_text);
String text = String.format("%s:%d", costText, COST);
return new UiTextObject(
text,
INFO_TEXT_ANCHOR,
UiTextObject.Pivot.Vertical
);
}

private GameObject createLikeIcon() {
return new UiImageObject(R.mipmap.item_like, LIKE_ICO_ANCHOR);
}

@SuppressLint("DefaultLocale")
private GameObject createLikeScoreText(long numLikes) {
String text = String.format("%03d", numLikes);
return new UiTextObject(text, LIKE_TEXT_ANCHOR, UiTextObject.Pivot.Vertical);
}

@Override
public void onEnter() {
Log.d(TAG, "::onEnter >> 장면에 진입함");

insertObject(Tags.Background, createBackground());

insertObject(Tags.Button, createEnergyButton());
insertObject(Tags.Text, createEnergyButtonIcon());

insertObject(Tags.Button, createSkipButton());
insertObject(Tags.Text, createSkipButtonText());

insertObject(Tags.Text, createInfoText());

insertObject(Tags.Button, createSpannerButton());
insertObject(Tags.Icon, createLikeIcon());
insertObject(Tags.Text, createLikeScoreText(block.numLikes));

Sound.resumeAllSounds();
}
Expand Down
24 changes: 21 additions & 3 deletions app/src/main/java/com/hk416/fallingdowntino/scene/InGameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import androidx.annotation.NonNull;

import com.hk416.fallingdowntino.R;
import com.hk416.fallingdowntino.object.tino.Tino;
import com.hk416.fallingdowntino.object.ui.DurabilityUi;
import com.hk416.fallingdowntino.object.ui.LikeUi;
Expand All @@ -27,12 +28,17 @@ public final class InGameScene extends GameScene {
public enum Tags { Object, Item, Player, Ui }

private final PauseScene pauseScene = new PauseScene();

private final boolean boost;
private Player player;


public InGameScene() {
super(Tags.values().length);
boost = false;
}

public InGameScene(boolean boost) {
super(Tags.values().length);
this.boost = boost;
}

private void setupDrawPipeline() {
Expand All @@ -43,6 +49,12 @@ private void setupDrawPipeline() {

private void setupObjects() {
player = new Player();
if (boost) {
player.setInvincibleTimer(Tino.INVINCIBLE_DURATION);
player.setCurrDownSpeed(Player.MAX_DOWN_SPEED);
player.setBehaviors(Tino.Behavior.RightInvincible, null);
}

insertObject(Tags.Player, player);
insertObject(Tags.Object, new BlockPool(
MainCamera.PROJ_LEFT,
Expand Down Expand Up @@ -70,7 +82,13 @@ public void onEnter() {
setupDrawPipeline();
setupObjects();
setupUserInterface();
Sound.resumeAllSounds();

if (boost) {
Sound.pauseMusic();
Sound.playEffect(R.raw.effect1);
} else {
Sound.resumeAllSounds();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void onUpdate(float elapsedTimeSec, long frameRate) {

if (timer >= DURATION) {
DataLoader.DataBlock block = GameView.getDataBlock();
if (block.numLikes > 30) {
if (block.numLikes > BoostGameScene.COST) {
SceneManager.getInstance().cmdPushScene(new BoostGameScene(block));
} else {
SceneManager.getInstance().cmdChangeScene(new InGameScene());
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
<string name="title_best_text">최고기록</string>
<string name="pause_main_text">일시정지</string>
<string name="pause_sub_text">화면을 터치해서 계속하기</string>
<string name="boost_btn_skip_text">생략하기</string>
<string name="boost_cost_text">비용</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<string name="title_best_text">Best</string>
<string name="pause_main_text">Pause</string>
<string name="pause_sub_text">Tap the screen to continue</string>
<string name="boost_btn_skip_text">Skip</string>
<string name="boost_cost_text">Cost</string>
</resources>

0 comments on commit 24bb573

Please sign in to comment.