From 7d86ed5935622a3ea083d75e565deb524017d8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20H=C3=BCbner?= Date: Thu, 22 Jun 2017 16:49:55 +0200 Subject: [PATCH] add scraps from other test project for now, bounce off this --- Box.gd | 10 +++++++++ Box.tscn | 35 +++++++++++++++++++++++++++++++ Bullet.gd | 23 ++++++++++++++++++++ Bullet.tscn | 33 +++++++++++++++++++++++++++++ Enemy.gd | 37 +++++++++++++++++++++++++++++++++ Enemy.tscn | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Game.gd | 4 ++++ Game.tscn | 27 +++++++++++++++++++++--- Player.gd | 40 +++++++++++++++++++++++++++++++++++ Player.tscn | 48 ++++++++++++++++++++++++++++++------------ box.png | 3 +++ bullet.png | 3 +++ endown.png | 3 +++ engine.cfg | 19 ++++++++--------- enleft.png | 3 +++ enright.png | 3 +++ enup.png | 3 +++ player.png | 3 +++ pointer.png | 3 +++ 19 files changed, 334 insertions(+), 26 deletions(-) create mode 100644 Box.gd create mode 100644 Box.tscn create mode 100644 Bullet.gd create mode 100644 Bullet.tscn create mode 100644 Enemy.gd create mode 100644 Enemy.tscn create mode 100644 Game.gd create mode 100644 Player.gd create mode 100644 box.png create mode 100644 bullet.png create mode 100644 endown.png create mode 100644 enleft.png create mode 100644 enright.png create mode 100644 enup.png create mode 100644 player.png create mode 100644 pointer.png diff --git a/Box.gd b/Box.gd new file mode 100644 index 0000000..bc3d98b --- /dev/null +++ b/Box.gd @@ -0,0 +1,10 @@ +extends StaticBody2D + +# class member variables go here, for example: +# var a = 2 +# var b = "textvar" + +func _ready(): + # Called every time the node is added to the scene. + # Initialization here + pass diff --git a/Box.tscn b/Box.tscn new file mode 100644 index 0000000..c69a38d --- /dev/null +++ b/Box.tscn @@ -0,0 +1,35 @@ +[gd_scene load_steps=4 format=1] + +[ext_resource path="res://Box.gd" type="Script" id=1] +[ext_resource path="res://box.png" type="Texture" id=2] + +[sub_resource type="RectangleShape2D" id=1] + +custom_solver_bias = 0.0 +extents = Vector2( 24.7036, 30.1941 ) + +[node name="Box" type="StaticBody2D"] + +input/pickable = false +shapes/0/shape = SubResource( 1 ) +shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 ) +shapes/0/trigger = false +collision/layers = 1 +collision/mask = 1 +constant_linear_velocity = Vector2( 0, 0 ) +constant_angular_velocity = 0.0 +friction = 1.0 +bounce = 0.0 +script/script = ExtResource( 1 ) + +[node name="Sprite" type="Sprite" parent="."] + +texture = ExtResource( 2 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] + +shape = SubResource( 1 ) +trigger = false +_update_shape_index = 0 + + diff --git a/Bullet.gd b/Bullet.gd new file mode 100644 index 0000000..d3675cc --- /dev/null +++ b/Bullet.gd @@ -0,0 +1,23 @@ +extends Area2D + +var velocity = Vector2(0, 0) +var bullet_velocity = 5 + +func _ready(): + connect("body_enter", self, "bullet_enter_body") + set_collision_mask_bit(1, false) + set_fixed_process(true) + +func bullet_enter_body(body): + if body.has_method("take_damage"): + body.take_damage(1) + queue_free() + +func bullet_left_scene(): + queue_free() + +func set_bullet_velocity(rel, dir): + velocity = rel + dir * bullet_velocity + +func _fixed_process(delta): + translate(velocity) diff --git a/Bullet.tscn b/Bullet.tscn new file mode 100644 index 0000000..3b807e4 --- /dev/null +++ b/Bullet.tscn @@ -0,0 +1,33 @@ +[gd_scene load_steps=4 format=1] + +[ext_resource path="res://Bullet.gd" type="Script" id=1] +[ext_resource path="res://bullet.png" type="Texture" id=2] + +[sub_resource type="CircleShape2D" id=1] + +custom_solver_bias = 0.0 +radius = 7.81268 + +[node name="Bullet" type="Area2D"] + +input/pickable = false +shapes/0/shape = SubResource( 1 ) +shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 ) +shapes/0/trigger = false +gravity_vec = Vector2( 0, 1 ) +gravity = 98.0 +linear_damp = 0.1 +angular_damp = 1.0 +script/script = ExtResource( 1 ) + +[node name="Sprite" type="Sprite" parent="."] + +texture = ExtResource( 2 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] + +shape = SubResource( 1 ) +trigger = false +_update_shape_index = 0 + + diff --git a/Enemy.gd b/Enemy.gd new file mode 100644 index 0000000..13f4427 --- /dev/null +++ b/Enemy.gd @@ -0,0 +1,37 @@ +extends KinematicBody2D + +# class member variables go here, for example: +# var a = 2 +# var b = "textvar" +var ani_sprite +var health = 100 + +func _ready(): + # Called every time the node is added to the scene. + # Initialization here + ani_sprite = get_node("AnimatedSprite") + set_fixed_process(true) + +func take_damage(damage): + health -= damage + +func _fixed_process(delta): + + if health <= 0: + queue_free() + + var target = get_parent().get_node("Player") + var angle = get_angle_to(target.get_global_pos()) + var move_dir = Vector2(0, 1).rotated(angle) + + if move_dir.x > 0: + ani_sprite.set_animation("right") + elif move_dir.y > 0: + ani_sprite.set_animation("down") + elif move_dir.x < 0: + ani_sprite.set_animation("left") + elif move_dir.y < 0: + ani_sprite.set_animation("up") + + # actually move too + move(move_dir) \ No newline at end of file diff --git a/Enemy.tscn b/Enemy.tscn new file mode 100644 index 0000000..71b6fb6 --- /dev/null +++ b/Enemy.tscn @@ -0,0 +1,60 @@ +[gd_scene load_steps=8 format=1] + +[ext_resource path="res://Enemy.gd" type="Script" id=1] +[ext_resource path="res://enright.png" type="Texture" id=2] +[ext_resource path="res://enleft.png" type="Texture" id=3] +[ext_resource path="res://enup.png" type="Texture" id=4] +[ext_resource path="res://endown.png" type="Texture" id=5] + +[sub_resource type="RectangleShape2D" id=2] + +custom_solver_bias = 0.0 +extents = Vector2( 16.7704, 24.8305 ) + +[sub_resource type="SpriteFrames" id=1] + +animations = [ { +"frames": [ ExtResource( 2 ) ], +"loop": true, +"name": "right", +"speed": 5.0 +}, { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "left", +"speed": 5.0 +}, { +"frames": [ ExtResource( 4 ) ], +"loop": true, +"name": "up", +"speed": 5.0 +}, { +"frames": [ ExtResource( 5 ) ], +"loop": true, +"name": "down", +"speed": 5.0 +} ] + +[node name="Enemy" type="KinematicBody2D"] + +input/pickable = false +shapes/0/shape = SubResource( 2 ) +shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 ) +shapes/0/trigger = false +collision/layers = 1 +collision/mask = 1 +collision/margin = 0.08 +script/script = ExtResource( 1 ) + +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] + +frames = SubResource( 1 ) +animation = "up" + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] + +shape = SubResource( 2 ) +trigger = false +_update_shape_index = 0 + + diff --git a/Game.gd b/Game.gd new file mode 100644 index 0000000..38c4d54 --- /dev/null +++ b/Game.gd @@ -0,0 +1,4 @@ +extends Node + +func _ready(): + pass diff --git a/Game.tscn b/Game.tscn index 7ce2ead..4328ded 100644 --- a/Game.tscn +++ b/Game.tscn @@ -1,9 +1,30 @@ -[gd_scene load_steps=2 format=1] +[gd_scene load_steps=5 format=1] -[ext_resource path="res://Player.tscn" type="PackedScene" id=1] +[ext_resource path="res://Game.gd" type="Script" id=1] +[ext_resource path="res://Player.tscn" type="PackedScene" id=2] +[ext_resource path="res://Enemy.tscn" type="PackedScene" id=3] +[ext_resource path="res://Box.tscn" type="PackedScene" id=4] [node name="Game" type="Node"] -[node name="Player" parent="." instance=ExtResource( 1 )] +script/script = ExtResource( 1 ) + +[node name="Player" parent="." instance=ExtResource( 2 )] + +[node name="Enemy" parent="." instance=ExtResource( 3 )] + +transform/pos = Vector2( 305.173, 133.348 ) + +[node name="Box 1" parent="." instance=ExtResource( 4 )] + +transform/pos = Vector2( 121.777, 141.339 ) + +[node name="Box 2" parent="." instance=ExtResource( 4 )] + +transform/pos = Vector2( 159.592, 142.666 ) + +[node name="Box 3" parent="." instance=ExtResource( 4 )] + +transform/pos = Vector2( 139.69, 112.812 ) diff --git a/Player.gd b/Player.gd new file mode 100644 index 0000000..bc66fe4 --- /dev/null +++ b/Player.gd @@ -0,0 +1,40 @@ +extends KinematicBody2D + +var bullet = load("res://Bullet.tscn") +var velocity = Vector2(0, 0) +var pointer + +func _ready(): + # Called every time the node is added to the scene. + pointer = get_node("Pointer") + set_fixed_process(true) + +func _fixed_process(delta): + + var point_dir = (get_viewport().get_mouse_pos() - get_global_pos()).normalized() + + if Input.is_action_pressed("move_left"): + velocity.x = -1 + + if Input.is_action_pressed("move_right"): + velocity.x = 1 + + if Input.is_action_pressed("move_up"): + velocity.y = -1 + + if Input.is_action_pressed("move_down"): + velocity.y = 1 + + # shooty + if Input.is_action_pressed("primary_fire"): + var new_bullet = bullet.instance() + new_bullet.set_pos(pointer.get_node("Sprite").get_global_pos() + velocity) + new_bullet.set_bullet_velocity(velocity, point_dir) + get_parent().add_child(new_bullet) # add to tree + + # rotatey pointer thingy + pointer.look_at(get_viewport().get_mouse_pos()) + + self.move(velocity) + velocity.x = 0 + velocity.y = 0 \ No newline at end of file diff --git a/Player.tscn b/Player.tscn index 9fdbed5..df21f7d 100644 --- a/Player.tscn +++ b/Player.tscn @@ -1,18 +1,24 @@ -[gd_scene load_steps=3 format=1] +[gd_scene load_steps=5 format=1] -[ext_resource path="res://player_controller.gd" type="Script" id=1] -[ext_resource path="res://icon.png" type="Texture" id=2] +[ext_resource path="res://Player.gd" type="Script" id=1] +[ext_resource path="res://player.png" type="Texture" id=2] +[ext_resource path="res://pointer.png" type="Texture" id=3] -[node name="Player" type="Control"] +[sub_resource type="RectangleShape2D" id=1] -focus/ignore_mouse = false -focus/stop_mouse = true -size_flags/horizontal = 2 -size_flags/vertical = 2 -margin/left = 0.0 -margin/top = 0.0 -margin/right = 40.0 -margin/bottom = 40.0 +custom_solver_bias = 0.0 +extents = Vector2( 17.1165, 38.4685 ) + +[node name="Player" type="KinematicBody2D"] + +transform/pos = Vector2( 36.5, 31 ) +input/pickable = false +shapes/0/shape = SubResource( 1 ) +shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 ) +shapes/0/trigger = false +collision/layers = 1 +collision/mask = 1 +collision/margin = 0.08 script/script = ExtResource( 1 ) [node name="Sprite" type="Sprite" parent="."] @@ -22,6 +28,22 @@ texture = ExtResource( 2 ) [node name="Listener" type="Listener" parent="."] _import_transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ) -current = false +current = true + +[node name="Position2D" type="Position2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] + +shape = SubResource( 1 ) +trigger = false +_update_shape_index = 0 + +[node name="Pointer" type="Node2D" parent="."] + +[node name="Sprite" type="Sprite" parent="Pointer"] + +transform/pos = Vector2( 0, 50.2221 ) +transform/rot = 90.0 +texture = ExtResource( 3 ) diff --git a/box.png b/box.png new file mode 100644 index 0000000..807fd5e --- /dev/null +++ b/box.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad95a31a5c41f2c604d71385252d5bdfc711cabc7cdc6ba8b2163e221da1e9fc +size 6978 diff --git a/bullet.png b/bullet.png new file mode 100644 index 0000000..ba7bbde --- /dev/null +++ b/bullet.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8659508ab4604ef48edd0c78ffbd7376eb954d1f5749a2467d8f7db067d38872 +size 661 diff --git a/endown.png b/endown.png new file mode 100644 index 0000000..36cd1e3 --- /dev/null +++ b/endown.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e69fe2cc42383b1a38bca244f62664f3185511b460d656a3ba24357ff8b725a +size 3215 diff --git a/engine.cfg b/engine.cfg index 5098c18..9771d21 100644 --- a/engine.cfg +++ b/engine.cfg @@ -1,14 +1,13 @@ -; Engine configuration file. -; It's best edited using the editor UI and not directly, -; since the parameters that go here are not all obvious. -; -; Format: -; [section] ; section goes between [] -; param=value ; assign values to parameters - - [application] - name="Scribe" +main_scene="res://Game.tscn" icon="res://icon.png" + +[input] + +move_up=[key(W), key(Up)] +move_down=[key(Down), key(S)] +move_left=[key(Left), key(A)] +move_right=[key(Right), key(D)] +primary_fire=[mbutton(0, 1)] diff --git a/enleft.png b/enleft.png new file mode 100644 index 0000000..ec40a82 --- /dev/null +++ b/enleft.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3304a7df3ef80df022f63e2c31469a53dc868de9e4e073b7b1150ffa945e9abb +size 3147 diff --git a/enright.png b/enright.png new file mode 100644 index 0000000..7043b7d --- /dev/null +++ b/enright.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45413154660c8fddf458043b52ab359f9b46fc0cc5b3ff099d709292a07a8090 +size 3077 diff --git a/enup.png b/enup.png new file mode 100644 index 0000000..e884532 --- /dev/null +++ b/enup.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:870df490b810fd689af53ef2f8d402ada356fab2197bb3a1c33cb4c7fe3ebf3c +size 2562 diff --git a/player.png b/player.png new file mode 100644 index 0000000..6a08661 --- /dev/null +++ b/player.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:61994dc8321cde10dd29b73b0342164c31e29c50dc3454b79c71f7cbb7b9b8f9 +size 3657 diff --git a/pointer.png b/pointer.png new file mode 100644 index 0000000..ba0f3c6 --- /dev/null +++ b/pointer.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:146750fc9a462f82dd3562354b3101460cc6c588ed89946e636af7bf121d4643 +size 851