Skip to content

Commit d158ca2

Browse files
committed
[2D/android_accelerometer] finished
1 parent b955905 commit d158ca2

14 files changed

+75
-12
lines changed

2D/android_accelerometer/ball.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extends RigidBody2D
2+
3+
var sprites = ["res://sprites/alienBeige_round.png", "res://sprites/alienBlue_round.png",
4+
"res://sprites/alienGreen_round.png", "res://sprites/alienPink_round.png", "res://sprites/alienYellow_round.png"]
5+
6+
# Called when the node enters the scene tree for the first time.
7+
func _ready():
8+
$ball.texture = load(sprites[int(rand_range(0, sprites.size()))])
9+
10+

2D/android_accelerometer/ball.tscn

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
[gd_scene load_steps=3 format=2]
1+
[gd_scene load_steps=4 format=2]
22

3-
[ext_resource path="res://circle.png" type="Texture" id=1]
3+
[ext_resource path="res://ball.gd" type="Script" id=1]
4+
[ext_resource path="res://sprites/alienBeige_round.png" type="Texture" id=2]
45

56
[sub_resource type="CircleShape2D" id=1]
6-
radius = 25.0
7+
radius = 54.9893
78

89
[node name="Ball" type="RigidBody2D"]
910
continuous_cd = 1
11+
script = ExtResource( 1 )
1012

1113
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
1214
shape = SubResource( 1 )
1315

14-
[node name="clipart276462" type="Sprite" parent="."]
15-
scale = Vector2( 0.0409951, 0.0409951 )
16-
texture = ExtResource( 1 )
16+
[node name="ball" type="Sprite" parent="."]
17+
position = Vector2( -2.14577e-06, -2.25008e-06 )
18+
scale = Vector2( 1.56107, 1.56107 )
19+
texture = ExtResource( 2 )

2D/android_accelerometer/circle.png

-463 KB
Binary file not shown.

2D/android_accelerometer/game.gd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ const ball = preload("res://ball.tscn")
44

55
onready var balls_container = $Balls
66

7+
const EARTH_GRAVITY = 9.8
8+
79
# Called when the node enters the scene tree for the first time.
810
func _ready():
9-
pass # Replace with function body.
11+
var gravity_strength = Physics2DServer.area_get_param(get_viewport().find_world_2d().get_space(), Physics2DServer.AREA_PARAM_GRAVITY)
12+
print(gravity_strength)
1013

1114
func _process(delta):
1215
var accel = Input.get_accelerometer()
1316
if accel:
14-
print(accel)
17+
#print(accel)
18+
var gravity_vector = Vector2(accel.x/EARTH_GRAVITY, -accel.y/EARTH_GRAVITY)
19+
Physics2DServer.area_set_param(get_viewport().find_world_2d().get_space(), Physics2DServer.AREA_PARAM_GRAVITY_VECTOR, gravity_vector)
1520

1621
func _unhandled_input(event):
1722
if event is InputEventScreenTouch and event.is_pressed():

2D/android_accelerometer/game.tscn

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,76 @@
1-
[gd_scene load_steps=4 format=2]
1+
[gd_scene load_steps=7 format=2]
22

33
[ext_resource path="res://game.gd" type="Script" id=1]
4+
[ext_resource path="res://sprites/platformPack_tilesheet.png" type="Texture" id=2]
45

56
[sub_resource type="RectangleShape2D" id=1]
67
extents = Vector2( 20, 960 )
78

89
[sub_resource type="RectangleShape2D" id=2]
910
extents = Vector2( 540, 21 )
1011

12+
[sub_resource type="ConvexPolygonShape2D" id=4]
13+
points = PoolVector2Array( 0, 0, 64, 0, 64, 64, 0, 64 )
14+
15+
[sub_resource type="TileSet" id=3]
16+
0/name = "platformPack_tilesheet.png 0"
17+
0/texture = ExtResource( 2 )
18+
0/tex_offset = Vector2( 0, 0 )
19+
0/modulate = Color( 1, 1, 1, 1 )
20+
0/region = Rect2( 384, 64, 64, 64 )
21+
0/tile_mode = 0
22+
0/occluder_offset = Vector2( 0, 0 )
23+
0/navigation_offset = Vector2( 0, 0 )
24+
0/shape_offset = Vector2( 0, 0 )
25+
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
26+
0/shape = SubResource( 4 )
27+
0/shape_one_way = false
28+
0/shape_one_way_margin = 1.0
29+
0/shapes = [ {
30+
"autotile_coord": Vector2( 0, 0 ),
31+
"one_way": false,
32+
"one_way_margin": 1.0,
33+
"shape": SubResource( 4 ),
34+
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
35+
} ]
36+
0/z_index = 0
37+
1138
[node name="Game" type="Node2D"]
1239
script = ExtResource( 1 )
1340

1441
[node name="Walls" type="Node" parent="."]
1542

1643
[node name="StaticBody2D" type="StaticBody2D" parent="Walls"]
44+
visible = false
1745
position = Vector2( -18, 960 )
1846

1947
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D"]
2048
shape = SubResource( 1 )
2149

2250
[node name="StaticBody2D2" type="StaticBody2D" parent="Walls"]
51+
visible = false
2352
position = Vector2( 1095, 960 )
2453

2554
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D2"]
2655
shape = SubResource( 1 )
2756

2857
[node name="StaticBody2D3" type="StaticBody2D" parent="Walls"]
58+
visible = false
2959
position = Vector2( 540, 0 )
3060

3161
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D3"]
3262
shape = SubResource( 2 )
3363

3464
[node name="StaticBody2D4" type="StaticBody2D" parent="Walls"]
65+
visible = false
3566
position = Vector2( 540, 1920 )
3667

3768
[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/StaticBody2D4"]
3869
shape = SubResource( 2 )
3970

4071
[node name="Balls" type="Node" parent="."]
72+
73+
[node name="TileMap" type="TileMap" parent="."]
74+
tile_set = SubResource( 3 )
75+
format = 1
76+
tile_data = PoolIntArray( 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 65536, 0, 0, 65552, 0, 0, 131072, 0, 0, 131088, 0, 0, 196608, 0, 0, 196624, 0, 0, 262144, 0, 0, 262160, 0, 0, 327680, 0, 0, 327696, 0, 0, 393216, 0, 0, 393232, 0, 0, 458752, 0, 0, 458768, 0, 0, 524288, 0, 0, 524304, 0, 0, 589824, 0, 0, 589840, 0, 0, 655360, 0, 0, 655376, 0, 0, 720896, 0, 0, 720912, 0, 0, 786432, 0, 0, 786448, 0, 0, 851968, 0, 0, 851984, 0, 0, 917504, 0, 0, 917520, 0, 0, 983040, 0, 0, 983056, 0, 0, 1048576, 0, 0, 1048592, 0, 0, 1114112, 0, 0, 1114128, 0, 0, 1179648, 0, 0, 1179664, 0, 0, 1245184, 0, 0, 1245200, 0, 0, 1310720, 0, 0, 1310736, 0, 0, 1376256, 0, 0, 1376272, 0, 0, 1441792, 0, 0, 1441808, 0, 0, 1507328, 0, 0, 1507344, 0, 0, 1572864, 0, 0, 1572880, 0, 0, 1638400, 0, 0, 1638416, 0, 0, 1703936, 0, 0, 1703952, 0, 0, 1769472, 0, 0, 1769488, 0, 0, 1835008, 0, 0, 1835024, 0, 0, 1900544, 0, 0, 1900545, 0, 0, 1900546, 0, 0, 1900547, 0, 0, 1900548, 0, 0, 1900549, 0, 0, 1900550, 0, 0, 1900551, 0, 0, 1900552, 0, 0, 1900553, 0, 0, 1900554, 0, 0, 1900555, 0, 0, 1900556, 0, 0, 1900557, 0, 0, 1900558, 0, 0, 1900559, 0, 0, 1900560, 0, 0 )

2D/android_accelerometer/project.godot

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ _global_script_class_icons={
1717

1818
config/name="android_accelerometer"
1919
run/main_scene="res://game.tscn"
20+
boot_splash/bg_color=Color( 0, 0.027451, 0.0901961, 1 )
2021
config/icon="res://icon.png"
2122

2223
[display]
@@ -31,11 +32,12 @@ window/stretch/aspect="expand"
3132

3233
[physics]
3334

34-
2d/default_gravity=150
35+
2d/default_gravity=700
3536

3637
[rendering]
3738

3839
quality/driver/driver_name="GLES2"
3940
vram_compression/import_etc=true
4041
vram_compression/import_etc2=false
42+
environment/default_clear_color=Color( 0, 0.0313726, 0.101961, 1 )
4143
environment/default_environment="res://default_env.tres"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ASSETS: Kenney https://www.kenney.nl/
1.33 KB
Loading
1.28 KB
Loading
1.35 KB
Loading

0 commit comments

Comments
 (0)