Skip to content

Commit

Permalink
what
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamBui committed Dec 4, 2015
2 parents 2e19870 + c54b146 commit 7994d03
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 128 deletions.
8 changes: 8 additions & 0 deletions actors.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ type part_typ =
| GoombaSquish
| BrickChunkL
| BrickChunkR
| Score100
| Score200
| Score400
| Score800
| Score1000
| Score2000
| Score4000
| Score8000

type spawn_typ =
| SPlayer of pl_typ * player_typ
Expand Down
8 changes: 8 additions & 0 deletions actors.mli
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ type part_typ =
| GoombaSquish
| BrickChunkL
| BrickChunkR
| Score100
| Score200
| Score400
| Score800
| Score1000
| Score2000
| Score4000
| Score8000

(*type unbblock_typ =
| Wood
Expand Down
24 changes: 16 additions & 8 deletions director.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,17 @@ let player_attack_enemy s1 o1 typ s2 o2 state context =
dec_health o2;
o1.invuln <- invuln;
o1.vel.y <- ~-. dampen_jump;
( if state.multiplier = 16 then
(update_score state 1600; (None, evolve_enemy o1.dir typ s2 o2 context))
else ( update_score state (100 * state.multiplier);
state.multiplier <- state.multiplier * 2;
(None,(evolve_enemy o1.dir typ s2 o2 context)) ))
if state.multiplier = 8 then begin
update_score state 800;
o2.score <- 800;
(None, evolve_enemy o1.dir typ s2 o2 context)
end else begin
let score = 100 * state.multiplier in
update_score state score;
o2.score <- score;
state.multiplier <- state.multiplier * 2;
(None,(evolve_enemy o1.dir typ s2 o2 context))
end
end

(*enemy_attack_player is used when an enemy kills a player.*)
Expand Down Expand Up @@ -219,7 +225,7 @@ let process_collision dir c1 c2 state =
| Panel -> game_over state
| _ ->
begin match dir with
| South -> state.multiplier <- 0 ; collide_block dir o1; (None, None)
| South -> state.multiplier <- 1 ; collide_block dir o1; (None, None)
| _ -> collide_block dir o1; (None, None)
end
end
Expand Down Expand Up @@ -276,7 +282,9 @@ let update_collidable state (collid:Object.collidable) all_collids =
(* TODO: optimize. Draw static elements only once *)
let obj = Object.get_obj collid in
let spr = Object.get_sprite collid in
if not obj.kill && (in_viewport state.vpt obj.pos || is_player collid) then begin
let viewport_filter = in_viewport state.vpt obj.pos || is_player collid ||
out_of_viewport_below state.vpt obj.pos.y in
if not obj.kill && viewport_filter then begin
obj.grounded <- false;
Object.process_obj obj state.map;
(* Run collision detection if moving object*)
Expand Down Expand Up @@ -329,7 +337,7 @@ let update_loop canvas pair =
let ctx = canvas##getContext (Dom_html._2d_) in
let cwidth = float_of_int canvas##width in
let cheight = float_of_int canvas##height in
let viewport = Viewport.make (cwidth,cheight) (cwidth +. 1000.,cheight) in
let viewport = Viewport.make (cwidth,cheight) (cwidth +. 1088.,cheight) in
let player = fst pair in
let objs = snd pair in
let state = {
Expand Down
16 changes: 13 additions & 3 deletions object.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type obj = {
mutable kill: bool;
mutable health: int;
mutable crouch: bool;
mutable score: int;
}

type collidable =
Expand Down Expand Up @@ -119,6 +120,7 @@ let make ?id:(id=None) ?dir:(dir=Left) spawnable context (posx, posy) =
kill = false;
health = 1;
crouch = false;
score = 0;
} in
(spr,obj)

Expand Down Expand Up @@ -356,10 +358,13 @@ let check_collision c1 c2 =
let kill collid ctx =
match collid with
| Enemy(t,s,o) ->
begin match t with
| Goomba -> [Particle.make GoombaSquish (o.pos.x,o.pos.y) ctx]
let pos = (o.pos.x,o.pos.y) in
let score = if o.score > 0 then [Particle.make_score o.score pos ctx] else [] in
let remains = begin match t with
| Goomba -> [Particle.make GoombaSquish pos ctx]
| _ -> []
end
end in
score @ remains
| Block(t,s,o) ->
begin match t with
| Brick ->
Expand All @@ -371,4 +376,9 @@ let kill collid ctx =
[p1;p2;p3;p4]
| _ -> []
end
| Item(t,s,o) ->
begin match t with
| Mushroom -> [Particle.make_score 1000 (o.pos.x,o.pos.y) ctx]
| _ -> []
end
| _ -> []
2 changes: 1 addition & 1 deletion object.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type obj = {
mutable kill: bool;
mutable health: int;
mutable crouch: bool;
mutable score: int;
}

type collidable =
Expand All @@ -45,7 +46,6 @@ val get_sprite : collidable -> Sprite.sprite

val get_obj : collidable -> obj

val get_typ : collidable ->
(* Creates a new object with a given
* actor type on the the canvas at a given position *)
val spawn : Actors.spawn_typ -> Dom_html.canvasRenderingContext2D Js.t
Expand Down
23 changes: 22 additions & 1 deletion particle.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ let make_type typ ctx =
| GoombaSquish as t -> make_params (Sprite.make_particle t ctx) 0. 30
| BrickChunkL as t -> make_params (Sprite.make_particle t ctx) 0. 300
| BrickChunkR as t -> make_params (Sprite.make_particle t ctx) 0. 300

| Score100 as t -> make_params (Sprite.make_particle t ctx) 0. 30
| Score200 as t -> make_params (Sprite.make_particle t ctx) 0. 30
| Score400 as t -> make_params (Sprite.make_particle t ctx) 0. 30
| Score800 as t -> make_params (Sprite.make_particle t ctx) 0. 30
| Score1000 as t -> make_params (Sprite.make_particle t ctx) 0. 30
| Score2000 as t -> make_params (Sprite.make_particle t ctx) 0. 30
| Score4000 as t -> make_params (Sprite.make_particle t ctx) 0. 30
| Score8000 as t -> make_params (Sprite.make_particle t ctx) 0. 30

let make ?vel:(vel=(0.,0.)) ?acc:(acc=(0.,0.)) part_type pos ctx =
let params = make_type part_type ctx in
let pos = pair_to_xy pos and vel = pair_to_xy vel and acc = pair_to_xy acc in
Expand All @@ -53,6 +61,19 @@ let make ?vel:(vel=(0.,0.)) ?acc:(acc=(0.,0.)) part_type pos ctx =
life = params.lifetime;
}

let make_score score pos ctx =
let t = match score with
| 100 -> Score100
| 200 -> Score200
| 400 -> Score400
| 800 -> Score800
| 1000 -> Score1000
| 2000 -> Score2000
| 4000 -> Score4000
| 8000 -> Score8000
| _ -> Score100
in make ~vel:(0.5,-0.7) t pos ctx

let update_vel part =
part.vel.x <- (part.vel.x +. part.acc.x);
part.vel.y <- (part.vel.y +. part.acc.y)
Expand Down
1 change: 1 addition & 0 deletions particle.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ type particle = {

val make : ?vel:float*float -> ?acc:float*float -> Actors.part_typ -> float*float -> Dom_html.canvasRenderingContext2D Js.t -> particle

val make_score : int -> float*float -> Dom_html.canvasRenderingContext2D Js.t -> particle
val process : particle -> unit
Loading

0 comments on commit 7994d03

Please sign in to comment.