반응형

보글보글 같은 플랫폼 게임에서 볼 수 있는 캐릭터와 플랫폼의 한 쪽 방향 충돌 체크를 구현해 보자.

 

화면과 같이 Sprite2D, StaticBody2D, CollisionShape2D를 이용해 배경과 바닥을 구성한다.

 

gound.jpg
0.20MB

 

화면과 같이 Sprite2D, StaticBody2D, CollisionShape2D를 이용해 플랫폼을 구성한다.

CollisionShape2D - One Way Collision 속성을 체크한다.

필요하다면 Sprite2D - Transform - Scale을 조절한다.

 

Platform.png
0.01MB

 

화면과 같이 CharacterBody2D, Sprite2D, CollisionShape2D를 이용해 플레이어를 구성한다.

플레이어는 스크립트를 추가한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Godot;
 
public partial class Player : CharacterBody2D
{
    public const float Speed = 300.0f;
    public const float JumpVelocity = -600.0f;
    // 플랫폼에 올라갈 수 있을 정도의 점프
 
    // Get the gravity from the project settings to be synced with RigidBody nodes.
    public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
 
    public override void _PhysicsProcess(double delta)
    {
        Vector2 velocity = Velocity;
 
        // Add the gravity.
        if (!IsOnFloor())
            velocity.Y += gravity * (float)delta;
 
        // Handle Jump.
        if (Input.IsActionJustPressed("ui_accept"&& IsOnFloor())
            velocity.Y = JumpVelocity;
 
        // 플랫폼에서 내려오기
        if (Input.IsActionJustPressed("ui_down"&& IsOnFloor())
            Position += new Vector2(01);
 
        // Get the input direction and handle the movement/deceleration.
        // As good practice, you should replace UI actions with custom gameplay actions.
        Vector2 direction = Input.GetVector("ui_left""ui_right""ui_up""ui_down");
        // direction 벡터는 키 입력이 반영되어 길이가 1인 normalized vector 값이 설정된다.
        // 예를들어 오른쪽 방향키가 눌렸다면 (1, 0), 아래 방향키가 눌렸다면 (0, 1),
        // 왼쪽+위 방향키가 눌렸다면 (-0.707, -0.707)이 설정된다.
        if (direction != Vector2.Zero)
        {
            velocity.X = direction.X * Speed;
        }
        else
        {
            velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
        }
 
        Velocity = velocity;
        MoveAndSlide();
    }
}
 

 

 

플레이어 스크립트를 위와 같이 작성한다.

 

그라운드, 플랫폼, 플레이어로 메인 씬을 구성한다.

 

게임을 실행하고 플랫폼에서 동작을 테스트 한다.

 

※ 참고

Using CharacterBody2d/3D

CharacterBody2D

 

반응형
Posted by J-sean
:
반응형

네이버 클라우드 플랫폼의 지오코딩을 사용해 보자.

 

xml 리소스 폴더를 만들고 network_security_config.xml 파일을 생성한다.

 

AndroidManifest.xml에 인터넷 권한과 networkSecurityConfig 옵션을 추가한다.

 

리니어 레이아웃에 텍스트뷰와 버튼을 적당히 배치한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.example.myapplication;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
 
public class MainActivity extends AppCompatActivity {
 
    TextView textView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        textView = findViewById(R.id.textView);
 
        Button button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        requestGeocode();
                    }
                }).start();
            }
        });
    }
 
    public void requestGeocode() {
        try {
            BufferedReader bufferedReader;
            StringBuilder stringBuilder = new StringBuilder();
            String addr = "분당구 성남대로 601";
            String query = "https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query=" + URLEncoder.encode(addr, "UTF-8");
            URL url = new URL(query);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            if (conn != null) {
                conn.setConnectTimeout(5000);
                conn.setReadTimeout(5000);
                conn.setRequestMethod("GET");
                conn.setRequestProperty("X-NCP-APIGW-API-KEY-ID""Client ID");
                conn.setRequestProperty("X-NCP-APIGW-API-KEY""Client Secret");
                conn.setDoInput(true);
 
                int responseCode = conn.getResponseCode();
 
                if (responseCode == 200) {
                    bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                } else {
                    bufferedReader = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
                }
 
                String line = null;
                while ((line = bufferedReader.readLine()) != null) {
                    stringBuilder.append(line + "\n");
                }
                //textView.setText(stringBuilder);
 
                int indexFirst;
                int indexLast;
 
                indexFirst = stringBuilder.indexOf("\"x\":\"");
                indexLast = stringBuilder.indexOf("\",\"y\":");
                String x = stringBuilder.substring(indexFirst + 5, indexLast);
 
                indexFirst = stringBuilder.indexOf("\"y\":\"");
                indexLast = stringBuilder.indexOf("\",\"distance\":");
                String y = stringBuilder.substring(indexFirst + 5, indexLast);
 
                textView.setText("X: " + x + ", " + "Y: " + y);
 
                bufferedReader.close();
                conn.disconnect();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 

 

MainActivity.java에 위 소스를 입력하고 빌드한다. '분당구 성남대로 601'의 주소 정보를 여러가지 데이터가 포함된 JSON 포맷으로 가져와 간단한 문자열 조작으로 GPS 좌표만 추출한다.

 

 

앱을 실행시키고 버튼을 터치하면 '분당구 성남대로 601'의 GPS 좌표가 표시된다.

 

구글 맵에서 GPS 좌표를 확인해 보자. 서현역이다.

 

아래와 같은 양식의 curl 명령으로도 동일한 JSON 데이터를 얻을 수 있다.

curl -G "https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query=%EB%B6%84%EB%8B%B9%EA%B5%AC%20%EC%84%B1%EB%82%A8%EB%8C%80%EB%A1%9C%20601" -H "X-NCP-APIGW-API-KEY-ID: Client ID" -H "X-NCP-APIGW-API-KEY: Client Secret"

※ query에는 주소를 url encoding한 값을 대입한다.

분당구 성남대로 601 = %EB%B6%84%EB%8B%B9%EA%B5%AC%20%EC%84%B1%EB%82%A8%EB%8C%80%EB%A1%9C%20601

 

아래와 같은 양식으로 웹브라우저 주소창에 입력해도 동일한 JSON 데이터를 얻을 수 있다.

https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query=분당구 성남대로 601&X-NCP-APIGW-API-KEY-ID=[Client ID]&X-NCP-APIGW-API-KEY=[Client Secret]

 

 

반응형
Posted by J-sean
:

Qt platform plugin error fix

C, C++ 2021. 9. 26. 15:14 |
반응형

Qt로 작성된 프로그램을 Qt Creator에서 실행하면 잘 되지만 실행 파일을 직접 실행하면 아래와 같은 에러가 발생한다.

 

 

This application failed to start because no Qt platform plugin could be initialized. 라는 메세지에서 알 수 있는 것 처럼 platform plugin이 없기 때문이다.

 

Qt 설치 폳더에서 platforms 폴더를 복사한다.

 

실행 파일이 있는 폴더에 붙여 넣는다.

Debug, Release 모두 동일하다.

그 외, 필요한 dll 파일도 모두 복사해 넣고 실행하면 문제없이 실행된다.

 

반응형
Posted by J-sean
:
반응형

Google Cloud Platform(GCP) 의 무료 프로그램을 이용하면 간단한 리눅스 서버를 만들 수 있다.

 

2019.10.11 - [Linux] - Google Cloud Platform Always Free Linux Web Server 구글 클라우드 플랫폼으로 무료 리눅스 웹서버 만들기

 

위 링크의 예전 방법과 비슷하지만 무료 프로그램 조건이 약간 변경 되었다.

 

GCP - Compute Engine - VM instances를 클릭한다.

 

CREATE INSTANCE를 클릭한다.

 

우선 무료 Compute Engine의 조건을 확인해 보자.

Google Cloud 무료 프로그램

 

 

무료 프로그램 조건에 맞게 설정하고 Create 버튼을 클릭한다.

  • Name: 원하는 이름으로 지정한다.
  • Region: 아래 목록중 하나를 선택한다.
    - Oregon: us-west1
    - Iowa: us-central1
    - South Carolina: us-east1
  • Machine family: General-purpose
  • Series: E2
  • Machine type: e2-micro (2 vCPU, 1 GB memory)
  • Boot disk: standard persistent disk로 최대 30GB 까지 선택 가능.
  • Firewall: 웹서버를 설치한다면 Allow HTTP/HTTPS traffic을 선택한다.

 

Instance가 생성 되었다. Connect - SSH 를 클릭한다.

 

생성된 Instance에 연결 되었다.

 

반응형
Posted by J-sean
: