0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Godot開発日記 - ②障害物ゲーム

Posted at

はじめに

Godot初心者が簡単なミニゲームを作って勉強する

環境

  • Godot4.4

仕様書

  • 右から流れてくる障害物をジャンプで回避するゲーム
  • 衝突したら左に押し出される
  • 左端に到達したらゲームオーバー
  • 障害物は動物2種類×大小の4種類

素材

成果物

https://geekman4040.itch.io/demoapp
(Game2をクリックして起動)

実装

スクリプト

次のパラメータを使い分けて実装

  • next_spawn_time: 次に動物がスポーンするまでの時間
  • start: ゲーム起動判定
func _process(delta: float) -> void:
	if start:
		next_spawn_time -= delta
		if next_spawn_time <= 0.0:
			_spawn_obstacle()
			_reset_spawn_timer()

func _spawn_obstacle() -> void:
	if obstacle_scenes.is_empty():
		return
	# ランダムにシーンを選ぶ
	var num = randi() % obstacle_scenes.size()
	var scene: PackedScene = obstacle_scenes[num]
	var obstacle = scene.instantiate()
	# 画面右端あたりに出現させる(y座標は種類ごとに調整しても良い)
	var pos_y
	if (num % 2 == 0):
		pos_y = 250
	else:
		pos_y =  235
	var spawn_position = Vector2(500, pos_y) # 仮: 画面右下あたり
	obstacle.position = spawn_position
	add_child(obstacle)

func _reset_spawn_timer() -> void:
	# min_interval + ランダムな遅延で次回出現時間を決定
	next_spawn_time = min_interval + randf_range(0, variance)

使ったノードたち

  • CharacterBody2D: プレイヤーの移動操作
  • StaticBody2D: 地面と障害物の当たり判定
  • Timer: スコア用

所要時間

2.5時間
※素材収集、エクスポート作業を除く

感想

今回はチャリ走のオマージュゲームです。
PhysicsBody2Dの子クラスたち(CharacterBody2D, StaticBody2D)の使い方を学べました。
また、各種素材(背景、ボタン)の画像生成にも着手しました。
そろそろゲームバランスやゲーム性に時間をかけたいところ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?