among-eux

Game made in 1 day with flx
git clone git://git.vgx.fr/among-eux
Log | Files | Refs

commit 0b9b8b650224f2b162c398dc15d580aa127fade0
parent 7ec9f8527adc851fce6b8e169b2976ff053a6871
Author: Léo Villeveygoux <l@vgx.fr>
Date:   Sun, 28 Aug 2022 15:01:14 +0200

Level system

Diffstat:
ALevel.gd | 17+++++++++++++++++
ALevel.tscn | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ALevels.gd | 26++++++++++++++++++++++++++
ALevels.tscn | 6++++++
DNiveau.gd | 14--------------
DNiveau.tscn | 78------------------------------------------------------------------------------
MPublic.tscn | 1+
Mproject.godot | 8++++++--
8 files changed, 139 insertions(+), 94 deletions(-)

diff --git a/Level.gd b/Level.gd @@ -0,0 +1,17 @@ +extends Node2D + +export var lvl = 1 + +var safe_radius = 40.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 _ready(): + $LvlLabel.text = "lvl: " + String(lvl) + +func _physics_process(_delta): + if $President.position.x + safe_radius > get_viewport_rect().size.x: + get_parent().next_lvl() diff --git a/Level.tscn b/Level.tscn @@ -0,0 +1,83 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://Level.gd" type="Script" id=1] +[ext_resource path="res://President.gd" type="Script" id=2] +[ext_resource path="res://Public.tscn" type="PackedScene" id=3] +[ext_resource path="res://Guard.gd" type="Script" id=4] +[ext_resource path="res://icon.png" type="Texture" id=5] + +[sub_resource type="CanvasItemMaterial" id=2] + +[sub_resource type="CircleShape2D" id=1] +radius = 29.0172 + +[node name="Level" type="Node2D"] +script = ExtResource( 1 ) + +[node name="LvlLabel" type="Label" parent="."] +margin_left = 438.0 +margin_top = 7.0 +margin_right = 502.0 +margin_bottom = 21.0 +text = "lvl: 1" +align = 2 + +[node name="Walls" type="StaticBody2D" parent="."] +material = SubResource( 2 ) +position = Vector2( 1067, 274 ) + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Walls"] +visible = false +build_mode = 1 +polygon = PoolVector2Array( -1067, -274, -555, -274, -555, 26, -1067, 26 ) + +[node name="President" type="RigidBody2D" parent="."] +position = Vector2( 29, 155 ) +mode = 2 +script = ExtResource( 2 ) +__meta__ = { +"_edit_group_": true +} + +[node name="Sprite" type="Sprite" parent="President"] +texture = ExtResource( 5 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="President"] +shape = SubResource( 1 ) + +[node name="Public" parent="." instance=ExtResource( 3 )] +position = Vector2( 152, 250 ) + +[node name="Public2" parent="." instance=ExtResource( 3 )] +position = Vector2( 285, 78 ) + +[node name="Public3" parent="." instance=ExtResource( 3 )] +position = Vector2( 277, 189 ) + +[node name="Public4" parent="." instance=ExtResource( 3 )] +position = Vector2( 156, 66 ) + +[node name="Public5" parent="." instance=ExtResource( 3 )] +position = Vector2( 255, 248 ) + +[node name="Public6" parent="." instance=ExtResource( 3 )] +position = Vector2( 176, 139 ) + +[node name="Public7" parent="." instance=ExtResource( 3 )] +position = Vector2( 395, 266 ) + +[node name="Public8" parent="." instance=ExtResource( 3 )] +position = Vector2( 409, 123 ) + +[node name="Guard" type="KinematicBody2D" parent="."] +position = Vector2( 54, 74 ) +script = ExtResource( 4 ) +__meta__ = { +"_edit_group_": true +} + +[node name="Sprite" type="Sprite" parent="Guard"] +texture = ExtResource( 5 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Guard"] +shape = SubResource( 1 ) diff --git a/Levels.gd b/Levels.gd @@ -0,0 +1,26 @@ +extends Node2D + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +var lvl = 1 +var level_scn = preload("res://Level.tscn") +var level + +func _ready(): + level = level_scn.instance() + add_child(level) + + +func next_lvl(): + lvl += 1 + level.queue_free() + level = level_scn.instance() + level.lvl = lvl + add_child(level) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/Levels.tscn b/Levels.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Levels.gd" type="Script" id=1] + +[node name="Levels" type="Node2D"] +script = ExtResource( 1 ) diff --git a/Niveau.gd b/Niveau.gd @@ -1,14 +0,0 @@ -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 @@ -1,78 +0,0 @@ -[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/Public.tscn b/Public.tscn @@ -7,6 +7,7 @@ radius = 29.0172 [node name="Public" type="RigidBody2D" groups=["public"]] +mode = 2 gravity_scale = 0.0 linear_damp = 1.0 script = ExtResource( 2 ) diff --git a/project.godot b/project.godot @@ -11,12 +11,15 @@ config_version=4 [application] config/name="President" -run/main_scene="res://Niveau.tscn" +run/main_scene="res://Levels.tscn" config/icon="res://icon.png" [display] -window/size/resizable=false +window/size/width=512 +window/size/height=300 +window/stretch/mode="viewport" +window/stretch/aspect="keep" [gui] @@ -30,6 +33,7 @@ common/enable_pause_aware_picking=true [rendering] quality/driver/driver_name="GLES2" +2d/snapping/use_gpu_pixel_snap=true vram_compression/import_etc=true vram_compression/import_etc2=false environment/default_environment="res://default_env.tres"