Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2dd2c13b19 | |||
| 29b125f5af | |||
| 2e494502a8 |
6
Week3Readme.md
Normal file
6
Week3Readme.md
Normal file
@ -0,0 +1,6 @@
|
||||
Here in week3 we have several missions to achieve.
|
||||
|
||||
1. Update the Bullet with some graphics
|
||||
2. Update the player with graphics and a state-machine
|
||||
3. Update the destroy function in SceneManager to stash bullets
|
||||
4. Update level loading in GameController and SceneManager
|
||||
BIN
assets/graphics/player/charge/Player Punch 64x64.png
Normal file
BIN
assets/graphics/player/charge/Player Punch 64x64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
40
assets/graphics/player/charge/Player Punch 64x64.png.import
Normal file
40
assets/graphics/player/charge/Player Punch 64x64.png.import
Normal file
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://t2wrpg2jjey2"
|
||||
path="res://.godot/imported/Player Punch 64x64.png-3a937f356fef19bd687f033e25d25550.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/graphics/player/charge/Player Punch 64x64.png"
|
||||
dest_files=["res://.godot/imported/Player Punch 64x64.png-3a937f356fef19bd687f033e25d25550.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/graphics/player/idle/Player Idle 48x48.png
Normal file
BIN
assets/graphics/player/idle/Player Idle 48x48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
40
assets/graphics/player/idle/Player Idle 48x48.png.import
Normal file
40
assets/graphics/player/idle/Player Idle 48x48.png.import
Normal file
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bhjnspvqa20rc"
|
||||
path="res://.godot/imported/Player Idle 48x48.png-9f43f14976963a2821a06ddf8579a76a.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/graphics/player/idle/Player Idle 48x48.png"
|
||||
dest_files=["res://.godot/imported/Player Idle 48x48.png-9f43f14976963a2821a06ddf8579a76a.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/graphics/player/jump_fall/player jump 48x48.png
Normal file
BIN
assets/graphics/player/jump_fall/player jump 48x48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1021 B |
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c84o6tpt2h0s8"
|
||||
path="res://.godot/imported/player jump 48x48.png-bb6ba8ccf76c9bd3765199af95f48c3c.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/graphics/player/jump_fall/player jump 48x48.png"
|
||||
dest_files=["res://.godot/imported/player jump 48x48.png-bb6ba8ccf76c9bd3765199af95f48c3c.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
BIN
assets/graphics/player/running/player run 48x48.png
Normal file
BIN
assets/graphics/player/running/player run 48x48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
40
assets/graphics/player/running/player run 48x48.png.import
Normal file
40
assets/graphics/player/running/player run 48x48.png.import
Normal file
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://jdvo0dp5qvnd"
|
||||
path="res://.godot/imported/player run 48x48.png-3529730a2a1b5884902527ab512e774d.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/graphics/player/running/player run 48x48.png"
|
||||
dest_files=["res://.godot/imported/player run 48x48.png-3529730a2a1b5884902527ab512e774d.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
@ -1,9 +1,228 @@
|
||||
[gd_scene format=3 uid="uid://byl4bdrupii3k"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b1obldvd2etx7" path="res://scripts/player.gd" id="1_3vyb7"]
|
||||
[ext_resource type="Texture2D" uid="uid://c84o6tpt2h0s8" path="res://assets/graphics/player/jump_fall/player jump 48x48.png" id="2_dqkch"]
|
||||
[ext_resource type="Texture2D" uid="uid://t2wrpg2jjey2" path="res://assets/graphics/player/charge/Player Punch 64x64.png" id="2_qlg0r"]
|
||||
[ext_resource type="Texture2D" uid="uid://bhjnspvqa20rc" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="3_qlg0r"]
|
||||
[ext_resource type="Texture2D" uid="uid://jdvo0dp5qvnd" path="res://assets/graphics/player/running/player run 48x48.png" id="4_tuyoq"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
|
||||
atlas = ExtResource("2_qlg0r")
|
||||
region = Rect2(192, 0, 64, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"]
|
||||
atlas = ExtResource("2_dqkch")
|
||||
region = Rect2(96, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(0, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(48, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(96, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(144, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_3v2ag"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(192, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_jej6c"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(240, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_f1ej7"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(288, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_oprun"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(336, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_a8ls1"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(384, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qfm1y"]
|
||||
atlas = ExtResource("3_qlg0r")
|
||||
region = Rect2(432, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_fulsm"]
|
||||
atlas = ExtResource("2_dqkch")
|
||||
region = Rect2(0, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_4r5pv"]
|
||||
atlas = ExtResource("2_dqkch")
|
||||
region = Rect2(48, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_60mlk"]
|
||||
atlas = ExtResource("4_tuyoq")
|
||||
region = Rect2(0, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_i4ail"]
|
||||
atlas = ExtResource("4_tuyoq")
|
||||
region = Rect2(48, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_a38lo"]
|
||||
atlas = ExtResource("4_tuyoq")
|
||||
region = Rect2(96, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_4ni07"]
|
||||
atlas = ExtResource("4_tuyoq")
|
||||
region = Rect2(144, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_l71n6"]
|
||||
atlas = ExtResource("4_tuyoq")
|
||||
region = Rect2(192, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ke2ow"]
|
||||
atlas = ExtResource("4_tuyoq")
|
||||
region = Rect2(240, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ujl30"]
|
||||
atlas = ExtResource("4_tuyoq")
|
||||
region = Rect2(288, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_31cv2"]
|
||||
atlas = ExtResource("4_tuyoq")
|
||||
region = Rect2(336, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qlg0r"]
|
||||
atlas = ExtResource("2_qlg0r")
|
||||
region = Rect2(192, 0, 64, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_pf23h"]
|
||||
atlas = ExtResource("2_qlg0r")
|
||||
region = Rect2(256, 0, 64, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_dt7fs"]
|
||||
atlas = ExtResource("2_qlg0r")
|
||||
region = Rect2(320, 0, 64, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wqfne"]
|
||||
atlas = ExtResource("2_qlg0r")
|
||||
region = Rect2(384, 0, 64, 64)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_pf23h"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_tuyoq")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"charging",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_fjrip")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"falling",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_smehm")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ur7pv")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_y4r1p")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_d2wvv")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_3v2ag")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_jej6c")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_f1ej7")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_oprun")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_a8ls1")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_qfm1y")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"idle",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_fulsm")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_4r5pv")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"jumping",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_60mlk")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_i4ail")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_a38lo")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_4ni07")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_l71n6")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ke2ow")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ujl30")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_31cv2")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"running",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_qlg0r")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_pf23h")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_dt7fs")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_wqfne")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"shoving",
|
||||
"speed": 12.0
|
||||
}]
|
||||
|
||||
[node name="Player" type="CharacterBody2D" unique_id=2145223914]
|
||||
scale = Vector2(1.4799998, 1.4799998)
|
||||
script = ExtResource("1_3vyb7")
|
||||
@ -24,3 +243,12 @@ position = Vector2(12.837839, -8.1081085)
|
||||
|
||||
[node name="LeftSpawn" type="Marker2D" parent="." unique_id=374152113]
|
||||
position = Vector2(-12.837839, -8.108109)
|
||||
|
||||
[node name="PlayerGraphic" type="AnimatedSprite2D" parent="." unique_id=1317034627]
|
||||
texture_filter = 1
|
||||
position = Vector2(0, -6.081082)
|
||||
sprite_frames = SubResource("SpriteFrames_pf23h")
|
||||
animation = &"shoving"
|
||||
autoplay = "idle"
|
||||
|
||||
[connection signal="animation_finished" from="PlayerGraphic" to="." method="_on_animation_finished"]
|
||||
|
||||
@ -49,6 +49,8 @@ func crateTotal(howmany):
|
||||
func bulletDamage(body, _bullet)->void:
|
||||
if body.is_in_group("shootable"):
|
||||
destroySignal.emit(body)
|
||||
destroySignal.emit(_bullet)
|
||||
|
||||
func rocketDamage(body, rocket)->void:
|
||||
if body.is_in_group("shootable"):
|
||||
print("Rocket strikes target!")
|
||||
|
||||
@ -6,6 +6,7 @@ signal fireSignal(markerPosition, direction, speed)
|
||||
@onready var left_cast: RayCast2D = $LeftCast
|
||||
@onready var right_spawn: Marker2D = $RightSpawn
|
||||
@onready var left_spawn: Marker2D = $LeftSpawn
|
||||
@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic
|
||||
|
||||
var pushRightEnabled = false
|
||||
var pushLeftEnabled = false
|
||||
@ -17,27 +18,48 @@ const JUMP_VELOCITY = -400.0
|
||||
|
||||
enum FaceDirection {RIGHT,LEFT}
|
||||
var facing:FaceDirection = FaceDirection.RIGHT
|
||||
#State Handling
|
||||
enum PlayerState {IDLE, RUNNING, JUMPING, FALLING, CHARGING, SHOVING}
|
||||
var current_player_state:PlayerState = PlayerState.IDLE
|
||||
var upJump:bool = false
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
|
||||
handle_input()
|
||||
handle_movement(delta)
|
||||
#States and Animation
|
||||
handle_update_states()
|
||||
handle_update_animation()
|
||||
move_and_slide()
|
||||
handle_collisions()
|
||||
|
||||
|
||||
func handle_input()->void:
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
current_player_state = PlayerState.JUMPING
|
||||
upJump = true
|
||||
# Handle shove.
|
||||
if Input.is_action_just_pressed("shove"):
|
||||
print("I want to shove")
|
||||
pushTimer = Time.get_ticks_msec()
|
||||
if pushRightEnabled and facing==FaceDirection.RIGHT:
|
||||
pushTimer = Time.get_ticks_msec()
|
||||
current_player_state = PlayerState.CHARGING
|
||||
if pushLeftEnabled and facing==FaceDirection.LEFT:
|
||||
pushTimer = Time.get_ticks_msec()
|
||||
current_player_state = PlayerState.CHARGING
|
||||
|
||||
if Input.is_action_just_released("shove"):
|
||||
var pushForce = Time.get_ticks_msec() - pushTimer
|
||||
if pushForce>4000:
|
||||
pushForce=4000
|
||||
if pushRightEnabled and facing==FaceDirection.RIGHT:
|
||||
#deliver the boom
|
||||
current_player_state=PlayerState.SHOVING
|
||||
pushSignal.emit(pushTarget, Vector2(1,0)*100*(pushForce/100))
|
||||
if pushLeftEnabled and facing==FaceDirection.LEFT:
|
||||
current_player_state=PlayerState.SHOVING
|
||||
pushSignal.emit(pushTarget, Vector2(-1,0)*100*(pushForce/100))
|
||||
#Handle Shoot Bullet
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
@ -47,7 +69,7 @@ func _physics_process(delta: float) -> void:
|
||||
FaceDirection.RIGHT:
|
||||
shootSignal.emit(right_spawn.global_transform, 800)
|
||||
FaceDirection.LEFT:
|
||||
shootSignal.emit(left_spawn.global_transform, 800)
|
||||
shootSignal.emit(left_spawn.global_transform, -800)
|
||||
#Handle fire rocket
|
||||
if Input.is_action_just_pressed("fire"):
|
||||
print("Ima fire rocket")
|
||||
@ -63,12 +85,17 @@ func _physics_process(delta: float) -> void:
|
||||
velocity.x = direction * SPEED
|
||||
if direction >0:
|
||||
facing = FaceDirection.RIGHT
|
||||
player_graphic.flip_h = false
|
||||
else:
|
||||
facing = FaceDirection.LEFT
|
||||
player_graphic.flip_h = true
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
func handle_movement(delta)->void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
func handle_collisions()->void:
|
||||
if right_cast.is_colliding():
|
||||
print("Right raycast collision")
|
||||
var collider = right_cast.get_collider()
|
||||
@ -94,3 +121,42 @@ func _physics_process(delta: float) -> void:
|
||||
if c.get_collider() is RigidBody2D:
|
||||
#c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
||||
pushSignal.emit(c.get_collider(), -c.get_normal() * 100)
|
||||
|
||||
#New functions for state handling
|
||||
func handle_update_states()->void:
|
||||
match current_player_state:
|
||||
PlayerState.IDLE when velocity.x !=0:
|
||||
current_player_state = PlayerState.RUNNING
|
||||
PlayerState.RUNNING when velocity.x == 0:
|
||||
current_player_state = PlayerState.IDLE
|
||||
PlayerState.JUMPING when velocity.y>0:
|
||||
current_player_state = PlayerState.FALLING
|
||||
PlayerState.FALLING when is_on_floor():
|
||||
if velocity.x == 0:
|
||||
current_player_state = PlayerState.IDLE
|
||||
else:
|
||||
current_player_state = PlayerState.RUNNING
|
||||
|
||||
func handle_update_animation()->void:
|
||||
match current_player_state:
|
||||
PlayerState.IDLE:
|
||||
player_graphic.play("idle")
|
||||
PlayerState.RUNNING:
|
||||
player_graphic.play("running")
|
||||
PlayerState.JUMPING:
|
||||
if upJump:
|
||||
player_graphic.play("jumping")
|
||||
PlayerState.FALLING:
|
||||
player_graphic.play("falling")
|
||||
PlayerState.CHARGING:
|
||||
player_graphic.play("charging")
|
||||
PlayerState.SHOVING:
|
||||
player_graphic.play("shoving")
|
||||
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
match current_player_state:
|
||||
PlayerState.JUMPING:
|
||||
upJump = false
|
||||
PlayerState.SHOVING:
|
||||
current_player_state = PlayerState.IDLE
|
||||
|
||||
@ -47,10 +47,26 @@ func updateCrates()->void:
|
||||
func pushTarget(body,pushDirection)->void:
|
||||
if body is RigidBody2D:
|
||||
body.apply_central_impulse(pushDirection)
|
||||
|
||||
#Stashes bullets off-screen instead of destroying them
|
||||
func stash(bullet:Bullet)->void:
|
||||
var stashPosition:Vector2 = Vector2(-100,-100)
|
||||
bullet.position = stashPosition
|
||||
bullet.setSpeed(0)
|
||||
bullet.set_process(false)
|
||||
|
||||
func destroy(body)->void:
|
||||
if body is Rocket:
|
||||
print("removing rocket")
|
||||
body.queue_free()
|
||||
match body:
|
||||
var bod when bod is Rocket:
|
||||
body.queue_free()
|
||||
var bod when bod is Crate:
|
||||
body.queue_free()
|
||||
var bod when bod is Bullet:
|
||||
print("stash a bullet")
|
||||
stash(body)
|
||||
_:
|
||||
body.queue_free()
|
||||
|
||||
func teleportTarget(body)->void:
|
||||
if body is Crate:
|
||||
var viewport_size = get_viewport().get_visible_rect().size
|
||||
@ -77,6 +93,7 @@ func makeBullet(spawnPosition, speed)->void:
|
||||
var myBullet:Bullet = bulletFactory()
|
||||
myBullet.transform = spawnPosition
|
||||
myBullet.setSpeed(speed)
|
||||
myBullet.set_process(true)
|
||||
|
||||
func rocketFactory()->Rocket:
|
||||
var myRocket:Rocket
|
||||
|
||||
Loading…
Reference in New Issue
Block a user