Skip to content

Commit

Permalink
added main menu and music
Browse files Browse the repository at this point in the history
  • Loading branch information
acapitani committed Dec 30, 2019
1 parent 3d7073d commit 365b4da
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 5 deletions.
Binary file added assets/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions assets/menu.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/menu.png-507092a63be01007fcca0624aab4189b.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/menu.png"
dest_files=[ "res://.import/menu.png-507092a63be01007fcca0624aab4189b.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
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Binary file added assets/title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions assets/title.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/title.png-f520a0d529e74edf0d3ba77895c4527c.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/title.png"
dest_files=[ "res://.import/title.png-f520a0d529e74edf0d3ba77895c4527c.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
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
12 changes: 11 additions & 1 deletion game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const FLOOR_Y = 142
const LIMIT_LEFT = 20
const LIMIT_RIGHT = 300

const MODE_1PVSCPU = 0
const MODE_1PVS2P = 1
const MODE_CPUVSCPU = 2

var player = null setget _set_player, _get_player
var main = null
var gamestate setget _set_gamestate
var game_mode = 0
#===========================
func _set_player( v ):
player = weakref( v )
Expand All @@ -23,6 +28,11 @@ func set_initial_gamestate():
gamestate = {
"cur_scene": ""
}
game_mode = MODE_1PVSCPU

func set_game_mode(mode):
game_mode = mode

func _set_gamestate( v ):
gamestate = v
if main != null:
Expand All @@ -36,7 +46,7 @@ func _ready():
set_initial_gamestate()
Engine.set_target_fps(Engine.get_iterations_per_second())

var songs = [preload( "res://music/titlesong.ogg" )]
var songs = [preload( "res://music/music.ogg" )]

var cursong = -1
func play_music( no ):
Expand Down
7 changes: 5 additions & 2 deletions main.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
extends Node2D

const FIRST_SCN = "res://scenes/scene_china.tscn"
const MENU_SCN = "res://scenes/scene_china.tscn"
#const FIRST_SCN = "res://scenes/scene_china.tscn"
#const MENU_SCN = "res://scenes/scene_china.tscn"

const FIRST_SCN = "res://scenes/start_menu/start_menu.tscn"
const MENU_SCN = "res://scenes/start_menu/start_menu.tscn"

func _ready():
game.main = self
Expand Down
Binary file added music/Epic Chinese Music - Kung Fu.mp3
Binary file not shown.
Binary file added music/music.ogg
Binary file not shown.
15 changes: 15 additions & 0 deletions music/music.ogg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[remap]

importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/music.ogg-4e39d6369ac4db9d479436fd6d94c7d1.oggstr"

[deps]

source_file="res://music/music.ogg"
dest_files=[ "res://.import/music.ogg-4e39d6369ac4db9d479436fd6d94c7d1.oggstr" ]

[params]

loop=true
loop_offset=0
4 changes: 3 additions & 1 deletion player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,9 @@ func cpu_check_block():
# ------------------------ CPU AI --------------------------------------

func wataa():
$mplayer.mplay(preload("res://sfx/wataa.wav"))
var p = randi()%4
if p==1:
$mplayer.mplay(preload("res://sfx/wataa.wav"))

func shout():
var n = randi()%6
Expand Down
2 changes: 1 addition & 1 deletion scenes/scene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func _ready():
input_timer.connect( "timeout", self, "_on_input_timer_timeout" )
add_child( input_timer )
input_timer.start()
#game.play_music( 0 )
game.play_music( 0 )

func _on_input_timer_timeout():
can_input = true
Expand Down
9 changes: 9 additions & 0 deletions scenes/scene_china.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ func _ready():
func _setup_players():
$player1.other_player = $player2
$player2.other_player = $player1
if game.game_mode==game.MODE_1PVSCPU:
$player1.player_num = 1
$player2.player_num = 0
elif game.game_mode==game.MODE_1PVS2P:
$player1.player_num = 1
$player2.player_num = 2
elif game.game_mode==game.MODE_CPUVSCPU:
$player1.player_num = -1
$player2.player_num = 0

func gong():
$mplayer.mplay(preload("res://sfx/gong.wav"))
61 changes: 61 additions & 0 deletions scenes/start_menu/menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
extends Node2D

signal selected_item


var cur_pos = 0
var nxt_pos = 0
var max_pos = 0
var items = []
var unselectable_items = []
func _ready():
print( game.gamestate )
items = get_children()
for idx in range( 1, items.size() ):
items[idx].modulate.a = 0.3#set_opacity( 0.3 )
max_pos = items.size() - 1

func set_active( v ):
if v: set_physics_process( true )
else: set_physics_process( false )

func set_unselectable_item( no ):
items[no].modulate.a = 0.1#set_opacity( 0.1 )
unselectable_items.append( no )

func _physics_process(delta):
if Input.is_action_just_pressed( "btn_action" ):
#SoundManager.Play("inter_confirm")
emit_signal( "selected_item", cur_pos )
set_physics_process( false )
return
if Input.is_action_just_pressed( "btn_down" ):
if unselectable_items.find( nxt_pos + 1 ) != -1:
if nxt_pos + 2 <= max_pos:
nxt_pos += 2
else:
nxt_pos += 1
elif Input.is_action_just_pressed( "btn_up" ):
if unselectable_items.find( nxt_pos - 1 ) != -1:
if nxt_pos - 2 >= 0:
nxt_pos -= 2
else:
nxt_pos -= 1

if nxt_pos < 0: nxt_pos = 0
elif nxt_pos > max_pos: nxt_pos = max_pos

if nxt_pos != cur_pos:
cur_pos = nxt_pos
_update_pos( cur_pos )

func _update_pos( pos ):
for idx in range( items.size() ):
if idx == pos:
items[idx].modulate.a = 1#set_opacity( 1 )
else:
if unselectable_items.find( idx ) == -1:
items[idx].modulate.a = 0.3#set_opacity( 0.3 )
else:
items[idx].modulate.a = 0.1#set_opacity( 0.1 )

6 changes: 6 additions & 0 deletions scenes/start_menu/menu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]

[ext_resource path="res://scenes/start_menu/menu.gd" type="Script" id=1]

[node name="menu" type="Node2D"]
script = ExtResource( 1 )
30 changes: 30 additions & 0 deletions scenes/start_menu/start_menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extends "res://scenes/scene.gd"

var nxt_level = "res://scenes/scene_china.tscn"

func _ready():
#if game.gamestate.cur_level.empty():
# $menu.unselectable_items.append( 1 )
#game.play_music( 2 )
pass

func _on_menu_selected_item( itemno ):
match itemno:
0:
# 1P vs CPU
print("player vs cpu")
game.set_initial_gamestate()
game.set_game_mode(game.MODE_1PVSCPU)
emit_signal( "finished_level", nxt_level )
1:
# 1P vs 1P
print("player vs player")
game.set_initial_gamestate()
game.set_game_mode(game.MODE_1PVS2P)
emit_signal( "finished_level", nxt_level )
2:
# CPU vs CPU
print("cpu vs cpu")
game.set_initial_gamestate()
game.set_game_mode(game.MODE_CPUVSCPU)
emit_signal( "finished_level", nxt_level )
40 changes: 40 additions & 0 deletions scenes/start_menu/start_menu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[gd_scene load_steps=6 format=2]

[ext_resource path="res://scenes/start_menu/start_menu.gd" type="Script" id=1]
[ext_resource path="res://assets/china-background.png" type="Texture" id=2]
[ext_resource path="res://scenes/start_menu/menu.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/menu.png" type="Texture" id=4]
[ext_resource path="res://assets/title.png" type="Texture" id=5]

[node name="start_menu" type="Node2D"]
script = ExtResource( 1 )

[node name="background" type="Sprite" parent="."]
texture = ExtResource( 2 )
offset = Vector2( 160, 100 )

[node name="menu" parent="." instance=ExtResource( 3 )]
position = Vector2( -1, 0 )

[node name="player_vs_cpu" type="Sprite" parent="menu"]
position = Vector2( 158, 103 )
texture = ExtResource( 4 )
region_enabled = true
region_rect = Rect2( 24, 59, 109, 27 )

[node name="player_vs_player" type="Sprite" parent="menu"]
position = Vector2( 158, 135 )
texture = ExtResource( 4 )
region_enabled = true
region_rect = Rect2( 32, 91, 96, 21 )

[node name="cpu_vs_cpu" type="Sprite" parent="menu"]
position = Vector2( 159, 164 )
texture = ExtResource( 4 )
region_enabled = true
region_rect = Rect2( 26, 118, 107, 23 )

[node name="title" type="Sprite" parent="."]
texture = ExtResource( 5 )
offset = Vector2( 160, 16 )
[connection signal="selected_item" from="menu" to="." method="_on_menu_selected_item"]
Binary file modified sfx/.DS_Store
Binary file not shown.

0 comments on commit 365b4da

Please sign in to comment.