commit 7ec9f8527adc851fce6b8e169b2976ff053a6871
Author: Léo Villeveygoux <l@vgx.fr>
Date: Sun, 28 Aug 2022 14:02:45 +0200
Inital game mechanics (no enemies)
Diffstat:
11 files changed, 252 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1 @@
+.import
diff --git a/Guard.gd b/Guard.gd
@@ -0,0 +1,35 @@
+extends KinematicBody2D
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+
+export var stop_dist = 10.0
+export var speed = 70.0
+export var dash_speed = 200.0
+export var dash_timeout = 3.0
+export var dash_duration = .3
+
+var target = Vector2()
+var dash_state = -dash_timeout
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ target = position
+
+func _unhandled_input(event):
+ if event is InputEventMouseButton:
+ target = event.position
+ if event.doubleclick and dash_state <= -dash_timeout:
+ dash_state = dash_duration
+ print("dash")
+
+func _physics_process(delta):
+ var to_target = target - position
+ if to_target.length() > stop_dist:
+ var move_speed = dash_speed if dash_state > 0 else speed
+ move_and_slide(to_target.normalized()*move_speed)
+ if dash_state > -dash_timeout:
+ dash_state -= delta
diff --git a/Niveau.gd b/Niveau.gd
@@ -0,0 +1,14 @@
+extends Node2D
+
+var lvl = 0
+
+var safe_radius = 50.0
+
+func _ready():
+ $President.position = Vector2(safe_radius, get_viewport_rect().size.y/2)
+ $Guard.position = Vector2(safe_radius, get_viewport_rect().size.y/2 - safe_radius*2)
+ $Guard.target = $Guard.position
+
+func _physics_process(_delta):
+ if $President.position.x + safe_radius > get_viewport_rect().size.x:
+ _ready()
diff --git a/Niveau.tscn b/Niveau.tscn
@@ -0,0 +1,78 @@
+[gd_scene load_steps=8 format=2]
+
+[ext_resource path="res://Public.tscn" type="PackedScene" id=1]
+[ext_resource path="res://icon.png" type="Texture" id=2]
+[ext_resource path="res://President.gd" type="Script" id=3]
+[ext_resource path="res://Guard.gd" type="Script" id=4]
+[ext_resource path="res://Niveau.gd" type="Script" id=5]
+
+[sub_resource type="CanvasItemMaterial" id=2]
+
+[sub_resource type="CircleShape2D" id=1]
+radius = 29.0172
+
+[node name="Niveau" type="Node2D"]
+script = ExtResource( 5 )
+
+[node name="Walls" type="StaticBody2D" parent="."]
+material = SubResource( 2 )
+position = Vector2( 1067, 274 )
+__meta__ = {
+"_edit_group_": true
+}
+
+[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Walls"]
+visible = false
+build_mode = 1
+polygon = PoolVector2Array( -1067, -274, -43, -274, -43, 326, -1068, 325 )
+
+[node name="President" type="RigidBody2D" parent="."]
+position = Vector2( 29, 279 )
+mode = 2
+script = ExtResource( 3 )
+__meta__ = {
+"_edit_group_": true
+}
+
+[node name="Sprite" type="Sprite" parent="President"]
+texture = ExtResource( 2 )
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="President"]
+shape = SubResource( 1 )
+
+[node name="Public" parent="." instance=ExtResource( 1 )]
+position = Vector2( 208, 389 )
+
+[node name="Public2" parent="." instance=ExtResource( 1 )]
+position = Vector2( 254, 284 )
+
+[node name="Public3" parent="." instance=ExtResource( 1 )]
+position = Vector2( 563, 307 )
+
+[node name="Public4" parent="." instance=ExtResource( 1 )]
+position = Vector2( 400, 224 )
+
+[node name="Public5" parent="." instance=ExtResource( 1 )]
+position = Vector2( 385, 395 )
+
+[node name="Public6" parent="." instance=ExtResource( 1 )]
+position = Vector2( 420, 297 )
+
+[node name="Public7" parent="." instance=ExtResource( 1 )]
+position = Vector2( 681, 384 )
+
+[node name="Public8" parent="." instance=ExtResource( 1 )]
+position = Vector2( 695, 241 )
+
+[node name="Guard" type="KinematicBody2D" parent="."]
+position = Vector2( 120, 256 )
+script = ExtResource( 4 )
+__meta__ = {
+"_edit_group_": true
+}
+
+[node name="Sprite" type="Sprite" parent="Guard"]
+texture = ExtResource( 2 )
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="Guard"]
+shape = SubResource( 1 )
diff --git a/President.gd b/President.gd
@@ -0,0 +1,10 @@
+extends RigidBody2D
+
+export var max_speed = 30.0
+
+func _integrate_forces(state):
+ #print_debug(state.linear_velocity.x)
+ if state.linear_velocity.x < max_speed:
+ applied_force.x = 30.0
+ else:
+ applied_force.x = 0
diff --git a/Public.gd b/Public.gd
@@ -0,0 +1,15 @@
+extends RigidBody2D
+
+export var max_speed = 20.0
+export var force = 20.0
+
+func _ready():
+ max_speed = rand_range(0, max_speed)
+
+func _integrate_forces(state):
+ #print_debug(state.linear_velocity.x)
+ var direction = get_node("../President").position - position
+ if state.linear_velocity.length() < max_speed:
+ applied_force = direction.normalized() * force
+ else:
+ applied_force = Vector2()
diff --git a/Public.tscn b/Public.tscn
@@ -0,0 +1,22 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://icon.png" type="Texture" id=1]
+[ext_resource path="res://Public.gd" type="Script" id=2]
+
+[sub_resource type="CircleShape2D" id=1]
+radius = 29.0172
+
+[node name="Public" type="RigidBody2D" groups=["public"]]
+gravity_scale = 0.0
+linear_damp = 1.0
+script = ExtResource( 2 )
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
+shape = SubResource( 1 )
+__meta__ = {
+"_edit_lock_": true
+}
+
+[node name="Icon" type="Sprite" parent="."]
+position = Vector2( 0, -4 )
+texture = ExtResource( 1 )
diff --git a/default_env.tres b/default_env.tres
@@ -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 )
diff --git a/icon.png b/icon.png
Binary files differ.
diff --git a/icon.png.import b/icon.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://icon.png"
+dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.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
diff --git a/project.godot b/project.godot
@@ -0,0 +1,35 @@
+; 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
+
+config_version=4
+
+[application]
+
+config/name="President"
+run/main_scene="res://Niveau.tscn"
+config/icon="res://icon.png"
+
+[display]
+
+window/size/resizable=false
+
+[gui]
+
+common/drop_mouse_on_gui_input_disabled=true
+
+[physics]
+
+common/enable_pause_aware_picking=true
+2d/default_gravity_vector=Vector2( 0, 0 )
+
+[rendering]
+
+quality/driver/driver_name="GLES2"
+vram_compression/import_etc=true
+vram_compression/import_etc2=false
+environment/default_environment="res://default_env.tres"