Created
January 11, 2015 04:37
-
-
Save Zaxuhe/dba572bd7951ba16b8a9 to your computer and use it in GitHub Desktop.
brick breaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local img_fondo; | |
local img_guante; | |
local img_pelota; | |
local pelota_y; | |
local pelota_x; | |
local guante_x; | |
local speed; | |
local f_guante; | |
local f_pelota; | |
local f_paleta; | |
local guantes = []; | |
function init() | |
{ | |
//solo es llamada una vez, al inicio | |
//cargamos imagenes, declaramos variables, etc... | |
//cargamos las imagenes | |
img_fondo = load_asset(1,false); | |
img_guante = load_asset(100,false); | |
img_pelota = load_asset(10,false); | |
f_pelota = phy_create_circle_shape_for_asset(img_pelota, asset_get_width(img_pelota)/2); | |
//phy_shape_set_collision_type(f_pelota,1); | |
//creamos las paredes | |
local pared1 = phy_create_rect_shape(720/2, 0, 720, 20, true); | |
//local pared2 = phy_create_rect_shape(720/2, 1280, 720, 20, true); | |
local pared3 = phy_create_rect_shape(0, 1280/2, 20, 1280, true); | |
local pared4 = phy_create_rect_shape(720, 1280/2, 20, 1280, true); | |
f_paleta = phy_create_rect_shape(720/2, 1200, 100, 20, true); | |
phy_shape_set_elasticy(f_paleta, 1); | |
phy_shape_set_collision_type(f_paleta,3); | |
phy_shape_set_elasticy(pared1, 1); | |
//phy_shape_set_elasticy(pared2, 1); | |
phy_shape_set_elasticy(pared3, 1); | |
phy_shape_set_elasticy(pared4, 1); | |
phy_shape_set_elasticy(f_pelota, 1); | |
phy_shape_set_collision_type(f_pelota, 1); | |
phy_create_collision_handler_begin(1, 2, desaparece); | |
phy_create_collision_handler_begin(1, 3, colisiono_paleta); | |
speed = 10; | |
} | |
function colisiono_paleta(shape1,shape2) | |
{ | |
} | |
function desaparece(shape1,shape2) | |
{ | |
print("colisiono"); | |
//shape1 lo tenemos que destruir porque le pego la pelota | |
foreach(idx,val in guantes) | |
{ | |
if (compare_shapes(shape1,val) == true) | |
{ | |
guantes.remove(idx); | |
phy_remove_shape(val); | |
return; | |
} | |
else if (compare_shapes(shape2,val) == true) | |
{ | |
guantes.remove(idx); | |
phy_remove_shape(val); | |
return; | |
} | |
} | |
} | |
function start_level(level_num) | |
{ | |
//se llama cada vez que salimos de los menus al juego | |
//iniciamos un nivel, puede ser la primera vez o despues de haber hecho game over | |
pelota_y = 1000; | |
pelota_x = random_int(300, 600); | |
phy_move_shape(f_pelota, pelota_x,pelota_y); | |
guante_x = 720/2; | |
phy_shape_set_velocity(f_pelota, 300, -180); | |
foreach(idx,val in guantes) | |
{ | |
phy_remove_shape(val); | |
} | |
guantes = []; | |
//generamos los guantes | |
//10 guantes | |
for (local i = 0; i < 10; i++) | |
{ | |
move_asset(img_guante, 100+i*60, 100); | |
local fg = phy_create_shape_for_asset(img_guante, true); | |
phy_shape_set_collision_type(fg, 2); | |
phy_shape_set_elasticy(fg, 1); | |
guantes.push(fg); | |
} | |
} | |
function update() | |
{ | |
//se llama cada ciclo del juego, excepto cuando ya se llamo wait_for_menu | |
move_asset(img_fondo,720/2,1280/2); | |
//move_asset(img_guante,guante_x,1000); | |
phy_move_shape(f_paleta,guante_x,1200); | |
move_asset(img_pelota,pelota_x,pelota_y); | |
// | |
local pg = phy_get_shape_position(f_pelota); | |
if (pg.y > 1280) | |
{ | |
goto_menu("gameover"); | |
} | |
} | |
function draw() | |
{ | |
//aqui nos encargamos exclusivamente de dibujar, cualquier movimiento se hace en update | |
//movemos el fondo al centro y dibujamos | |
draw_asset(img_fondo); | |
local pg = phy_get_shape_position(f_pelota); | |
move_asset(img_pelota,pg.x,pg.y); | |
draw_asset(img_pelota); | |
foreach(idx,val in guantes) | |
{ | |
local pg = phy_get_shape_position(val); | |
move_asset(img_guante, pg.x, pg.y); | |
draw_asset(img_guante); | |
} | |
draw_text(0, 0, 1, "teest"); | |
} | |
function touch_start(pos_x,pos_y) { | |
//iniciamos touch | |
guante_x = pos_x; | |
} | |
function touch_move(pos_x,pos_y) { | |
//movemos touch | |
guante_x = pos_x; | |
} | |
function touch_end(pos_x,pos_y) { | |
//terminamos touch | |
guante_x = pos_x; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment