Added ski-invasion
This commit is contained in:
40
src/avalanche/avalanche.gd
Normal file
40
src/avalanche/avalanche.gd
Normal file
@@ -0,0 +1,40 @@
|
||||
class_name Avalanche
|
||||
extends Area2D
|
||||
|
||||
const base_speed = 3.5
|
||||
var speed : float = base_speed * Global.TILE_SCALE
|
||||
var kmh_speed = speed*1000 / 3600
|
||||
const avalanche_width = 50
|
||||
const avalanche_height = 2
|
||||
|
||||
func _ready():
|
||||
position.x = Global.player.position.x- (int(Global.player.position.x)%Global.TILE_SCALE)
|
||||
position.y = Global.player.position.y - 10*Global.TILE_SCALE
|
||||
|
||||
for i in range(-avalanche_height/2,avalanche_height/2):
|
||||
for j in range(-avalanche_width/2,avalanche_width/2):
|
||||
$TileMap.set_cell(0,Vector2(j,i), 0,Vector2i(9,5),0)
|
||||
$CollisionShape.scale = Vector2i(avalanche_width,avalanche_height)
|
||||
|
||||
func reset():
|
||||
speed = base_speed * Global.TILE_SCALE
|
||||
kmh_speed = speed * 1000 / 3600
|
||||
_ready()
|
||||
|
||||
func _process(delta):
|
||||
position.x = Global.player.position.x- (int(Global.player.position.x)%Global.TILE_SCALE)
|
||||
position.y += speed*delta
|
||||
kmh_speed = speed*1000 / 3600
|
||||
pass
|
||||
|
||||
|
||||
func _on_body_entered(body):
|
||||
if(body.is_in_group("Enemy")):
|
||||
body.queue_free()
|
||||
speed+=0.1 * Global.TILE_SCALE
|
||||
kmh_speed = speed*1000 / 3600
|
||||
pass
|
||||
if(body.is_in_group("Player")):
|
||||
print("Avalanche Hit Player")
|
||||
pass
|
||||
pass
|
21
src/avalanche/avalanche.tscn
Normal file
21
src/avalanche/avalanche.tscn
Normal file
@@ -0,0 +1,21 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://q8rg3smgpxpg"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/avalanche/avalanche.gd" id="1_e7063"]
|
||||
[ext_resource type="TileSet" uid="uid://bl2sbc1gv1e2q" path="res://src/map/map.tres" id="2_35aeg"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hitsr"]
|
||||
size = Vector2(16, 16)
|
||||
|
||||
[node name="Avalanche" type="Area2D" groups=["Avalanche"]]
|
||||
collision_layer = 8
|
||||
collision_mask = 14
|
||||
script = ExtResource("1_e7063")
|
||||
|
||||
[node name="TileMap" type="TileMap" parent="."]
|
||||
tile_set = ExtResource("2_35aeg")
|
||||
format = 2
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape2D" parent="." groups=["Avalanche"]]
|
||||
shape = SubResource("RectangleShape2D_hitsr")
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
17
src/enemy/enemy.gd
Normal file
17
src/enemy/enemy.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
class_name Enemy
|
||||
extends CharacterBody2D
|
||||
|
||||
@export var speed = 50;
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
|
||||
var dir = (Global.player.position-position).normalized()
|
||||
velocity = dir*speed
|
||||
var col = move_and_slide()
|
||||
for i in get_slide_collision_count():
|
||||
pass
|
23
src/enemy/enemy.tres
Normal file
23
src/enemy/enemy.tres
Normal file
@@ -0,0 +1,23 @@
|
||||
[gd_resource type="SpriteFrames" load_steps=3 format=3 uid="uid://dbyy37vnjhld1"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://q7ooafycqvcv" path="res://res/Tiles/tile_0078.png" id="1_760qg"]
|
||||
[ext_resource type="Texture2D" uid="uid://csv10375x6ofi" path="res://res/Tiles/tile_0079.png" id="2_wl314"]
|
||||
|
||||
[resource]
|
||||
animations = [{
|
||||
"frames": [],
|
||||
"loop": true,
|
||||
"name": &"dead",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("1_760qg")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("2_wl314")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 5.0
|
||||
}]
|
22
src/enemy/enemy.tscn
Normal file
22
src/enemy/enemy.tscn
Normal file
@@ -0,0 +1,22 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://ciel1xlp71ni7"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/enemy/enemy.gd" id="1_rmw5w"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://dbyy37vnjhld1" path="res://src/enemy/enemy.tres" id="2_qrbqi"]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_no0w4"]
|
||||
radius = 6.0
|
||||
height = 16.0
|
||||
|
||||
[node name="Enemy" type="CharacterBody2D" groups=["Enemy"]]
|
||||
z_index = 1
|
||||
collision_layer = 4
|
||||
collision_mask = 4
|
||||
slide_on_ceiling = false
|
||||
script = ExtResource("1_rmw5w")
|
||||
speed = 20
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
sprite_frames = ExtResource("2_qrbqi")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." groups=["Enemy"]]
|
||||
shape = SubResource("CapsuleShape2D_no0w4")
|
23
src/global.gd
Normal file
23
src/global.gd
Normal file
@@ -0,0 +1,23 @@
|
||||
extends Node
|
||||
|
||||
const TILE_SCALE : int = 16;
|
||||
var slope : float = 1.0;
|
||||
var map = null
|
||||
var player = preload("res://src/player/player.tscn").instantiate()
|
||||
var enemy = preload("res://src/enemy/enemy.tscn")
|
||||
var avalanche = preload("res://src/avalanche/avalanche.tscn").instantiate()
|
||||
var enemies = []
|
||||
|
||||
func reset():
|
||||
if(map):
|
||||
map.reset()
|
||||
if(player):
|
||||
player.reset()
|
||||
if(avalanche):
|
||||
avalanche.reset()
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
func _process(delta):
|
||||
pass
|
179
src/map/map.gd
Normal file
179
src/map/map.gd
Normal file
@@ -0,0 +1,179 @@
|
||||
extends TileMap
|
||||
|
||||
const min_x_width: int = 10;
|
||||
const max_x_width: int = 35;
|
||||
const x_margin: int = 20;
|
||||
const y_prerender: int = 10;
|
||||
|
||||
var last_tile_y : int = -10;
|
||||
var x_offset : int = 0;
|
||||
var x_width : int = 20;
|
||||
var last_had_gs : bool = false;
|
||||
|
||||
var last_line : Array[TEXT_TYPE] = []
|
||||
var new_line : Array[TEXT_TYPE] = []
|
||||
|
||||
|
||||
enum TEXT_TYPE {
|
||||
TREE, POWDER,
|
||||
L_EDGE_GROW, L_GROW_EDGE,
|
||||
L_EDGE_SHRINK, L_SHRINK_EDGE,
|
||||
L_EDGE, SLOPE, R_EDGE,
|
||||
R_EDGE_GROW, R_GROW_EDGE,
|
||||
R_EDGE_SHRINK, R_SHRINK_EDGE,
|
||||
NONE
|
||||
}
|
||||
|
||||
|
||||
func get_texture(tt: TEXT_TYPE) -> Vector2i:
|
||||
match tt:
|
||||
TEXT_TYPE.TREE:
|
||||
if(randf()>0.9):
|
||||
return Vector2i(6,0)
|
||||
return Vector2i(6,2)
|
||||
TEXT_TYPE.POWDER:
|
||||
if(randf()>0.2):
|
||||
return Vector2i(0,0)
|
||||
return Vector2i(5,0)
|
||||
|
||||
TEXT_TYPE.L_EDGE_GROW:
|
||||
return Vector2i(2,1)
|
||||
TEXT_TYPE.L_GROW_EDGE:
|
||||
return Vector2i(0,1)
|
||||
|
||||
TEXT_TYPE.L_EDGE_SHRINK:
|
||||
return Vector2i(2,4)
|
||||
TEXT_TYPE.L_SHRINK_EDGE:
|
||||
return Vector2i(0,2)
|
||||
|
||||
TEXT_TYPE.L_EDGE:
|
||||
return Vector2i(1,0)
|
||||
|
||||
TEXT_TYPE.SLOPE:
|
||||
if(randf()>0.2):
|
||||
return Vector2i(2,0)
|
||||
return Vector2i(3,0)
|
||||
|
||||
TEXT_TYPE.R_EDGE:
|
||||
return Vector2i(4,0)
|
||||
|
||||
TEXT_TYPE.R_EDGE_GROW:
|
||||
return Vector2i(3,1)
|
||||
TEXT_TYPE.R_GROW_EDGE:
|
||||
return Vector2i(5,1)
|
||||
|
||||
TEXT_TYPE.R_EDGE_SHRINK:
|
||||
return Vector2i(3,4)
|
||||
TEXT_TYPE.R_SHRINK_EDGE:
|
||||
return Vector2i(5,2)
|
||||
_:
|
||||
return Vector2i(0,0)
|
||||
|
||||
func gen_line():
|
||||
if(last_line.size() == 0):
|
||||
new_line.resize(x_width+ 2*x_margin)
|
||||
new_line.fill(TEXT_TYPE.POWDER)
|
||||
for j in range(x_margin+1, x_margin+x_width ):
|
||||
new_line[j] = TEXT_TYPE.SLOPE
|
||||
|
||||
new_line[x_margin] = TEXT_TYPE.L_EDGE
|
||||
new_line[x_margin+x_width] = TEXT_TYPE.R_EDGE
|
||||
last_line = Array(new_line)
|
||||
return
|
||||
|
||||
var last_width = x_width
|
||||
var grow = !last_had_gs && (last_width<max_x_width) && randf()<0.3
|
||||
var shrink = !last_had_gs && (last_width>min_x_width) && randf()<0.3
|
||||
last_had_gs = grow || shrink
|
||||
|
||||
var grow_rand = randf()
|
||||
var shrink_rand = randf()
|
||||
|
||||
var grow_l = grow && grow_rand<0.6
|
||||
var shrink_l = shrink && shrink_rand<0.6
|
||||
var grow_r = grow && grow_rand>=0.6
|
||||
var shrink_r = shrink && shrink_rand>=0.6
|
||||
|
||||
var start_offset = -1 if grow_l else (1 if shrink_l else 0)
|
||||
var end_offset = 1 if grow_r else (-1 if shrink_r else 0)
|
||||
var this_width = last_width + (-start_offset) + end_offset
|
||||
var this_offset = x_offset + start_offset
|
||||
|
||||
new_line.resize(this_width+ 2*x_margin)
|
||||
new_line.fill(TEXT_TYPE.POWDER)
|
||||
|
||||
for j in range(x_margin, x_margin+this_width ):
|
||||
new_line[j] = TEXT_TYPE.SLOPE
|
||||
|
||||
if(grow_l):
|
||||
new_line[x_margin] = TEXT_TYPE.POWDER
|
||||
new_line[x_margin+1] = TEXT_TYPE.L_EDGE_GROW
|
||||
elif(shrink_l):
|
||||
new_line[x_margin] = TEXT_TYPE.SLOPE
|
||||
new_line[x_margin-1] = TEXT_TYPE.L_SHRINK_EDGE
|
||||
else:
|
||||
if(last_line[x_margin+1] == TEXT_TYPE.L_EDGE_GROW):
|
||||
new_line[x_margin] = TEXT_TYPE.L_GROW_EDGE
|
||||
elif(last_line[x_margin-1] == TEXT_TYPE.L_SHRINK_EDGE):
|
||||
new_line[x_margin] = TEXT_TYPE.L_EDGE_SHRINK
|
||||
else:
|
||||
new_line[x_margin] = TEXT_TYPE.L_EDGE
|
||||
|
||||
if(grow_r):
|
||||
new_line[x_margin+this_width] = TEXT_TYPE.POWDER
|
||||
new_line[x_margin+this_width-1] = TEXT_TYPE.R_EDGE_GROW
|
||||
elif(shrink_r):
|
||||
new_line[x_margin+this_width] = TEXT_TYPE.SLOPE
|
||||
new_line[x_margin+this_width+1] = TEXT_TYPE.R_SHRINK_EDGE
|
||||
else:
|
||||
if(last_line[x_margin+this_width-1] == TEXT_TYPE.R_EDGE_GROW):
|
||||
new_line[x_margin+this_width] = TEXT_TYPE.R_GROW_EDGE
|
||||
elif(last_line[x_margin+this_width+1] == TEXT_TYPE.R_SHRINK_EDGE):
|
||||
new_line[x_margin+this_width] = TEXT_TYPE.R_EDGE_SHRINK
|
||||
else:
|
||||
new_line[x_margin+this_width] = TEXT_TYPE.R_EDGE
|
||||
|
||||
x_offset = this_offset
|
||||
x_width = this_width
|
||||
last_line = new_line.duplicate()#Array.from(new_line)
|
||||
|
||||
func gen_cells(ny:int):
|
||||
for i in range(last_tile_y, last_tile_y+ny):
|
||||
gen_line()
|
||||
for j in range(last_line.size()):
|
||||
set_cell(0,Vector2(j+x_offset,i), 0,get_texture(last_line[j]),0)
|
||||
last_tile_y += ny
|
||||
|
||||
func _ready():
|
||||
Global.map = self
|
||||
add_child(Global.player)
|
||||
Global.player.position=Vector2((x_offset + x_margin + x_width/2.0)*Global.TILE_SCALE,0)
|
||||
while(Global.player.position.y + y_prerender*Global.TILE_SCALE > last_tile_y*Global.TILE_SCALE):
|
||||
gen_cells(2)
|
||||
add_child(Global.avalanche)
|
||||
pass
|
||||
|
||||
func reset():
|
||||
last_tile_y = -10;
|
||||
x_offset = 0;
|
||||
x_width = 20;
|
||||
Global.player.position=Vector2((x_offset + x_margin + x_width/2.0)*Global.TILE_SCALE,0)
|
||||
Global.avalanche.reset()
|
||||
|
||||
last_line = []
|
||||
new_line = []
|
||||
clear()
|
||||
while(Global.player.position.y + y_prerender*Global.TILE_SCALE > last_tile_y*Global.TILE_SCALE):
|
||||
gen_cells(2)
|
||||
|
||||
func _process(delta):
|
||||
if(Global.player.position.y + y_prerender*Global.TILE_SCALE > last_tile_y*Global.TILE_SCALE):
|
||||
gen_cells(1)
|
||||
if(randf()<0.2):
|
||||
var new_enemy = Global.enemy.instantiate()
|
||||
new_enemy.position.y = last_tile_y*Global.TILE_SCALE
|
||||
new_enemy.position.x = (x_offset+x_margin + randf()*x_width)*Global.TILE_SCALE
|
||||
add_child(new_enemy)
|
||||
|
||||
|
||||
|
159
src/map/map.tres
Normal file
159
src/map/map.tres
Normal file
@@ -0,0 +1,159 @@
|
||||
[gd_resource type="TileSet" load_steps=3 format=3 uid="uid://bl2sbc1gv1e2q"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bxl3fs8u40ki6" path="res://res/tiles.png" id="1_ka6ac"]
|
||||
|
||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_qmyk0"]
|
||||
resource_name = "tiles"
|
||||
texture = ExtResource("1_ka6ac")
|
||||
0:0/0 = 0
|
||||
0:0/0/probability = 0.1
|
||||
0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
0:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, -8, 8, 8, -8, 8, -8, -8)
|
||||
1:1/0 = 0
|
||||
1:1/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
1:1/0/physics_layer_0/angular_velocity = 0.0
|
||||
1:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, -8, 8, 8, -8, 8, -8, -8)
|
||||
6:6/0 = 0
|
||||
6:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
6:6/0/physics_layer_0/angular_velocity = 0.0
|
||||
7:6/0 = 0
|
||||
7:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
7:6/0/physics_layer_0/angular_velocity = 0.0
|
||||
8:6/0 = 0
|
||||
8:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
8:6/0/physics_layer_0/angular_velocity = 0.0
|
||||
9:6/0 = 0
|
||||
9:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
9:6/0/physics_layer_0/angular_velocity = 0.0
|
||||
10:6/0 = 0
|
||||
10:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
10:6/0/physics_layer_0/angular_velocity = 0.0
|
||||
10:5/0 = 0
|
||||
10:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
10:5/0/physics_layer_0/angular_velocity = 0.0
|
||||
11:5/0 = 0
|
||||
11:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
11:5/0/physics_layer_0/angular_velocity = 0.0
|
||||
11:6/0 = 0
|
||||
11:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
11:6/0/physics_layer_0/angular_velocity = 0.0
|
||||
6:2/0 = 0
|
||||
6:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
6:2/0/physics_layer_0/angular_velocity = 0.0
|
||||
6:0/size_in_atlas = Vector2i(1, 2)
|
||||
6:0/0 = 0
|
||||
6:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
6:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
7:0/size_in_atlas = Vector2i(1, 2)
|
||||
7:0/0 = 0
|
||||
7:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
7:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
7:2/0 = 0
|
||||
7:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
7:2/0/physics_layer_0/angular_velocity = 0.0
|
||||
10:0/0 = 0
|
||||
10:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
10:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
11:0/0 = 0
|
||||
11:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
11:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
8:0/0 = 0
|
||||
8:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
8:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
9:0/0 = 0
|
||||
9:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
9:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
1:0/0 = 0
|
||||
1:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
1:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
1:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(0, -8, -8, -8, -8, -8, -8, -8, -8, 8, 0, 8, 0, 8)
|
||||
4:0/0 = 0
|
||||
4:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
4:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
4:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, -8, 0.125, -8, -0.125, 8, 8, 8)
|
||||
5:0/0 = 0
|
||||
5:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
5:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
5:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, -8, 8, 8, -8, 8, -8, -8)
|
||||
3:0/0 = 0
|
||||
3:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
3:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
2:0/0 = 0
|
||||
2:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
2:0/0/physics_layer_0/angular_velocity = 0.0
|
||||
0:1/0 = 0
|
||||
0:1/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
0:1/0/physics_layer_0/angular_velocity = 0.0
|
||||
0:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, -8, 8, 0, 8, 0, 0, 8, -8)
|
||||
0:2/0 = 0
|
||||
0:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
0:2/0/physics_layer_0/angular_velocity = 0.0
|
||||
0:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, -8, 8, 8, 8, 0, 0, 0, -8)
|
||||
1:2/0 = 0
|
||||
1:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
1:2/0/physics_layer_0/angular_velocity = 0.0
|
||||
2:2/0 = 0
|
||||
2:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
2:2/0/physics_layer_0/angular_velocity = 0.0
|
||||
2:1/0 = 0
|
||||
2:1/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
2:1/0/physics_layer_0/angular_velocity = 0.0
|
||||
2:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(0, -8, -8, -8, -8, -8, -8, -8, -8, 8, 0, 0, 0, 0)
|
||||
3:1/0 = 0
|
||||
3:1/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
3:1/0/physics_layer_0/angular_velocity = 0.0
|
||||
3:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, -8, 0.125, -8, 0.013577, -0.868928, 8, 8, 8, 8)
|
||||
3:2/0 = 0
|
||||
3:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
3:2/0/physics_layer_0/angular_velocity = 0.0
|
||||
4:2/0 = 0
|
||||
4:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
4:2/0/physics_layer_0/angular_velocity = 0.0
|
||||
4:1/0 = 0
|
||||
4:1/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
4:1/0/physics_layer_0/angular_velocity = 0.0
|
||||
4:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, -8, 8, 8, -8, 8, -8, -8)
|
||||
5:1/0 = 0
|
||||
5:1/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
5:1/0/physics_layer_0/angular_velocity = 0.0
|
||||
5:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, -8, 8, 8, 0, 8, 0, 0, -8, -8)
|
||||
5:2/0 = 0
|
||||
5:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
5:2/0/physics_layer_0/angular_velocity = 0.0
|
||||
5:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, -8, 8, 8, -8, 8, 0, 0, 0, -8)
|
||||
4:3/0 = 0
|
||||
4:3/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
4:3/0/physics_layer_0/angular_velocity = 0.0
|
||||
3:3/0 = 0
|
||||
3:3/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
3:3/0/physics_layer_0/angular_velocity = 0.0
|
||||
2:4/0 = 0
|
||||
2:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
2:4/0/physics_layer_0/angular_velocity = 0.0
|
||||
2:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(0, 0, 0, 8, -8, 8, -8, -8)
|
||||
1:4/0 = 0
|
||||
1:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
1:4/0/physics_layer_0/angular_velocity = 0.0
|
||||
1:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
|
||||
1:3/0 = 0
|
||||
1:3/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
1:3/0/physics_layer_0/angular_velocity = 0.0
|
||||
2:3/0 = 0
|
||||
2:3/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
2:3/0/physics_layer_0/angular_velocity = 0.0
|
||||
3:4/0 = 0
|
||||
3:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
3:4/0/physics_layer_0/angular_velocity = 0.0
|
||||
3:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(0, 0, 0, 8, 8, 8, 8, -8)
|
||||
4:4/0 = 0
|
||||
4:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
4:4/0/physics_layer_0/angular_velocity = 0.0
|
||||
4:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
|
||||
9:5/0 = 0
|
||||
9:5/0/physics_layer_0/linear_velocity = Vector2(0, 0)
|
||||
9:5/0/physics_layer_0/angular_velocity = 0.0
|
||||
|
||||
[resource]
|
||||
physics_layer_0/collision_layer = 1
|
||||
sources/0 = SubResource("TileSetAtlasSource_qmyk0")
|
11
src/map/map.tscn
Normal file
11
src/map/map.tscn
Normal file
@@ -0,0 +1,11 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://psrip8826pbi"]
|
||||
|
||||
[ext_resource type="TileSet" uid="uid://bl2sbc1gv1e2q" path="res://src/map/map.tres" id="1_1vaa2"]
|
||||
[ext_resource type="Script" path="res://src/map/map.gd" id="2_7k23r"]
|
||||
|
||||
[node name="Map" type="Node2D"]
|
||||
|
||||
[node name="TileMap" type="TileMap" parent="."]
|
||||
tile_set = ExtResource("1_1vaa2")
|
||||
format = 2
|
||||
script = ExtResource("2_7k23r")
|
7
src/other/label_settings.tres
Normal file
7
src/other/label_settings.tres
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_resource type="LabelSettings" format=3 uid="uid://dxx71wu5tfouc"]
|
||||
|
||||
[resource]
|
||||
font_size = 26
|
||||
outline_size = 1
|
||||
outline_color = Color(0, 0, 0, 1)
|
||||
shadow_color = Color(0, 0, 0, 1)
|
123
src/player/player.gd
Normal file
123
src/player/player.gd
Normal file
@@ -0,0 +1,123 @@
|
||||
class_name Player
|
||||
extends CharacterBody2D
|
||||
|
||||
var angle : float = 0
|
||||
var breaking : bool = false
|
||||
@export var energy = 0
|
||||
@export var mass = 50
|
||||
|
||||
var score = 0
|
||||
var coin = 0
|
||||
|
||||
var multiplier = 0;
|
||||
|
||||
|
||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||
var carve_angle : float = PI/1.8
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
|
||||
func reset():
|
||||
energy = 0
|
||||
score = 0
|
||||
coin = 0
|
||||
mass = 50
|
||||
angle = 0
|
||||
carve_angle = PI/1.8
|
||||
|
||||
func _physics_process(delta):
|
||||
var direction = get_global_mouse_position()-position
|
||||
var new_angle : float = direction.angle()-PI/2
|
||||
if(new_angle >= PI):
|
||||
new_angle -= 2*PI
|
||||
if(new_angle <= -PI):
|
||||
new_angle += 2*PI
|
||||
|
||||
if(abs(new_angle-angle)>PI/8):
|
||||
new_angle = lerp(angle, new_angle, 0.05)
|
||||
angle = new_angle
|
||||
rotation = angle
|
||||
|
||||
var delta_height = sin(atan(Global.slope)) * sin(angle+PI/2) * delta
|
||||
energy += mass * gravity * delta_height * Global.TILE_SCALE
|
||||
if(energy <= 0): energy = 0
|
||||
|
||||
var speed = sqrt(2*energy/mass)
|
||||
var friction = 0.5* (speed**2) * delta
|
||||
breaking = Input.is_key_pressed(KEY_SPACE)
|
||||
if(Input.is_key_pressed(KEY_SPACE)):
|
||||
friction += max(10* (speed**2) * delta,1.2*1e3)
|
||||
if(angle > 0):
|
||||
rotation -= PI/2
|
||||
else:
|
||||
rotation += PI/2
|
||||
|
||||
energy -= 0.5 * friction**2 / mass
|
||||
if(energy <= 0):
|
||||
energy = 0
|
||||
var f_speed = sqrt(2*energy/mass)
|
||||
var kmh_speed = f_speed*1000 / 3600
|
||||
|
||||
$skin.scale.x = -1 if(angle > 0) else 1
|
||||
$speed.visible = !breaking && kmh_speed > 50
|
||||
$speed.play()
|
||||
$break.visible = breaking && kmh_speed > 15
|
||||
$break.play()
|
||||
$break.position.x = -10 if angle>0 else +10
|
||||
$break.scale.x = -1 if angle>0 else +1
|
||||
|
||||
var new_vy = f_speed * sin(angle+PI/2)
|
||||
var new_vx = f_speed * cos(angle+PI/2)
|
||||
|
||||
velocity.y = new_vy
|
||||
velocity.x = new_vx
|
||||
|
||||
$Control/BotRight/PlayerSpeed.text = "Player: "+ str(int(kmh_speed))+"km/h"
|
||||
$Control/TopLeft/Slope.text = "Slope: "+ str(int(Global.slope*100))+"%"
|
||||
$Control/TopLeft/AvalancheSpeed.text = "Avalanche: "+ str(int(Global.avalanche.kmh_speed))+"km/h"
|
||||
$Control/TopRight/Score.text = "Score: "+str(int(score))
|
||||
$Control/TopRight/Coin.text = "Gold: "+str(int(coin))
|
||||
|
||||
move_and_slide()
|
||||
for i in range(get_slide_collision_count()):
|
||||
var curcol = get_slide_collision(i)
|
||||
if(curcol.get_collider().is_in_group("Enemy")):
|
||||
pass
|
||||
else:
|
||||
var wall_friction = max(2* (speed**2) * delta,1e3)
|
||||
energy -= 0.5 * wall_friction**2 / mass
|
||||
if(energy<0):
|
||||
energy = 0
|
||||
|
||||
func ski_col_side(col_angle):
|
||||
var ski_angle_col = rotation-col_angle-PI/2
|
||||
if(ski_angle_col<0): ski_angle_col += 2*PI
|
||||
|
||||
if(ski_angle_col>(PI/2-carve_angle/2) and ski_angle_col<(PI/2+carve_angle/2)):
|
||||
score += 10
|
||||
multiplier = 2.0;
|
||||
pass
|
||||
elif(ski_angle_col>(3*PI/2-carve_angle/2) and ski_angle_col<(3*PI/2+carve_angle/2)):
|
||||
score += 10
|
||||
multiplier = 2.0
|
||||
pass
|
||||
else:
|
||||
var enemy_hit_friction = 1e4
|
||||
multiplier = 0
|
||||
score += 1
|
||||
energy -= 0.5 * enemy_hit_friction**2 / mass
|
||||
if(energy<0):
|
||||
energy = 0
|
||||
|
||||
func _on_entered(body):
|
||||
if(body.is_in_group("Enemy")):
|
||||
ski_col_side(position.angle_to_point(body.position))
|
||||
coin += 1
|
||||
body.queue_free()
|
||||
|
||||
|
||||
|
||||
func _on_area_entered(area):
|
||||
if(area.is_in_group("Avalanche")):
|
||||
Global.reset()
|
40
src/player/player.tres
Normal file
40
src/player/player.tres
Normal file
@@ -0,0 +1,40 @@
|
||||
[gd_resource type="SpriteFrames" load_steps=6 format=3 uid="uid://buvd4q0n2gvrl"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dym8shekf5iwk" path="res://res/Tiles/tile_0059.png" id="1_76fyl"]
|
||||
[ext_resource type="Texture2D" uid="uid://ddw26yfxeee8r" path="res://res/Tiles/tile_0070.png" id="1_nltak"]
|
||||
[ext_resource type="Texture2D" uid="uid://dy8y52aq3bp6w" path="res://res/Tiles/tile_0059_b.png" id="1_xhbww"]
|
||||
[ext_resource type="Texture2D" uid="uid://dnpuc4bbohvwp" path="res://res/Tiles/tile_0059_b_f.png" id="2_hcewj"]
|
||||
[ext_resource type="Texture2D" uid="uid://dktejghq82u8d" path="res://res/Tiles/tile_0059_f.png" id="2_yta5k"]
|
||||
|
||||
[resource]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 0.5,
|
||||
"texture": ExtResource("1_xhbww")
|
||||
}, {
|
||||
"duration": 0.5,
|
||||
"texture": ExtResource("2_hcewj")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"break",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 0.5,
|
||||
"texture": ExtResource("1_76fyl")
|
||||
}, {
|
||||
"duration": 0.5,
|
||||
"texture": ExtResource("2_yta5k")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"fast",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": ExtResource("1_nltak")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"player",
|
||||
"speed": 5.0
|
||||
}]
|
98
src/player/player.tscn
Normal file
98
src/player/player.tscn
Normal file
@@ -0,0 +1,98 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://uswmt78bbe3f"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/player/player.gd" id="1_5ri3q"]
|
||||
[ext_resource type="SpriteFrames" uid="uid://buvd4q0n2gvrl" path="res://src/player/player.tres" id="1_h8qmi"]
|
||||
[ext_resource type="LabelSettings" uid="uid://dxx71wu5tfouc" path="res://src/other/label_settings.tres" id="3_8tpu5"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_v1cfh"]
|
||||
size = Vector2(8, 13)
|
||||
|
||||
[node name="Player" type="CharacterBody2D" groups=["Player"]]
|
||||
z_index = 3
|
||||
collision_layer = 2
|
||||
collision_mask = 3
|
||||
wall_min_slide_angle = 1.34565
|
||||
script = ExtResource("1_5ri3q")
|
||||
mass = 60
|
||||
|
||||
[node name="speed" type="AnimatedSprite2D" parent="."]
|
||||
position = Vector2(0, -12)
|
||||
sprite_frames = ExtResource("1_h8qmi")
|
||||
animation = &"fast"
|
||||
|
||||
[node name="break" type="AnimatedSprite2D" parent="."]
|
||||
position = Vector2(10, 0)
|
||||
sprite_frames = ExtResource("1_h8qmi")
|
||||
animation = &"break"
|
||||
|
||||
[node name="skin" type="AnimatedSprite2D" parent="."]
|
||||
sprite_frames = ExtResource("1_h8qmi")
|
||||
animation = &"player"
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
zoom = Vector2(2, 2)
|
||||
|
||||
[node name="SoftCollider" type="Area2D" parent="." groups=["Player"]]
|
||||
collision_layer = 0
|
||||
collision_mask = 12
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape2D" parent="SoftCollider" groups=["Player"]]
|
||||
position = Vector2(0, 1.5)
|
||||
shape = SubResource("RectangleShape2D_v1cfh")
|
||||
|
||||
[node name="WorldCollisionShape" type="CollisionShape2D" parent="." groups=["Player"]]
|
||||
position = Vector2(0, 1.5)
|
||||
shape = SubResource("RectangleShape2D_v1cfh")
|
||||
|
||||
[node name="Control" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="TopLeft" type="VBoxContainer" parent="Control"]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="Slope" type="Label" parent="Control/TopLeft"]
|
||||
layout_mode = 2
|
||||
text = "10%"
|
||||
label_settings = ExtResource("3_8tpu5")
|
||||
|
||||
[node name="AvalancheSpeed" type="Label" parent="Control/TopLeft"]
|
||||
layout_mode = 2
|
||||
text = "0 km/h"
|
||||
label_settings = ExtResource("3_8tpu5")
|
||||
|
||||
[node name="BotRight" type="VBoxContainer" parent="Control"]
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -55.0
|
||||
offset_top = -40.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
|
||||
[node name="PlayerSpeed" type="Label" parent="Control/BotRight"]
|
||||
layout_mode = 2
|
||||
text = "0 km/h"
|
||||
label_settings = ExtResource("3_8tpu5")
|
||||
|
||||
[node name="TopRight" type="VBoxContainer" parent="Control"]
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -70.0
|
||||
offset_bottom = 40.0
|
||||
grow_horizontal = 0
|
||||
|
||||
[node name="Score" type="Label" parent="Control/TopRight"]
|
||||
layout_mode = 2
|
||||
text = "Score: 0"
|
||||
label_settings = ExtResource("3_8tpu5")
|
||||
|
||||
[node name="Coin" type="Label" parent="Control/TopRight"]
|
||||
layout_mode = 2
|
||||
text = "Coin: 0"
|
||||
label_settings = ExtResource("3_8tpu5")
|
||||
|
||||
[connection signal="area_entered" from="SoftCollider" to="." method="_on_area_entered"]
|
||||
[connection signal="body_entered" from="SoftCollider" to="." method="_on_entered"]
|
Reference in New Issue
Block a user