Browse Source

more physics on car

master
as4s4hetic 3 years ago
parent
commit
ba72a1b379
  1. 12
      Scenes/Car.tscn
  2. 50
      Scripts/Car.gd
  3. 1
      Scripts/ScrollCamera.gd
  4. BIN
      Sprites/alistair/car-full-2a.png
  5. 35
      Sprites/alistair/car-full-2a.png.import
  6. BIN
      Sprites/alistair/car-full-3a.png
  7. 35
      Sprites/alistair/car-full-3a.png.import
  8. 2
      Story/Ch1S1.tscn

12
Scenes/Car.tscn

@ -1,10 +1,12 @@ @@ -1,10 +1,12 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://Car.gd" type="Script" id=1]
[ext_resource path="res://Scripts/Car.gd" type="Script" id=1]
[ext_resource path="res://Sprites/alistair/car-full-1.png" type="Texture" id=2]
[ext_resource path="res://Sprites/alistair/car-full-2.png" type="Texture" id=3]
[ext_resource path="res://Sprites/alistair/car-full.png" type="Texture" id=4]
[ext_resource path="res://Sprites/alistair/car-full-3.png" type="Texture" id=5]
[ext_resource path="res://Sprites/alistair/car-full-3a.png" type="Texture" id=6]
[ext_resource path="res://Sprites/alistair/car-full-2a.png" type="Texture" id=7]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
@ -12,6 +14,11 @@ animations = [ { @@ -12,6 +14,11 @@ animations = [ {
"loop": true,
"name": "default",
"speed": 5.0
}, {
"frames": [ ExtResource( 4 ), ExtResource( 2 ), ExtResource( 7 ), ExtResource( 6 ) ],
"loop": true,
"name": "Accelerate",
"speed": 20.0
} ]
[sub_resource type="CapsuleShape2D" id=2]
@ -24,6 +31,7 @@ script = ExtResource( 1 ) @@ -24,6 +31,7 @@ script = ExtResource( 1 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
position = Vector2( 0, -42 )
frames = SubResource( 1 )
animation = "Accelerate"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, 3 )

50
Scripts/Car.gd

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
extends KinematicBody2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
var moveSpeed : int = 280
var vel = Vector2()
var facingDir = Vector2()
onready var rayCast = $RayCast2D
onready var anim = $AnimatedSprite
func _ready():
pass
func _physics_process(delta):
handle_movements()
manage_animations()
func handle_movements():
vel = Vector2(-1, 0)
# inputs
if Input.is_action_pressed("move_up"):
vel.y = -1
if Input.is_action_pressed("move_down"):
vel.y = 1
if Input.is_action_pressed("move_left"):
moveSpeed += 5
else:
moveSpeed -= 1
if Input.is_action_pressed("move_right"):
moveSpeed -= 5
moveSpeed = clamp(moveSpeed, 280, 500)
# move the player
move_and_slide(vel * moveSpeed, Vector2.ZERO)
func play_animation (anim_name):
if anim.animation != anim_name:
anim.play(anim_name)
func manage_animations ():
if Input.is_action_pressed("move_left"):
play_animation("Accelerate")
else:
play_animation("default")

1
Scripts/ScrollCamera.gd

@ -18,3 +18,4 @@ onready var target = get_node("../Player") @@ -18,3 +18,4 @@ onready var target = get_node("../Player")
func _process (delta):
position = target.position
position.y -= 240
position.x -= 480

BIN
Sprites/alistair/car-full-2a.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

35
Sprites/alistair/car-full-2a.png.import

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/car-full-2a.png-0f64cdfb4ad576205590422cb4a652b5.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/alistair/car-full-2a.png"
dest_files=[ "res://.import/car-full-2a.png-0f64cdfb4ad576205590422cb4a652b5.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

BIN
Sprites/alistair/car-full-3a.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

35
Sprites/alistair/car-full-3a.png.import

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/car-full-3a.png-376bde5618312891a4e2f322b963c7d6.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Sprites/alistair/car-full-3a.png"
dest_files=[ "res://.import/car-full-3a.png-376bde5618312891a4e2f322b963c7d6.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

2
Story/Ch1S1.tscn

@ -119,7 +119,7 @@ motion_mirroring = Vector2( 2880, 0 ) @@ -119,7 +119,7 @@ motion_mirroring = Vector2( 2880, 0 )
tile_set = ExtResource( 1 )
cell_y_sort = true
format = 1
tile_data = PoolIntArray( -262132, 536870935, 0, -262113, 536870935, 0, -196608, 24, 0, -65499, 536870934, 0, 17, 28, 0 )
tile_data = PoolIntArray( -262132, 536870935, 0, -262113, 536870935, 0, -196608, 24, 0, -65499, 536870934, 0, 19, 536870940, 0 )
[node name="Grass" type="TileMap" parent="Background/Close"]
tile_set = ExtResource( 1 )

Loading…
Cancel
Save