Sorted things out

This commit is contained in:
Mikołaj Lubiak 2022-12-15 19:48:20 +01:00
parent 3a2931bf9e
commit 0b560ba074
12 changed files with 353 additions and 0 deletions

37
Scenes/Bullet.tscn Normal file
View File

@ -0,0 +1,37 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://Script/Bullet.gd" type="Script" id=1]
[ext_resource path="res://Sprites/bullet.png" type="Texture" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 4, 8.5 )
[sub_resource type="GDScript" id=3]
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 5, 9.5 )
[node name="Bullet" type="RigidBody2D"]
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 76.704, 3 )
scale = Vector2( 2.15162, 0.446 )
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 100, 7 )
rotation = -1.5708
texture = ExtResource( 2 )
[node name="Area2D" type="Area2D" parent="."]
position = Vector2( 69.733, 15.448 )
scale = Vector2( 1.726, 0.454 )
script = SubResource( 3 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2( 4, -27.5 )
shape = SubResource( 2 )
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
[connection signal="body_shape_entered" from="Area2D" to="." method="_on_Area2D_body_shape_entered"]

30
Scenes/Enemy.tscn Normal file
View File

@ -0,0 +1,30 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Sprites/player.png" type="Texture" id=1]
[ext_resource path="res://Script/Enemy.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 16, 16.5 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 23, 19.5 )
[node name="Enemy" type="KinematicBody2D"]
script = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, -0.5 )
shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="."]
modulate = Color( 1, 0, 0, 1 )
rotation = 1.56981
texture = ExtResource( 1 )
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2( 0, -0.5 )
shape = SubResource( 2 )
[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]

105
Scenes/Main.tscn Normal file
View File

@ -0,0 +1,105 @@
[gd_scene load_steps=11 format=2]
[ext_resource path="res://Scenes/wall.tres" type="TileSet" id=1]
[ext_resource path="res://Sprites/weapon.png" type="Texture" id=2]
[ext_resource path="res://Sprites/grass.png" type="Texture" id=3]
[ext_resource path="res://Sprites/player.png" type="Texture" id=4]
[ext_resource path="res://Sprites/light.png" type="Texture" id=5]
[ext_resource path="res://Script/movement.gd" type="Script" id=6]
[ext_resource path="res://Script/SceneSpawner.gd" type="Script" id=7]
[sub_resource type="GDScript" id=3]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 36.4995, 55.7176 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 20, 24 )
[node name="World" type="Node2D"]
position = Vector2( 6, -10 )
z_as_relative = false
script = ExtResource( 7 )
[node name="Ground" type="Node2D" parent="."]
[node name="grass" type="Sprite" parent="Ground"]
texture = ExtResource( 3 )
script = SubResource( 3 )
[node name="grass2" type="Sprite" parent="Ground"]
position = Vector2( 650, 0 )
texture = ExtResource( 3 )
[node name="grass3" type="Sprite" parent="Ground"]
position = Vector2( 0, 600 )
texture = ExtResource( 3 )
[node name="grass4" type="Sprite" parent="Ground"]
position = Vector2( 650, 600 )
texture = ExtResource( 3 )
[node name="grass5" type="Sprite" parent="Ground"]
position = Vector2( 1300, 600 )
texture = ExtResource( 3 )
[node name="grass6" type="Sprite" parent="Ground"]
position = Vector2( 1300, 0 )
texture = ExtResource( 3 )
[node name="Map" type="Node2D" parent="."]
[node name="TileMap" type="TileMap" parent="Map"]
position = Vector2( -1, -2 )
scale = Vector2( 0.5, 0.5 )
tile_set = ExtResource( 1 )
format = 1
tile_data = PoolIntArray( -1245213, -1073741824, 0, -1245204, -1073741824, 0, -1245195, -1073741824, 0, -1245186, -1073741824, 0, -1310713, -1073741824, 0, -1310704, -1073741824, 0, -1310688, -1073741824, 0, -1310679, -1073741824, 0, -1310670, -1073741824, 0, -1310661, -1073741824, 0, -1310660, -1073741824, 0, -1245125, -1073741824, 0, -589853, -1073741824, 0, -589844, -1073741824, 0, -655309, -1073741824, 0, -655300, -1073741824, 0, 51, -1073741824, 0, 60, -1073741824, 0, 589795, -1073741824, 0, 589804, -1073741824, 0, 655411, -1073741824, 0, 655420, -1073741824, 0, 1245155, -1073741824, 0, 1245164, -1073741824, 0, 1900515, -1073741824, 0, 1900517, -1073741824, 0, 1900526, -1073741824, 0, 1900534, -1073741824, 0, 1900535, 0, 0, 1900543, -1073741824, 0, 1835009, 0, 0, 1835016, -1073741824, 0, 1835019, 0, 0, 1835025, -1073741824, 0, 1835029, 0, 0, 1835034, -1073741824, 0, 1835039, 0, 0, 1835043, -1073741824, 0, 1835049, 0, 0, 1835052, -1073741824, 0, 1835059, -1073741824, 0, 1835068, -1073741824, 0 )
[node name="TileMap2" type="TileMap" parent="Map"]
scale = Vector2( 0.1, 0.1 )
tile_set = ExtResource( 1 )
format = 1
tile_data = PoolIntArray( -3145626, -1073741824, 0, -2490266, -1073741824, 0, -1834906, -1073741824, 0, -1179546, -1073741824, 0, -524186, -1073741824, 0, 180, -1073741824, 0, 189, -1073741824, 0, 198, -1073741824, 0, 204, -1073741824, 0, 208, -1073741824, 0, 217, -1073741824, 0, 226, -1073741824, 0, 235, -1073741824, 0, 244, -1073741824, 0, 246, -1073741824, 0, 131174, -1073741824, 0, 655540, -1073741824, 0, 786534, -1073741824, 0, 1310900, -1073741824, 0, 1966260, -1073741824, 0, 2621620, -1073741824, 0, 3276971, -1073741824, 0, 3276980, -1073741824, 0, 3866572, -1073741824, 0, 3866581, -1073741824, 0, 3866590, -1073741824, 0, 3866599, -1073741824, 0, 3866608, -1073741824, 0, 3866617, -1073741824, 0, 3801090, -1073741824, 0, 3801099, -1073741824, 0, 4718763, -1073741824, 0, 4718772, -1073741824, 0, 5177402, -1073741824, 0, 5374132, -1073741824, 0, 5832762, -1073741824, 0, 6029492, -1073741824, 0, 6029501, -1073741824, 0, 6029508, -1073741824, 0, 6029511, -1073741824, 0, 6029517, -1073741824, 0, 6029521, -1073741824, 0, 6029530, -1073741824, 0, 6029539, -1073741824, 0, 6029548, -1073741824, 0, 6029557, -1073741824, 0, 6029559, 1610612736, 0, 6488122, -1073741824, 0, 7143482, -1073741824, 0, 7798842, -1073741824, 0, 8454202, -1073741824, 0, 8585274, -1073741824, 0 )
[node name="Player" type="KinematicBody2D" parent="."]
position = Vector2( 539, 334 )
script = ExtResource( 6 )
[node name="Light2D" type="Light2D" parent="Player"]
position = Vector2( -1, 2 )
texture = ExtResource( 5 )
color = Color( 1, 0.878431, 0.0745098, 1 )
energy = 0.5
shadow_enabled = true
shadow_buffer_size = 4096
shadow_filter_smooth = 64.0
[node name="Sprite" type="Sprite" parent="Player"]
position = Vector2( 0, 1 )
rotation = 1.56962
texture = ExtResource( 4 )
[node name="weapon" type="Sprite" parent="Player"]
position = Vector2( 35, 3 )
rotation = 1.5708
texture = ExtResource( 2 )
[node name="Camera2D" type="Camera2D" parent="Player"]
position = Vector2( 2, 1 )
current = true
smoothing_enabled = true
smoothing_speed = 10.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"]
position = Vector2( 0, 1.5 )
scale = Vector2( 0.493156, -0.314084 )
shape = SubResource( 1 )
[node name="Area2D" type="Area2D" parent="Player"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player/Area2D"]
position = Vector2( 0, 1 )
shape = SubResource( 2 )
[connection signal="body_entered" from="Player/Area2D" to="Player" method="_on_Area2D_body_entered"]

7
Scenes/default_env.tres Normal file
View File

@ -0,0 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )

33
Scenes/wall.tres Normal file
View File

@ -0,0 +1,33 @@
[gd_resource type="TileSet" load_steps=4 format=2]
[ext_resource path="res://Sprites/grass.png" type="Texture" id=1]
[sub_resource type="OccluderPolygon2D" id=1]
polygon = PoolVector2Array( -338, -312, -337, 312, 337, 312, 338, -313 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 337.5, 312 )
[resource]
0/name = "Sprite"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 0.588235, 0.392157, 0.588235, 1 )
0/region = Rect2( 0, 0, 674, 624 )
0/tile_mode = 0
0/occluder_offset = Vector2( 337, 312 )
0/occluder = SubResource( 1 )
0/navigation_offset = Vector2( 337, 312 )
0/shape_offset = Vector2( 337.5, 312 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 337.5, 312 )
0/shape = SubResource( 2 )
0/shape_one_way = false
0/shape_one_way_margin = 1.0
0/shapes = [ {
"autotile_coord": Vector2( 0, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 2 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 337.5, 312 )
} ]
0/z_index = 0

25
Scenes/wall.tscn Normal file
View File

@ -0,0 +1,25 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Sprites/grass.png" type="Texture" id=1]
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 337.5, 312 )
[sub_resource type="OccluderPolygon2D" id=1]
polygon = PoolVector2Array( -338, -312, -337, 312, 337, 312, 338, -313 )
[node name="Node2D" type="Node2D"]
[node name="Sprite" type="Sprite" parent="."]
modulate = Color( 0.588235, 0.392157, 0.588235, 1 )
scale = Vector2( 0.1, 0.1 )
texture = ExtResource( 1 )
[node name="StaticBody2D" type="StaticBody2D" parent="Sprite"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Sprite/StaticBody2D"]
position = Vector2( 0.5, 0 )
shape = SubResource( 2 )
[node name="LightOccluder2D" type="LightOccluder2D" parent="Sprite"]
occluder = SubResource( 1 )

5
Script/Bullet.gd Normal file
View File

@ -0,0 +1,5 @@
extends RigidBody2D
func _on_Area2D_body_entered(body):
if "Enemy" in body.name:
queue_free()

17
Script/Enemy.gd Normal file
View File

@ -0,0 +1,17 @@
extends KinematicBody2D
var motion = Vector2()
func _ready():
pass # Replace with function body.
func _physics_process(delta):
var Player = get_parent().get_node("Player")
position += (Player.position - position) / 50
look_at(Player.position)
move_and_collide(motion)
func _on_Area2D_body_entered(body):
if "Bullet" in body.name:
queue_free()

22
Script/SceneSpawner.gd Normal file
View File

@ -0,0 +1,22 @@
extends Node
func _ready():
var rand = RandomNumberGenerator.new()
var enemyscene = load("res://Scenes/Enemy.tscn")
var screen_size = get_viewport().get_visible_rect().size
for i in range(0,10):
var enemy = enemyscene.instance()
rand.randomize()
var x = rand.randf_range(0, screen_size.x)
rand.randomize()
var y = rand.randf_range(0, screen_size.y)
enemy.position.y = y
enemy.position.x = x
add_child(enemy)
func _on_Area2D_body_entered(body):
if "Bullet" in body.name:
queue_free()

37
Script/movement.gd Normal file
View File

@ -0,0 +1,37 @@
extends KinematicBody2D
var speed = 300
var bullet_speed = 2000
var bullet = preload("res://Scenes/Bullet.tscn")
func _physics_process(delta):
var motion = Vector2()
if Input.is_action_pressed("ui_right"):
motion.x += 1
if Input.is_action_pressed("ui_left"):
motion.x -= 1
if Input.is_action_pressed("ui_down"):
motion.y += 1
if Input.is_action_pressed("ui_up"):
motion.y -= 1
motion = motion.normalized()
motion = move_and_slide(motion * speed)
look_at(get_global_mouse_position())
if Input.is_action_just_pressed("LMB"):
fire()
func fire():
var bullet_instance = bullet.instance()
bullet_instance.position = get_global_position()
bullet_instance.rotation_degrees = rotation_degrees
bullet_instance.apply_impulse(Vector2(), Vector2(bullet_speed, 0).rotated(rotation))
get_tree().get_root().call_deferred("add_child", bullet_instance)
func kill():
get_tree().reload_current_scene()
func _on_Area2D_body_entered(body):
if "Enemy" in body.name:
kill()

BIN
Sprites/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

35
Sprites/icon.png.import Normal file
View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-f9ba9008f31679cd240e2c5f33a9a4fb.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/icon.png"
dest_files=[ "res://.import/icon.png-f9ba9008f31679cd240e2c5f33a9a4fb.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0