Commit inicial.

This commit is contained in:
2013-04-06 19:30:23 +02:00
committed by Valeriano A.R
parent 5b379ff6d3
commit 4e111d881e
223 changed files with 2175 additions and 14598 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
build-*
*.dll
*.exe
*.so
*.so.*

Binary file not shown.

Before

Width:  |  Height:  |  Size: 476 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 366 B

View File

@@ -1,71 +0,0 @@
/***********************************************
* Copyright (c) 2010 Valeriano Alfonso *
***********************************************/
/*
NOTA DE DOMINIO PUBLICO
-----------------------
ImgView es Dominio Publico. Esto significa que se puede hacer con el
lo que se quiera sin haber ninguna garantia de reembolso o idoneidad.
Se aprecia que la fuente sea citada.
*/
#imgview_fondo {
background-image: url(fondo.png);
}
#imgview_imgcargando {
border: 10px solid white;
}
#imgview_fondo a {
padding:0px;
margin:0px;
}
#imgview {
background-color: white;
border: 10px solid white;
}
#imgview img {
border: none;
padding:0px;
margin:0px;
}
#imgview a {
padding:0px;
margin:0px;
}
#imgview_control {
height: 30px;
background-color: white;
}
#imgview_anterior {
background-color: white;
float: left;
width: 50%;
height:32px;
border:0px;
padding:0px;
margin:0px;
background-image:url('anterior.png');
background-repeat:no-repeat;
background-position: 50% 0%;
cursor:pointer;
}
#imgview_siguiente {
background-color: white;
float: right;
width: 50%;
height:32px;
border:0px;
padding:0px;
margin:0px;
background-image:url('siguiente.png');
background-repeat:no-repeat;
background-position: 50% 0%;
cursor:pointer;
}

View File

@@ -1,497 +0,0 @@
/***********************************************
* Copyright (c) 2010 Valeriano Alfonso *
***********************************************/
/*
NOTA DE DOMINIO PUBLICO
-----------------------
ImgView es Dominio Publico. Esto significa que se puede hacer con el
lo que se quiera sin haber ninguna garantia de reembolso o idoneidad.
Se aprecia que la fuente sea citada.
*/
/*
Historial de cambios
--------------------
1.0 2010-1-3 :
* Version inicial.
1.1 2010-1-5 :
* Corregida necesidad de cargar el script en la seccion head.
* Funcionalidad basica de album implementada.
1.2 2010-5-18 :
* Asimilado de todos los enlaces a imagenes en un album general.
* Iconos de anterior y siguiente de los albums, nuevos.
*/
/////////////////////////
// Configuracion
//
var imgview_prefix = ""; // Se atoconfigura
var imgview_border = 10; // Tambien ajustar en el CSS.
var imgview_control_alto = 32; // Tambien ajustar en el CSS.
///////////////////////
// Globales
//
var imgview_nombre_album="";
var imgview_href_anterior="";
var imgview_href_siguiente="";
var imgview_preloader=false;
/////////////////////////////////////
// ImgView_ShowImage
//
function ImgView_ShowImage(href,is_album){
var elemFondo = document.getElementById('imgview_fondo');
var elemImgview = document.getElementById('imgview');
var elemImgviewControl = document.getElementById('imgview_control');
var elemImgCargando = document.getElementById('imgview_imgcargando');
var elemEnlace = document.getElementById('imgview_enlace');
var elemImg = document.getElementById('imgview_img');
var elemAnt = document.getElementById('imgview_anterior');
var elemSig = document.getElementById('imgview_siguiente');
var preloader;
var max_horiz, max_vert;
var ventana_ancho, ventana_alto;
var pagina_ancho, pagina_alto;
var pos_horiz = 0, pos_vert = 0;
if(is_album){
var enlaces;
var imgview_RegExp;
var nombre_temp;
var i,j;
// Buscar imagenes anterior y siguientes
enlaces = document.getElementsByTagName("a");
for(i=0;i<enlaces.length;i++){
if(enlaces[i].getAttribute("href")==href &&
enlaces[i].getAttribute("imgview_albumid")==imgview_nombre_album)
{
// Encontrado el actual
// Buscar Anterior
imgview_href_anterior="";
if(i>0){
j=i-1;
while(j>=0){
if(enlaces[j].getAttribute("imgview_albumid")==
imgview_nombre_album)
{
imgview_href_anterior=enlaces[j].getAttribute("href");
break;
}
j--;
}
}
// Buscar Siguiente
imgview_href_siguiente="";
if(i<(enlaces.length-1)){
j=i+1;
while(j<enlaces.length){
if(enlaces[j].getAttribute("imgview_albumid")==
imgview_nombre_album)
{
imgview_href_siguiente=enlaces[j].getAttribute("href");
break;
}
j++;
}
}
}
}
}
// Obtener maximos de scroll
if(window.innerHeight && window.scrollMaxY) {
max_horiz = document.body.scrollWidth;
max_vert = window.innerHeight + window.scrollMaxY;
}else if(document.body.scrollHeight > document.body.offsetHeight){
// all but Explorer Mac
max_horiz = document.body.scrollWidth;
max_vert = document.body.scrollHeight;
}else{
// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
max_horiz = document.body.offsetWidth;
max_vert = document.body.offsetHeight;
}
// Obtener tamanho de la ventana
if(window.innerHeight) {
// Todos excepto Explorer
ventana_ancho = window.innerWidth;
ventana_alto = window.innerHeight;
}else if(document.documentElement && document.documentElement.clientHeight){
// Explorer 6 Strict
ventana_ancho = document.documentElement.clientWidth;
ventana_alto = document.documentElement.clientHeight;
}else if(document.body){
// Resto de Explorers
ventana_ancho = document.body.clientWidth;
ventana_alto = document.body.clientHeight;
}
// HACK: reducir el tamaho de ventana_ancho. Hace que no sobrepase los bordes
ventana_ancho-=20;
// Obtener el tamanho de la pagina
if(max_vert < ventana_alto){
pagina_alto = ventana_alto;
}else{
pagina_alto = max_vert;
}
if(max_horiz < ventana_ancho){
pagina_ancho = ventana_ancho;
}else{
pagina_ancho = max_horiz;
}
// Obtener posicion del los scrolls
if( typeof( window.pageYOffset ) == 'number' ) {
// La mayoria de navegadores
pos_vert = window.pageYOffset;
pos_horiz = window.pageXOffset;
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
// Explorer
pos_vert = document.body.scrollTop;
pos_horiz = document.body.scrollLeft;
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
// Explorer 6 Strict
pos_vert = document.documentElement.scrollTop;
pos_horiz = document.documentElement.scrollLeft;
}
// Centrar y hacer visible la imagen de cargando
if(elemImgCargando){
elemImgCargando.style.top =
(pos_vert +
((ventana_alto - elemImgCargando.height) / 2)) + 'px';
elemImgCargando.style.left =
(pos_horiz +
((ventana_ancho - elemImgCargando.width) / 2)) + 'px';
elemImgCargando.style.display = 'block';
}
// Hacer que el fondo ocupe la pagina y sea visible
elemFondo.style.height = (pagina_alto + 'px');
elemFondo.style.display = 'block';
// Carga de la imagen
imgview_preloader=new Image();
imgview_preloader.onload=function(){
// Mostrar imgview, necesario para que los tamanhos sean correctos
elemImgview.style.display = 'block';
// Mostrar/Ocultar control de albums
if(is_album){
elemImgviewControl.style.display = 'block';
ventana_alto-=imgview_control_alto;
if(imgview_href_anterior.length==0){
elemAnt.style.display = 'none';
}else{
elemAnt.style.display = 'block';
}
if(imgview_href_siguiente.length==0){
elemSig.style.display = 'none';
}else{
elemSig.style.display = 'block';
}
}else{
elemImgviewControl.style.display = 'none';
}
// Establecer la imagen precargada
elemImg.src = href;
elemImg.width = imgview_preloader.width;
elemImg.height = imgview_preloader.height;
// Ajustar el tamanho de la imagen
var relacion=elemImg.width/elemImg.height;
if((elemImg.height+imgview_border*2)>ventana_alto){
elemImg.height=ventana_alto-imgview_border*2;
elemImg.width=elemImg.height*relacion;
}
if((elemImg.width+imgview_border*2)>ventana_ancho){
elemImg.width=ventana_ancho-imgview_border*2;
elemImg.height=elemImg.width/relacion;
}
// Centrar imgview
elemImgview.style.top =
(pos_vert +
((ventana_alto - elemImg.height) / 2) - imgview_border) + 'px';
elemImgview.style.left =
(pos_horiz +
((ventana_ancho - elemImg.width) / 2) - imgview_border) + 'px';
// Oclultar imagen de cargar y mostrar imgview
if(elemImgCargando) {
elemImgCargando.style.display = 'none';
}
return false;
}
imgview_preloader.src = href;
elemEnlace.href = href;
}
/////////////////////////////////////
// ImgView_Show
//
function ImgView_Show(obj){
imgview_nombre_album=obj.getAttribute("imgview_albumid");
if(imgview_nombre_album){
ImgView_ShowImage(obj.getAttribute("href"),true);
}else{
ImgView_ShowImage(obj.getAttribute("href"),false);
}
}
/////////////////////////////////////
// ImgView_Hide
//
function ImgView_Hide(){
var elemFondo = document.getElementById('imgview_fondo');
var elemImgview = document.getElementById('imgview');
var elemImgCargando = document.getElementById('imgview_imgcargando');
var elemEnlace = document.getElementById('imgview_enlace');
elemFondo.style.display = 'none';
elemImgview.style.display = 'none';
elemImgCargando.style.display = 'none';
imgview_preloader.onload=function(){return false;}
imgview_preloader.src = "";
elemEnlace.href = "";
}
/////////////////////////////////////
// ImgView_ShowAnterior
//
function ImgView_ShowAnterior(obj){
if(imgview_href_anterior.length){
ImgView_ShowImage(imgview_href_anterior,true);
}
}
/////////////////////////////////////
// ImgView_ShowSiguiente
//
function ImgView_ShowSiguiente(obj){
if(imgview_href_siguiente.length){
ImgView_ShowImage(imgview_href_siguiente,true);
}
}
/////////////////////////////////////
// ImgView_Init
//
// Asociar al evento "onclick" la funcion "ImgView_Show" a los links con rel="imgview".
// Anhadir el markup necesario para mostrar imagenes.
function ImgView_Init(){
var i;
var enlaces;
var scripts;
var imgview_RegExp;
var isimage_RegExp;
if (!document.getElementsByTagName){
return;
}
// HACK: Obtener el path donde de este mismo script
scripts=document.getElementsByTagName("script");
imgview_RegExp = /imgview\.js$/i;
for(i=0;i<scripts.length;i++){
if(imgview_RegExp.test(scripts[i].getAttribute("src"))){
imgview_prefix=scripts[i].getAttribute("src").
replace(imgview_RegExp,"");
}
}
if(imgview_prefix.length<1){
imgview_prefix=".";
}
// Iterar los enlaces
enlaces = document.getElementsByTagName("a");
imgview_RegExp = /^imgview\./i;
isimage_RegExp = /\.gif$|\.jpg$|\.jpeg$|\.png$/i;
for(i=0;i<enlaces.length;i++){
link_href=enlaces[i].getAttribute("href");
if(link_href && isimage_RegExp.test(link_href)){
link_rel = enlaces[i].getAttribute("rel")
// Enlace a imagen
if(link_rel == "imgview"){
// Imagen Normal
enlaces[i].onclick =
function () {
ImgView_Show(this);
return false;
}
}else{
if(imgview_RegExp.test(link_rel)){
// Imagen de Album
nombre_album=link_rel.replace(imgview_RegExp,"");
enlaces[i].setAttribute("imgview_albumid",nombre_album);
enlaces[i].onclick =
function () {
ImgView_Show(this);
return false;
}
}else{
// Anhadir en el album global
enlaces[i].setAttribute("imgview_albumid","imgview");
enlaces[i].onclick =
function () {
ImgView_Show(this);
return false;
}
}
}
}
}
// Inyectar el link de la hoja de estilo
var LinkHoja=document.createElement('link');
LinkHoja.rel="stylesheet";
LinkHoja.type="text/css";
LinkHoja.href=imgview_prefix+"/imgview.css";
document.getElementsByTagName("head")[0].appendChild(LinkHoja);
var elemCuerpo = document.body;
// Inyectar markup del fondo con la animacion de carga
var elemFondo = document.createElement("div");
elemFondo.setAttribute('id','imgview_fondo');
elemFondo.onclick =
function () {
ImgView_Hide();
return false;
}
elemFondo.style.display = 'none';
elemFondo.style.position = 'absolute';
elemFondo.style.top = '0';
elemFondo.style.left = '0';
elemFondo.style.zIndex = '90';
elemFondo.style.width = '100%';
elemCuerpo.insertBefore(elemFondo, elemCuerpo.firstChild);
var elemImgCargando = document.createElement("img");
elemImgCargando.src = imgview_prefix+"/cargando.gif";
elemImgCargando.setAttribute('id','imgview_imgcargando');
elemImgCargando.style.position = 'absolute';
elemImgCargando.style.zIndex = '150';
elemImgCargando.style.display = 'none';
elemImgCargando.onclick =
function () {
ImgView_Hide();
return false;
}
elemCuerpo.insertBefore(elemImgCargando, elemCuerpo.firstChild);
// Inyectar markup de imgview
var elemImgview = document.createElement("div");
elemImgview.setAttribute('id','imgview');
elemImgview.style.display = 'none';
elemImgview.style.position = 'absolute';
elemImgview.style.zIndex = '100';
elemCuerpo.insertBefore(elemImgview, elemFondo.nextSibling);
var elemEnlace = document.createElement("a");
elemEnlace.setAttribute('href','#');
elemEnlace.setAttribute('id','imgview_enlace');
elemEnlace.setAttribute('title','Click para cerrar');
elemEnlace.onclick =
function () {
ImgView_Hide();
return false;
}
elemImgview.appendChild(elemEnlace);
var elemImg = document.createElement("img");
elemImg.setAttribute('id','imgview_img');
elemEnlace.appendChild(elemImg);
var elemImgviewControl = document.createElement("div");
elemImgviewControl.setAttribute('id','imgview_control');
elemImgviewControl.style.display = 'none';
elemImgview.appendChild(elemImgviewControl);
var elemImgviewAnterior = document.createElement("div");
elemImgviewAnterior.setAttribute('id','imgview_anterior');
elemImgviewControl.appendChild(elemImgviewAnterior);
elemImgviewAnterior.onclick =
function () {
ImgView_ShowAnterior(this);
return false;
}
var elemImgviewSiguiente = document.createElement("div");
elemImgviewSiguiente.setAttribute('id','imgview_siguiente');
elemImgviewControl.appendChild(elemImgviewSiguiente);
elemImgviewSiguiente.onclick =
function () {
ImgView_ShowSiguiente(this);
return false;
}
// Deshabilitar seleccion de la imagen
elemImgview.onselectstart=function () {return false;}
elemImgview.style.MozUserSelect="none";
elemImg.onselectstart=function () {return false;}
elemImgview.style.MozUserSelect="none";
}
// Asociar la funcion de inciado al evento "onload"
// sin evitar la ejecucion de lo que pudiera estar antes
var imgview_oldonload = window.onload;
if (typeof(imgview_oldonload)!='function'){
window.onload = ImgView_Init;
}else{
window.onload = function(){
imgview_oldonload();
ImgView_Init();
}
}

View File

@@ -1,67 +0,0 @@
-----------------
---- ImgView ----
-----------------
Informacion:
------------
ImgView es un visor de imagenes escrito en Javascript, diseñado para no
entorpecer la navegacion de los usuarios.
Caracteristicas:
----------------
* Apertura de las imagenes en la propia pagina.
* Fundido a negro del resto de la pagina.
* Ajuste del tamaño de las imagenes para que no se salgan de la ventana.
* Conserva la direccion del enlace original.
* Sale clickando en cualquier sitio.
* Soporte para albumes de fotos.
* Asimilacion de todos los enlaces a imagenes por defecto.
Historial:
----------
1.0 2010-1-3 :
* Version inicial.
1.1 2010-1-5 :
* Corregida necesidad de cargar el script en la seccion head.
* Funcionalidad basica de album implementada.
1.2 2010-5-18 :
* Asimilado de todos los enlaces a imagenes en un album general.
* Iconos de anterior y siguiente de los albums, nuevos.
* Ocultado de iconos de anterior siguiente al principio y al
final del album respectivamente.
Instalacion:
------------
Descomprimir en algun directorio accesible al exterior mediante el servidor web.
Uso:
----
Para usarlo hay que cargar el script "imgview.js" en las paginas
donde quiera ser usado:
<script type="text/javascript" src="imgview/imgview.js"></script>
Con esto todos los enlaces a imagenes usaran imgview. Es recomendable
insertar una imagen en miniatura dentro del enlace.
Uso Avanzado:
-------------
Para mostrar una imagen independiente de cualquier album:
<a href="imagen.jpg" rel="imgview"><img src="thumb.jpg"></a>
Para crear albumes independientes; poner a todas las imagenes del mismo grupo
rel="imgview.album", siendo "album" el nombre para esa coleccion:
<a href="imagen1.jpg" rel="imgview.album"><img src="thumb1.jpg"></a>
<a href="imagen2.jpg" rel="imgview.album"><img src="thumb2.jpg"></a>
Licencia:
---------
ImgView es Dominio Publico. Esto significa que se puede hacer con el
lo que se quiera sin haber ninguna garantia de reembolso o idoneidad.
Se aprecia que la fuente sea citada.
Copyright (c) 2010 Valeriano Alfonso

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1003 B

View File

@@ -1,104 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" >
<meta name="author" content="Valeriano Alfonso" >
<meta name="description" content="Lonely Ruins" >
<meta name="keywords" content="linux windows game lonely ruins robot kitten">
<meta name="Copyright" content="Copyright (c) 2011-2012 by Valeriano Alfonso, All Right Reserved">
<meta content="ALL" name="ROBOTS">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="imgview/imgview.js"></script>
<title>Lonely Ruins</title>
</head>
<body>
<div class="contenedor">
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr><td>
<div class="cabecera">
<a class="titulo" href="./"><!-- LOGO--><img src="imagenes/logo_lonelyruins_web.png"></a>
<div class="navbar">
<!-- NAVBAR-->
<div class="menu">
<ul>
<li><a href="#about">About</a></li>
<li><a href="#play">Play</a></li>
<li><a href="#screenshots">Screenshots</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</div>
</div>
<div class="contenido">
<!-- CONTENIDO -->
<!--ABOUT-->
<a name="about"></a>
<h1>About</h1>
You are a robot on a rescue mision.<br>
The rescuer and the rescued are alone<br>
in a strange place.<br>
<br>
Good Luck!<br>
<p>&nbsp;</p>
<!--PLAY-->
<a name="play"></a>
<h1>Play</h1>
<div class="columnContainer">
<div class="column2" style="text-align: center;">
<a href="play.html" class="playLink">&#9658; Play</a>
</div>
<div class="column2" style="text-align: center;">
<a href="https://play.google.com/store/apps/details?id=com.var.lonelyruins"><img alt="Get it on Google Play" src="https://developer.android.com/images/brand/en_generic_rgb_wo_45.png"></a>
</div>
</div>
<p>&nbsp;</p>
<!--SCREENSHOTS-->
<a name="screenshots"></a>
<h1>Screenshots</h1>
<p>
<span style="vertical-align:top;">
<a href="sshots/20120102/shot-20120102-1.png" rel="imgview.lonelyruins"><img src="sshots/20120102/shot-20120102-1.thumb.png"></a>
<a href="sshots/20120102/shot-20120102-2.png" rel="imgview.lonelyruins"><img src="sshots/20120102/shot-20120102-2.thumb.png"></a>
<a href="sshots/20120102/shot-20120102-3.png" rel="imgview.lonelyruins"><img src="sshots/20120102/shot-20120102-3.thumb.png"></a>
</span>
</p>
<p>&nbsp;</p>
<!--CONTACT-->
<a name="contact"></a>
<h1>Contact</h1>
<ul>
<li><a href="http://varstudio.com">VAR Studio (Main site in spanish).</a></li>
</ul>
<p>&nbsp;</p>
<div class="toTop"><a href="#top">Back to top.</a></div>
<p>&nbsp;</p>
<!-- PIE -->
<div class="pie">
<b>Copyright &copy; 2011-2014 <a href="/">Valeriano Alfonso</a>.</b>
</div>
</div>
</td></tr>
</table>
</div>
</body>
</html>

View File

@@ -1,36 +0,0 @@
<?php
// split -b 1024 -a 4 -d game.js game.js
$filelist=array();
$fileout="game.js";
for($i=0;$i<564;$i++){
$filelist[]=sprintf("game.js%04d",$i);
}
// Quitar el limite de tiempo
set_time_limit(0);
// Fusionar ficheros
$out=fopen($fileout,"wb") or die("error creating/opening merged file");
foreach($filelist as $file){
$size=filesize($file);
$in=fopen($file,"rb") or die("error opening file");
$data=fread($in, $size) or die("error reading file");
fclose($in);
fwrite($out,$data,$size) or die("error writing to merged file");
}
fclose($out);
// Limpiar
foreach($filelist as $file){
unlink($file);
}
unlink("join.php");
?>
<html>
<body>
<h1>OK!</h1>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -1,133 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Lonely Ruins</title>
</head>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
font-family: Verdana,Arial,Helvetica,sans-serif;
background-color:#000000;
color: #777777;
font-size: 10pt;
}
h1{
text-align: left;
margin-top: 0;
margin-bottom: 1em;
font-size: 16pt;
font-weight: bold;
}
.header{
margin:0 auto;
width:600px;
padding-top:10px;
text-align:center;
}
.progress-container{
border: 1px solid #808080;
border-radius: 5px;
padding: 5px;
box-shadow: 0px 0px 5px #808080;
}
.progress-container progress{
width:100%;
}
.game-screen-container{
margin:0 auto;
width:640px;
padding-top:10px;
}
.game-screen-container canvas{
border: 1px solid #808080;
border-radius: 5px;
padding: 5px;
box-shadow: 0px 0px 5px #808080;
}
</style>
<body>
<div class="header">
<a class="titulo" href="./"><img
src="imagenes/logo_lonelyruins_web_mini.png"></a>
</div>
<div class="game-screen-container">
<div id="progress-container" class="progress-container">
<h1>Loading...</h1>
<span>Code:</span></br>
<progress id="progress-code" max="1" value="0"></progress></br>
</br>
<span>Data:</span></br>
<progress id="progress-data" max="1" value="0"></progress></br>
</div>
<canvas class="game-screen" id="canvas" style="display:none;"
oncontextmenu="event.preventDefault()"></canvas>
</div>
<script type='text/javascript'>
var Module = {
preRun: [function (){
FS.mkdir('/saves');
FS.mount(IDBFS, {}, '/saves');
addRunDependency("SaveDir");
FS.syncfs(true, function (err) {
removeRunDependency("SaveDir");
});
}],
postRun: [],
canvas: document.getElementById('canvas'),
progressContainer: document.getElementById('progress-container'),
progressCode: document.getElementById('progress-code'),
progressData: document.getElementById('progress-data'),
print: function(text) {
if(console && console.log){
console.log(text);
}
},
printErr: function(text) {
this.print(text);
},
setStatus: function(text) {
this.print(text);
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
if(m){
this.progressData.value = parseInt(m[2]);
this.progressData.max = parseInt(m[4]);
}
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
if(!left){
// All loaded
this.progressContainer.style.display="none";
this.canvas.style.display="block";
}
},
LaunchCode: function (){
var xhr = new XMLHttpRequest();
xhr.open('GET', "game.js", true);
xhr.responseType = 'text';
xhr.onprogress = function(event) {
this.progressCode.value = event.loaded;
this.progressCode.max = event.total;
}.bind(this);
xhr.onload = function(event) {
var packageData = xhr.response;
// Launch loaded code
eval.call(null,packageData);
};
xhr.onerror = function(event) {
alert(event);
};
xhr.send(null);
}
};
Module.LaunchCode();
</script>
<!-- <script async type="text/javascript" src="game.js"></script> -->
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -1,223 +0,0 @@
/***********************************************
* Copyright (c) 2012 Valeriano Alfonso *
***********************************************/
/* Elementos Base */
html, body {
height: 100%;
margin: 0;
padding: 0;
font-family: Verdana,Arial,Helvetica,sans-serif;
background-color:#000000;
color: #777777;
font-size: 10pt;
}
h1{
text-align: left;
margin-top: 0;
margin-bottom: 1em;
font-size: 16pt;
font-weight: bold;
}
h2{
text-align: left;
margin-top: 0;
margin-bottom: 0.75em;
font-size: 14pt;
font-weight: bold;
}
h3{
text-align: left;
margin-top: 0;
margin-bottom: 0.5em;
font-size: 10pt;
font-weight: bold;
}
h4{
margin-top: 0;
margin-bottom: 0.5em;
font-size: 11pt;
font-weight: bold;
}
p,li,td{
margin-top: 0;
margin-bottom: 0.5em;
font-size: 10pt;
}
li {
padding:2px;
}
img {
border:0;
}
/* Links normales */
a {
text-decoration:none;
font-weight: bold;
display:inline;
}
a:link {
color: #7777FF;
}
a:visited {
color: #7777FF;
}
a:hover {
color: #FFFFFF;
text-decoration: underline;
}
a:active {
color: #CBB545;
}
/* Estilo de Lonely Ruins */
.contenedor {
margin: 0;
padding: 0;
float: left;
width: 100%;
min-height: 100%;
}
.cabecera {
width: 700px;
height:130px;
margin: 0 auto;
position: relative;
}
.titulo {
margin:0;
padding:0;
border:0;
vertical-align:bottom;
position:absolute;
}
a.titulo:hover {
background:none;
}
a.titulo img {
border:none;
}
a.titulo:hover img{
border:none;
}
.contenido {
width: 700px;
margin:0;
padding:0;
border:0;
position:relative;
margin: 0 auto;
vertical-align:bottom;
}
.pie {
width:700px;
height: 64px;
margin:0;
padding:0;
border:0;
position:relative;
margin: 0 auto;
font-weight: bold;
}
.navbar {
height:130px;
width:500px;
margin:0;
padding:0;
border:0;
vertical-align:bottom;
position:absolute;
bottom:0px;
right:0px;
}
.navbar ul {
list-style:none;
list-style-type:none;
list-style-position:inside;
border:0;
padding:0;
margin:0;
display:block;
position:absolute;
bottom:0;
right:0;
}
.navbar li{
padding:0px;
float: left;
text-align: center;
vertical-align: bottom;
margin: 1px;
border-left:1px solid #777777;
}
.navbar li:first-child{
border-left:none;
}
/* links del navbar */
.navbar a {
padding: 4px;
font-size:12pt;
display:block;
}
.toTop{
text-align:right;
font-size:7pt;
}
.columnContainer{
white-space: nowrap;
font-size: 0;
vertical-align: top;
}
.column2{
width:50%;
display:inline-block;
font-size: 10pt;
vertical-align:top;
}
.playLink{
font-size:25px;
display: inline-block;
border-radius: 10px;
border: solid 1px grey;
width:127px;
height:43px;
line-height:43px;
}
.playLink:link{
color: #777777;
}
.playLink:hover{
box-shadow: 0 0 5px white;
text-shadow: 0 0 2px white;
border: solid 1px white;
text-decoration:none;
color: white;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

1261
GameEnts.c

File diff suppressed because it is too large Load Diff

View File

@@ -1,51 +1,70 @@
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado) // Copyright (C) 2012 Valeriano Alfonso Rodriguez (Kableado)
#ifndef _GAMEENTS_H_ #ifndef _GAMEENTS_H_
#define _GAMEENTS_H_ #define _GAMEENTS_H_
void GameEnts_Init();
enum { enum {
Ent_Player, Ent_Player,
Ent_Barrel, Ent_Platform,
Ent_Column, Ent_Block,
Ent_Floor,
Ent_Hole_Spiked,
Ent_Hole_Filled,
Ent_Hole_Lava,
Ent_ArrowShooter,
Ent_Arrow,
Ent_SavePoint,
Ent_ExitPoint,
Ent_Teleporter,
Ent_Teleporter_Dest,
Ent_Effect
} EntityType;
extern Entity ent_player;
extern Entity ent_barrel;
extern Entity ent_column;
extern Entity ent_column_faded;
extern Entity ent_rock;
extern Entity ent_lamp;
extern Entity ent_floor;
extern Entity ent_floor_right;
extern Entity ent_floor_left;
extern Entity ent_floor_center;
extern Entity ent_hole_spiked;
extern Entity ent_hole_filled;
extern Entity ent_hole_lava;
extern Entity ent_arrowshooter_up;
extern Entity ent_arrowshooter_down;
extern Entity ent_arrowshooter_left;
extern Entity ent_arrowshooter_right;
extern Entity ent_arrow_up;
extern Entity ent_arrow_down;
extern Entity ent_arrow_left;
extern Entity ent_arrow_right;
extern Entity ent_exitpoint;
extern Entity ent_endpoint;
extern Entity ent_savepoint;
extern Entity ent_teleporter;
extern Entity ent_teleporter_dest;
#endif Ent_Wizard,
Ent_MagikBall,
Ent_Earth,
Ent_EarthBack,
Ent_StoneBrick,
Ent_StoneBrickBack,
Ent_SpikedBush,
Ent_LavaPit,
Ent_Fireball,
Ent_Flower,
Ent_Spike,
Ent_CarnivorePlant,
Ent_Bunny,
Ent_Spider,
Ent_Guard,
Ent_EliteGuard,
Ent_Axe,
Ent_GoatMan,
Ent_Princess
} EntityType;
extern Entity *ent_Player;
extern Entity *ent_Platform;
extern Entity *ent_Block;
extern Entity *ent_Wizard;
extern Entity *ent_MagikBall;
extern Entity *ent_Earth;
extern Entity *ent_EarthBack;
extern Entity *ent_StoneBrick;
extern Entity *ent_StoneBrickBack;
extern Entity *ent_SpikedBush;
extern Entity *ent_LavaPit;
extern Entity *ent_Fireball;
extern Entity *ent_Spike[2];
extern Entity *ent_Flower[2];
extern Entity *ent_CarnivorePlant[2];
extern Entity *ent_Bunny;
extern Entity *ent_Spider;
extern Entity *ent_Axe;
extern Entity *ent_Guard;
extern Entity *ent_EliteGuard;
extern Entity *ent_GoatMan;
extern Entity *ent_Princess;
int EntityApplyGravity(Entity *e);
void EntEarth_Init(Entity *ent,int up,int down,int left,int right);
void EntStoneBrick_Init(Entity *ent,int up,int down,int left,int right);
void GameEnts_Init();
#endif _GAMEENTS_H_

View File

@@ -25,7 +25,7 @@ typedef struct {
// Anim_LoadAnim // Anim_LoadAnim
// //
// //
Anim Anim_LoadAnim(char *fichero,int width,int frames,float fps){ Anim Anim_LoadAnim(char *fichero,int frames,float fps){
DrawImg img; DrawImg img;
Animation *anim; Animation *anim;
int w,h; int w,h;
@@ -39,10 +39,7 @@ Anim Anim_LoadAnim(char *fichero,int width,int frames,float fps){
// Create the animation container // Create the animation container
anim=malloc(sizeof(Animation)); anim=malloc(sizeof(Animation));
anim->img=img; anim->img=img;
anim->w=width; anim->w=w/frames;
if(width<=0){
anim->w=w/frames;
}
anim->fps=fps; anim->fps=fps;
anim->frames=frames; anim->frames=frames;
anim->ftime=1000/fps; anim->ftime=1000/fps;
@@ -101,7 +98,7 @@ void Anim_Draw(Anim a,int time_ms,int x,int y){
Animation *anim=a; Animation *anim=a;
int frame; int frame;
frame=(time_ms/anim->ftime)%anim->frames; frame=(time_ms%anim->time)/anim->ftime;
Draw_DrawImgPart(anim->img,x,y,anim->w,frame); Draw_DrawImgPart(anim->img,x,y,anim->w,frame);
} }

View File

@@ -17,7 +17,7 @@ typedef void *Anim;
// Anim_LoadAnim // Anim_LoadAnim
// //
// //
Anim Anim_LoadAnim(char *fichero,int width,int frames,float fps); Anim Anim_LoadAnim(char *fichero,int frames,float fps);
///////////////////////////// /////////////////////////////

View File

@@ -4,9 +4,6 @@
#define _WIN32_WINNT 0x0501 #define _WIN32_WINNT 0x0501
#include <windows.h> #include <windows.h>
#endif #endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include "Audio.h" #include "Audio.h"
@@ -18,35 +15,30 @@ static void Audio_MixerCallback(void *ud,Uint8 *stream,int l);
// AudioWave // // AudioWave //
/////////////// ///////////////
// Reference to a sound. // Reference to a sound.
typedef struct TAudioWave TAudioWave, *AudioWave; typedef struct Tag_AudioWave {
struct TAudioWave { SDL_AudioSpec spec;
unsigned int sampleRate;
int channels;
int bpb;
int BPB;
Uint32 len; Uint32 len;
Uint8 *buffer; Uint8 *buffer;
AudioWave next; struct Tag_AudioWave *next;
}; } AudioWave;
AudioWave _waves=NULL; AudioWave *_waves=NULL;
//////////////////////////////////////////////// ////////////////////////////////////////////////
// AudioChan // // AudioChan //
/////////////// ///////////////
// Reference to a sound. // Reference to a sound.
typedef struct TAudioChan TAudioChan, *AudioChan; typedef struct Tag_AudioChan {
struct TAudioChan { AudioWave *wave;
AudioWave wave;
Uint32 pos; Uint32 pos;
unsigned char rightvol; unsigned char rightvol;
unsigned char leftvol; unsigned char leftvol;
AudioChan next; struct Tag_AudioChan *next;
}; } AudioChan;
AudioChan _channels=NULL; AudioChan *_channels=NULL;
AudioChan _free_channels=NULL; AudioChan *_free_channels=NULL;
///////////////////////////// /////////////////////////////
// Audio_Init // Audio_Init
@@ -63,7 +55,7 @@ int Audio_Init(){
#endif #endif
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0){ if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0){
printf("Audio_Init: Failure initializing SDL Audio.\n"); printf("Audio_Init: Failure initializing SDL Audio.\n");
printf("\tSDL Error: %s\n",SDL_GetError()); printf("Audio_Init: SDL Error: %s\n",SDL_GetError());
return(0); return(0);
} }
@@ -71,11 +63,11 @@ int Audio_Init(){
as.freq = 44100; as.freq = 44100;
as.format = AUDIO_S16SYS; as.format = AUDIO_S16SYS;
as.channels = 2; as.channels = 2;
as.samples = 2048; as.samples = 1024;
as.callback = Audio_MixerCallback; as.callback = Audio_MixerCallback;
if(SDL_OpenAudio(&as, &as2) < 0){ if(SDL_OpenAudio(&as, &as2) < 0){
printf("Audio_Init: Failure opening audio.\n"); printf("Audio_Init: Failure opening audio.\n");
printf("\tSDL Error: %s\n",SDL_GetError()); printf("Audio_Init: SDL Error: %s\n",SDL_GetError());
return(0); return(0);
} }
@@ -102,16 +94,16 @@ int Audio_Init(){
// Mixes the audio channels. // Mixes the audio channels.
static void Audio_MixerCallback(void *ud,Uint8 *stream,int l){ static void Audio_MixerCallback(void *ud,Uint8 *stream,int l){
signed short *ptr_out,*ptr_wave; signed short *ptr_out,*ptr_wave;
AudioChan prevchan; AudioChan *prevchan;
AudioChan chan; AudioChan *chan;
AudioWave wave; AudioWave *wave;
int len=l/4; // Asume 16bpb and 2 output chan int len=l/4; // Asume 16bpb and 2 output chan
int chan_remain; int chan_remain;
int len_mix; int len_mix;
int i; int i;
// Clean // Clean
memset(stream,0,l); memset(stream,0,len);
// Mix all the channels // Mix all the channels
prevchan=NULL; prevchan=NULL;
@@ -119,7 +111,7 @@ static void Audio_MixerCallback(void *ud,Uint8 *stream,int l){
while(chan){ while(chan){
if(!chan->wave){ if(!chan->wave){
// Remove finished channels // Remove finished channels
AudioChan aux_chan=chan->next; AudioChan *aux_chan=chan->next;
chan->next=_free_channels; chan->next=_free_channels;
_free_channels=chan; _free_channels=chan;
chan=aux_chan; chan=aux_chan;
@@ -198,105 +190,38 @@ void Audio_Frame(){
// //
// Loads a sound, giving a reference. // Loads a sound, giving a reference.
AudioSnd Audio_LoadSound(char *filename){ AudioSnd Audio_LoadSound(char *filename){
int error = 0; AudioWave *wave;
FILE *f;
char id[5] = { 0, 0, 0, 0, 0 }, *sndBuffer = NULL;
short formatTag, channels, bitsPerSample;
int formatLen, sampleRate, dataSize;
f = fopen(filename, "rb"); // Allocate and load the sound
if (!f) { wave=malloc(sizeof(AudioWave));
printf("Audio_LoadSound: Failure opening file.\n"); if( SDL_LoadWAV(filename,
&wave->spec, &wave->buffer, &wave->len) == NULL )
{
printf("Audio_LoadSound: Failure Loading sound: %s\n",filename);
printf("Audio_LoadSound: SDL Error: %s\n",SDL_GetError());
free(wave);
return(NULL); return(NULL);
} }
// Read id "RIFF" // Asert results
fread(id, 4, sizeof(char), f); if( wave->spec.format != AUDIO_S16 ||
if (strcmp(id, "RIFF")) { wave->spec.freq != 44100 ||
printf("Audio_LoadSound: File is not RIFF.\n"); wave->spec.channels != 1 )
fclose(f); {
return(NULL); printf("Audio_LoadSound: Failure opening sound. (44.1Khz/16b/1c).\n");
SDL_FreeWAV(wave->buffer);
free(wave);
return(0);
} }
// File size (-"RIFF") // Correct the lenght
fseek(f, 4, SEEK_CUR); // size wave->len/=2;
// Read id "WAVE"
fread(id, 4, sizeof(char), f);
if (strcmp(id, "WAVE")) {
printf("Audio_LoadSound: File is not WAVE.\n");
fclose(f);
return(NULL);
}
// Read the format
fread(id, 1, sizeof(char) * 4, f); // Read "fmt "
fread(&formatLen, 1, sizeof(int), f);
if (formatLen < 14) {
printf("Audio_LoadSound: File too short.\n");
fclose(f);
return (NULL );
}
fread(&formatTag, 1, sizeof(short), f); // 1=PCM
if (formatTag != 1) {
printf("Audio_LoadSound: Not PCM format.\n");
fclose(f);
return (NULL );
}
fread(&channels, 1, sizeof(short), f);
fread(&sampleRate, 1, sizeof(int), f);
fseek(f, 2, SEEK_CUR); // avgBytesSec
fseek(f, 2, SEEK_CUR); // blockAlign
fread(&bitsPerSample, 1, sizeof(short), f);
fseek(f, formatLen - 14, SEEK_CUR); // Align read
// Assert sound format
if (sampleRate!=44100 || channels!=1 || bitsPerSample!=2) {
printf("Audio_LoadSound: Format not supported: "
"sampleRate:%d; channels:%d; BPB:%d\n",
sampleRate, channels, bitsPerSample);
fclose(f);
return(NULL);
}
// Skip no "data" blocks
do{
int lenRead=fread(id, 1, sizeof(char) * 4, f);
if(lenRead<4){ break; }
if (strcmp(id, "data")) {
fread(&dataSize, 1, sizeof(int), f);
fseek(f, dataSize, SEEK_CUR);
}else{
break;
}
}while(1);
if (strcmp(id, "data")) {
printf("Audio_LoadSound: DATA block not found\n");
fclose(f);
return (NULL );
}
// Read the "data" block
fread(&dataSize, 1, sizeof(int), f);
sndBuffer = malloc(sizeof(char)*dataSize);
fread(sndBuffer, dataSize, sizeof(char), f);
fclose(f);
// Build the wave object
AudioWave wave = malloc(sizeof(TAudioWave));
wave->sampleRate = sampleRate;
wave->channels = channels;
wave->buffer = (Uint8 *) sndBuffer;
wave->BPB = bitsPerSample;
wave->bpb = wave->bpb * 8;
wave->len = dataSize / (wave->BPB * wave->channels);
// Take a reference // Take a reference
wave->next=_waves; wave->next=_waves;
_waves=wave; _waves=wave;
return (wave); return((AudioSnd)wave);
} }
@@ -307,8 +232,8 @@ AudioSnd Audio_LoadSound(char *filename){
void Audio_PlaySound(AudioSnd snd, void Audio_PlaySound(AudioSnd snd,
float leftvol, float rightvol) float leftvol, float rightvol)
{ {
AudioChan chan; AudioChan *chan;
AudioWave wave; AudioWave *wave;
if(!snd) if(!snd)
return; return;
@@ -321,7 +246,7 @@ void Audio_PlaySound(AudioSnd snd,
_free_channels=chan->next; _free_channels=chan->next;
chan->next=NULL; chan->next=NULL;
}else{ }else{
chan=malloc(sizeof(TAudioChan)); chan=malloc(sizeof(AudioChan));
chan->next=NULL; chan->next=NULL;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,13 @@
int Draw_Init(int width,int height,char *title,int pfps,int fps); int Draw_Init(int width,int height,char *title,int pfps,int fps);
/////////////////////////////
// Draw_Loop
//
// Loops updating the game window.
void Draw_Loop(int (*proc)(),void (*draw)());
///////////////////////////// /////////////////////////////
// Draw_Clean // Draw_Clean
// //
@@ -21,37 +28,6 @@ void Draw_Clean(
unsigned char b); unsigned char b);
/////////////////////////////
// Draw_Loop
//
// Loops updating the game window.
void Draw_Loop(
void (*proc)(void *data),
void (*draw)(void *data,float f),
void *data);
/////////////////////////////
// Draw_BreakLoop
//
// Breaks the drawing loop
void Draw_BreakLoop();
/////////////////////////////
// Draw_OverrideExit
//
// Overrides the default exit mechanism
void Draw_OverrideExit(int override);
/////////////////////////////
// Draw_Flush
//
// Performs all the queued draw actions.
void Draw_Flush();
//////////////////////////////////////////////// ////////////////////////////////////////////////
// DrawImg // // DrawImg //
///////////// /////////////
@@ -59,12 +35,6 @@ void Draw_Flush();
typedef void *DrawImg; typedef void *DrawImg;
/////////////////////////////
// Draw_CreateImage
//
DrawImg Draw_CreateImage(int w,int h);
///////////////////////////// /////////////////////////////
// Draw_LoadImage // Draw_LoadImage
// //

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2011-2014 Valeriano Alfonso Rodriguez (Kableado) // Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -17,12 +17,12 @@
// Entity_New // Entity_New
// //
// //
Entity _free_entity=NULL; Entity *_free_entity=NULL;
Entity Entity_New(){ Entity *Entity_New(){
Entity e; Entity *e;
if(!_free_entity){ if(!_free_entity){
e=malloc(sizeof(TEntity)); e=malloc(sizeof(Entity));
}else{ }else{
e=_free_entity; e=_free_entity;
_free_entity=e->next; _free_entity=e->next;
@@ -30,11 +30,9 @@ Entity Entity_New(){
e->base=NULL; e->base=NULL;
e->type=0; e->type=0;
vec2_set(e->pos0,0.0f,0.0f);
vec2_set(e->pos,0.0f,0.0f); vec2_set(e->pos,0.0f,0.0f);
e->flags=EntityFlag_Collision|EntityFlag_Overlap; e->flags=EntityFlag_Collision|EntityFlag_Overlap;
e->zorder=1; e->zorder=1;
e->sortYOffset=0;
vec2_set(e->dir,0.0f,0.0f); vec2_set(e->dir,0.0f,0.0f);
@@ -77,7 +75,7 @@ Entity Entity_New(){
// Entity_Destroy // Entity_Destroy
// //
// //
void Entity_Destroy(Entity e){ void Entity_Destroy(Entity *e){
if(e->ondelete){ if(e->ondelete){
e->ondelete(e); e->ondelete(e);
} }
@@ -90,8 +88,8 @@ void Entity_Destroy(Entity e){
// Entity_Copy // Entity_Copy
// //
// //
Entity Entity_Copy(Entity e){ Entity *Entity_Copy(Entity *e){
Entity n; Entity *n;
n=Entity_New(); n=Entity_New();
@@ -100,7 +98,6 @@ Entity Entity_Copy(Entity e){
vec2_set(n->pos,e->pos[0],e->pos[1]); vec2_set(n->pos,e->pos[0],e->pos[1]);
n->flags=e->flags; n->flags=e->flags;
n->zorder=e->zorder; n->zorder=e->zorder;
n->sortYOffset=e->sortYOffset;
vec2_set(n->vel,e->vel[0],e->vel[1]); vec2_set(n->vel,e->vel[0],e->vel[1]);
n->radius=e->radius; n->radius=e->radius;
@@ -136,8 +133,6 @@ Entity Entity_Copy(Entity e){
n->D=e->D; n->D=e->D;
n->child=e->child; n->child=e->child;
Entity_CalcBBox(n);
// Call the copy event // Call the copy event
if(n->oncopy){ if(n->oncopy){
n->oncopy(n); n->oncopy(n);
@@ -147,67 +142,22 @@ Entity Entity_Copy(Entity e){
} }
/////////////////////////////
// Entity_CalcBBox
//
//
#define BBox_ExtraMargin 10
#define max(a,b) ((a)>(b)?(a):(b))
void Entity_CalcBBox(Entity e){
float hHeight=(max(e->height,e->radius)/2)+BBox_ExtraMargin;
float hWidth=(max(e->width,e->radius)/2)+BBox_ExtraMargin;
if(e->vel[0]>0){
e->maxX=e->pos[0]+e->vel[0]+hWidth;
e->minX=e->pos[0]-hWidth;
}else{
e->minX=(e->pos[0]+e->vel[0])-hWidth;
e->maxX=e->pos[0]+hWidth;
}
if(e->vel[1]>0){
e->maxY=e->pos[1]+e->vel[1]+hHeight;
e->minY=e->pos[1]-hHeight;
}else{
e->minY=(e->pos[1]+e->vel[1])-hHeight;
e->maxY=e->pos[1]+hHeight;
}
}
/////////////////////////////
// Entity_BBoxIntersect
//
//
int Entity_BBoxIntersect(Entity ent1,Entity ent2){
if( ent1->maxX>=ent2->minX && ent1->minX<=ent2->maxX &&
ent1->maxY>=ent2->minY && ent1->minY<=ent2->maxY )
{
return(1);
}
return(0);
}
///////////////////////////// /////////////////////////////
// Entity_Draw // Entity_Draw
// //
// //
void Entity_Draw(Entity e,int x,int y,float f){ void Entity_Draw(Entity *e,int x,int y){
vec2 fPos;
Draw_SetColor(e->color[0],e->color[1],e->color[2],e->color[3]); Draw_SetColor(e->color[0],e->color[1],e->color[2],e->color[3]);
if(e->flags&EntityFlag_UpdatedPos){ AnimPlay_Draw(&e->anim,e->pos[0]+x,e->pos[1]+y);
vec2_interpol(fPos,e->pos0,e->pos,f);
AnimPlay_Draw(&e->anim,fPos[0]+x,fPos[1]+y);
}else{
AnimPlay_Draw(&e->anim,e->pos[0]+x,e->pos[1]+y);
}
} }
///////////////////////////// /////////////////////////////
// Entity_IsVisible // Entity_IsVisible
// //
// //
int Entity_IsVisible(Entity e,int x,int y,int w,int h){ int Entity_IsVisible(Entity *e,int x,int y,int w,int h){
int xmax,xmin; int xmax,xmin;
int ymax,ymin; int ymax,ymin;
int ih,iw; int ih,iw;
@@ -235,7 +185,7 @@ int Entity_IsVisible(Entity e,int x,int y,int w,int h){
// Entity_Process // Entity_Process
// //
// //
void Entity_Process(Entity b,int ft){ void Entity_Process(Entity *b,int ft){
b->flags&=~EntityFlag_UpdatedPos; b->flags&=~EntityFlag_UpdatedPos;
// Launch method // Launch method
@@ -249,11 +199,9 @@ void Entity_Process(Entity b,int ft){
// Entity_PostProcess // Entity_PostProcess
// //
// //
void Entity_PostProcess(Entity e,int ft){ void Entity_PostProcess(Entity *e,int ft){
float qlen,len; float qlen,len;
vec2_copy(e->pos0,e->pos);
// Determine if there is movement // Determine if there is movement
qlen=vec2_dot(e->vel,e->vel); qlen=vec2_dot(e->vel,e->vel);
if(qlen>0.0f){ if(qlen>0.0f){
@@ -275,8 +223,6 @@ void Entity_PostProcess(Entity e,int ft){
// Mark the update of the position. // Mark the update of the position.
vec2_copy(e->oldpos,e->pos); vec2_copy(e->oldpos,e->pos);
e->flags|=EntityFlag_UpdatedPos; e->flags|=EntityFlag_UpdatedPos;
Entity_CalcBBox(e);
} }
// Launch method // Launch method
@@ -290,123 +236,131 @@ void Entity_PostProcess(Entity e,int ft){
///////////////////////////// /////////////////////////////
// CollisionInfo_New // Entity_CollisionResponseClircle
// //
// // Normal response to a collision between circles.
CollisionInfo _free_collInfo=NULL; void Entity_CollisionResponseCircle(
CollisionInfo CollisionInfo_New(int responseType,Entity ent1,Entity ent2,float t,vec2 n,int applyFriction){ Entity *b1,Entity *b2,float t,vec2 n)
CollisionInfo collInfo;
if(!_free_collInfo){
collInfo=malloc(sizeof(TCollisionInfo));
}else{
collInfo=_free_collInfo;
_free_collInfo=collInfo->next;
}
collInfo->next=NULL;
collInfo->responseType=responseType;
collInfo->ent1=ent1;
collInfo->ent2=ent2;
collInfo->t=t;
vec2_copy(collInfo->n,n);
collInfo->applyFriction=applyFriction;
return collInfo;
}
/////////////////////////////
// CollisionInfo_Destroy
//
//
void CollisionInfo_Destroy(CollisionInfo *collInfoRef){
if(collInfoRef==NULL || collInfoRef[0]==NULL){return;}
CollisionInfo collInfo=collInfoRef[0];
CollisionInfo nextCollInfo;
while(collInfo!=NULL){
nextCollInfo=collInfo->next;
collInfo->next=_free_collInfo;
_free_collInfo=collInfo;
collInfo=nextCollInfo;
}
collInfoRef[0]=NULL;
}
/////////////////////////////
// CollisionInfo_Add
//
//
void CollisionInfo_Add(CollisionInfo *collInfoRef,
int responseType,Entity ent1,Entity ent2,float t,vec2 n,int applyFriction)
{ {
if(collInfoRef==NULL){return;} float moment;
CollisionInfo prevCollInfo=NULL; vec2 temp;
CollisionInfo collInfo=collInfoRef[0]; float elast;
CollisionInfo newCollInfo=CollisionInfo_New(responseType,ent1,ent2,t,n,applyFriction);
while(collInfo!=NULL && collInfo->t<t){ if(b1->mass>0.0f && b2->mass>0.0f){
prevCollInfo=collInfo; // Calculate elasticity
collInfo=collInfo->next; elast=(b1->mass*b1->elast+b2->mass*b2->elast)/
} (b1->mass+b2->mass);
if(prevCollInfo==NULL){
collInfoRef[0]=newCollInfo; // Collision between two massed balls
moment=((1.0f+elast)*b1->mass*b2->mass*
(fabs(vec2_dot(b1->vel,n))+fabs(vec2_dot(b2->vel,n))))
/(b1->mass+b2->mass);
vec2_scale(temp,n,moment/b1->mass);
vec2_minus(b1->vel,b1->vel,temp);
vec2_scale(temp,n,moment/b2->mass);
vec2_plus(b2->vel,b2->vel,temp);
}else
if(b1->mass>0.0f && b2->mass<=0.0f){
// Collision between a massed ball and a fixed ball
moment=(1.0f+b1->elast)*
(vec2_dot(b1->vel,n));
vec2_scale(temp,n,moment);
vec2_minus(b1->vel,b1->vel,temp);
}else
if(b1->mass<=0.0f && b2->mass>0.0f){
// Collision between a massed ball and a fixed ball
// (imposible, but better safe)
moment=(1.0f+b2->elast)*
(vec2_dot(b2->vel,n));
vec2_scale(temp,n,moment);
vec2_plus(b2->vel,b2->vel,temp);
}else{ }else{
prevCollInfo->next=newCollInfo; // Collision between 2 fixed balls
// (imposible, but better safe)
vec2_set(b1->vel,0,0);
vec2_set(b2->vel,0,0);
} }
newCollInfo->next=collInfo;
} }
///////////////////////////// /////////////////////////////
// CollisionInfo_CheckRepetition // Entity_CollisionResponseLine
// //
// // Normal response to a collision with a line.
int CollisionInfo_CheckRepetition(CollisionInfo collInfo,Entity ent1,Entity ent2) void Entity_CollisionResponseLine(
Entity *ent,Entity *ent2,float t,vec2 norm,int applyFriction)
{ {
while(collInfo!=NULL){ vec2 pos2,vel2,velFric,intersection;
if((collInfo->ent1==ent1 && collInfo->ent2==ent2) || float dist,fric_static,fric_dynamic,fricLen;
(collInfo->ent1==ent2 && collInfo->ent2==ent1))
{ // Calculate friction
return(1); fric_static=(ent->fric_static+ent2->fric_static)/2;
fric_dynamic=(ent->fric_dynamic+ent2->fric_dynamic)/2;
// Calculate end position
vec2_scale(vel2,ent->vel,1.0f-t);
dist=-vec2_dot(norm,vel2);
vec2_plus(pos2,ent->pos,ent->vel);
vec2_scaleadd(pos2,pos2,norm,dist);
// Calculate intersection
vec2_scaleadd(intersection,ent->pos,ent->vel,t);
if(applyFriction){
// Apply friction
vec2_minus(velFric,pos2,intersection);
fricLen=sqrtf(vec2_dot(velFric,velFric));
if(fricLen<fric_static){
// Apply static friction
vec2_copy(pos2,intersection);
}else{
// Apply dynamic friction
if(fricLen>0.0f){
vec2_scaleadd(pos2,intersection,velFric,
1.0f-(fric_dynamic+(fric_static/fricLen)));
}else{
vec2_scaleadd(pos2,intersection,velFric,
1.0f-fric_dynamic);
}
} }
collInfo=collInfo->next;
} }
return(0);
// Apply to velocity
vec2_scaleadd(pos2,pos2,norm,0.1f);
vec2_minus(ent->vel,pos2,ent->pos);
} }
///////////////////////////// /////////////////////////////
// Entity_CheckCollisions // Entity_Collide
// //
// //
int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){ int Entity_Collide(Entity *b1,Entity *b2){
float t; float t;
vec2 n,p; vec2 n,p;
vec2 vel; vec2 vel;
int flags=ent1->flags|ent2->flags; int flags=b1->flags|b2->flags;
if(flags&EntityFlag_Platform && !(flags&EntityFlag_Block)){ if(flags&EntityFlag_Platform && !(flags&EntityFlag_Block)){
// One of the entities is a platform and none is a block // One of the entities is a platform and none is a block
Entity ent,ent_plat; Entity *ent,*ent_plat;
float plat_width; float plat_width;
vec2 p; vec2 p;
// Decide who is the platform and who is the ent // Decide who is the platform and who is the ent
if(ent1->mass<=0.0f && ent2->mass>0.0f){ if(b1->mass<=0.0f && b2->mass>0.0f){
ent=ent2; ent=b2;
ent_plat=ent1; ent_plat=b1;
}else }else
if(ent2->mass<=0.0f && ent1->mass>0.0f){ if(b2->mass<=0.0f && b1->mass>0.0f){
ent=ent1; ent=b1;
ent_plat=ent2; ent_plat=b2;
}else{ }else{
// Two static or two dinamic entities?!? // Two static or two dinamic entities?!?
return(0); return(0);
} }
// Check Top // Check Top
vec2_set(n,0,-1); vec2_set(n,0,-1);
vec2_scaleadd(p,ent_plat->pos,n,(ent->height+ent_plat->height)/2); vec2_scaleadd(p,ent_plat->pos,n,(ent->height+ent_plat->height)/2);
@@ -414,10 +368,36 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
if(Intersect_RayEdge(ent->pos,ent->vel, if(Intersect_RayEdge(ent->pos,ent->vel,
n,p,plat_width,&t)) n,p,plat_width,&t))
{ {
// Keep colision info int response=1;
CollisionInfo_Add(collInfoRef, int rc;
CollisionResponse_Line,ent,ent_plat,t,n,1);
return(1); // Check the collision methods
if(ent->collision){
rc=ent->collision(ent,ent_plat,t,n);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
if(ent_plat->collision){
vec2 n2;
vec2_scale(n2,n,-1.0f);
rc=ent_plat->collision(ent_plat,ent,t,n2);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
// Collision response
if(response==1){
Entity_CollisionResponseLine(ent,ent_plat,t,n,1);
return(1);
}
if (response==2) {
return(1);
}
return(0);
} }
return(0); return(0);
@@ -425,19 +405,19 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
if(flags&EntityFlag_Block && !(flags&EntityFlag_Platform)){ if(flags&EntityFlag_Block && !(flags&EntityFlag_Platform)){
// One of the entities is a block and none is a platform // One of the entities is a block and none is a platform
Entity ent,ent_block; Entity *ent,*ent_block;
float auxT,block_len; float auxT,block_len;
vec2 auxN,p; vec2 auxN,p;
int applyFriction; int applyFriction;
// Decide who is the platform and who is the ent // Decide who is the block and who is the ent
if(ent1->mass<=0.0f && ent2->mass>0.0f){ if(b1->mass<=0.0f && b2->mass>0.0f){
ent=ent2; ent=b2;
ent_block=ent1; ent_block=b1;
}else }else
if(ent2->mass<=0.0f && ent1->mass>0.0f){ if(b2->mass<=0.0f && b1->mass>0.0f){
ent=ent1; ent=b1;
ent_block=ent2; ent_block=b2;
}else{ }else{
// Two static or two dinamic entities?!? // Two static or two dinamic entities?!?
return(0); return(0);
@@ -504,155 +484,61 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
} }
if(t<1.0f){ if(t<1.0f){
// Keep colision info // Handle colision
CollisionInfo_Add(collInfoRef, int response=1;
CollisionResponse_Line,ent,ent_block,t,n,applyFriction); int rc;
return(1);
// Check the collision methods
if(ent->collision){
rc=ent->collision(ent,ent_block,t,n);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
if(ent_block->collision){
vec2 n2;
vec2_scale(n2,n,-1.0f);
rc=ent_block->collision(ent_block,ent,t,n2);
if (rc==0)
response=0;
if (rc>1)
response=2;
}
// Collision response
if(response==1){
Entity_CollisionResponseLine(ent,ent_block,t,n,applyFriction);
return(1);
}
if (response==2) {
return(1);
}
return(0);
} }
return(0); return(0);
} }
// Test relative to ent1
vec2_minus(vel,ent1->vel,ent2->vel);
if(Colision_CircleCircle(ent1->pos,ent1->radius,vel,ent2->pos,ent2->radius,&t,n)){
// Keep colision info
CollisionInfo_Add(collInfoRef,
CollisionResponse_Circle,ent1,ent2,t,n,0);
return(1);
}
return(0);
}
// Test relative to b1
///////////////////////////// vec2_minus(vel,b1->vel,b2->vel);
// Entity_CollisionResponseCircle if(Colision_CircleCircle(b1->pos,b1->radius,vel,b2->pos,b2->radius,&t,n)){
//
// Normal response to a collision between circles.
void Entity_CollisionResponseCircle(
Entity b1,Entity b2,float t,vec2 n)
{
float moment;
vec2 temp;
float elast;
if(b1->mass>0.0f && b2->mass>0.0f){
// Calculate elasticity
elast=(b1->mass*b1->elast+b2->mass*b2->elast)/
(b1->mass+b2->mass);
// Collision between two massed balls
moment=((1.0f+elast)*b1->mass*b2->mass*
(fabs(vec2_dot(b1->vel,n))+fabs(vec2_dot(b2->vel,n))))
/(b1->mass+b2->mass);
vec2_scale(temp,n,moment/b1->mass);
vec2_minus(b1->vel,b1->vel,temp);
Entity_CalcBBox(b1);
vec2_scale(temp,n,moment/b2->mass);
vec2_plus(b2->vel,b2->vel,temp);
Entity_CalcBBox(b2);
}else
if(b1->mass>0.0f && b2->mass<=0.0f){
// Collision between a massed ball and a fixed ball
moment=(1.0f+b1->elast)*
(vec2_dot(b1->vel,n));
vec2_scale(temp,n,moment);
vec2_minus(b1->vel,b1->vel,temp);
Entity_CalcBBox(b1);
}else
if(b1->mass<=0.0f && b2->mass>0.0f){
// Collision between a massed ball and a fixed ball
// (imposible, but better safe)
moment=(1.0f+b2->elast)*
(vec2_dot(b2->vel,n));
vec2_scale(temp,n,moment);
vec2_plus(b2->vel,b2->vel,temp);
Entity_CalcBBox(b2);
}else{
// Collision between 2 fixed balls
// (imposible, but better safe)
vec2_set(b1->vel,0,0);
Entity_CalcBBox(b1);
vec2_set(b2->vel,0,0);
Entity_CalcBBox(b2);
}
}
/////////////////////////////
// Entity_CollisionResponseLine
//
// Normal response to a collision with a line.
void Entity_CollisionResponseLine(
Entity ent,Entity ent2,float t,vec2 norm,int applyFriction)
{
vec2 pos2,vel2,velFric,intersection;
float dist,fric_static,fric_dynamic,fricLen;
// Calculate friction
fric_static=(ent->fric_static+ent2->fric_static)/2;
fric_dynamic=(ent->fric_dynamic+ent2->fric_dynamic)/2;
// Calculate end position
vec2_scale(vel2,ent->vel,1.0f-t);
dist=-vec2_dot(norm,vel2);
vec2_plus(pos2,ent->pos,ent->vel);
vec2_scaleadd(pos2,pos2,norm,dist);
// Calculate intersection
vec2_scaleadd(intersection,ent->pos,ent->vel,t);
if(applyFriction){
// Apply friction
vec2_minus(velFric,pos2,intersection);
fricLen=sqrtf(vec2_dot(velFric,velFric));
if(fricLen<fric_static){
// Apply static friction
vec2_copy(pos2,intersection);
}else{
// Apply dynamic friction
if(fricLen>0.0f){
vec2_scaleadd(pos2,intersection,velFric,
1.0f-(fric_dynamic+(fric_static/fricLen)));
}else{
vec2_scaleadd(pos2,intersection,velFric,
1.0f-fric_dynamic);
}
}
}
// Apply to velocity
vec2_scaleadd(pos2,pos2,norm,0.1f);
vec2_minus(ent->vel,pos2,ent->pos);
Entity_CalcBBox(ent);
}
/////////////////////////////
// Entity_CollisionInfoResponse
//
//
int Entity_CollisionInfoResponse(CollisionInfo collInfo){
while(collInfo!=NULL){
// Handle colision
int response=1; int response=1;
int rc; int rc;
vec2 n1;
vec2 n2; vec2 n2;
vec2_copy(n1,collInfo->n); vec2_scale(n2,n,-1.0f);
vec2_scale(n2,collInfo->n,-1.0f);
// Check the collision methods // Check the collision methods
if(collInfo->ent1->collision){ if(b1->collision){
rc=collInfo->ent1->collision(collInfo->ent1,collInfo->ent2,collInfo->t,n1); rc=b1->collision(b1,b2,t,n2);
if (rc==0) if (rc==0)
response=0; response=0;
if (rc>1) if (rc>1)
response=2; response=2;
} }
if(collInfo->ent2->collision){ if(b2->collision){
rc=collInfo->ent2->collision(collInfo->ent2,collInfo->ent1,collInfo->t,n2); rc=b2->collision(b2,b1,t,n);
if (rc==0) if (rc==0)
response=0; response=0;
if (rc>1) if (rc>1)
@@ -661,26 +547,17 @@ int Entity_CollisionInfoResponse(CollisionInfo collInfo){
// Collision response // Collision response
if(response==1){ if(response==1){
if(collInfo->responseType==CollisionResponse_Line){ if(vec2_dot(b1->vel,b1->vel)>vec2_dot(b2->vel,b2->vel)){
Entity_CollisionResponseLine( Entity_CollisionResponseCircle(b1,b2,t,n);
collInfo->ent1,collInfo->ent2,collInfo->t,collInfo->n,collInfo->applyFriction); }else{
}else Entity_CollisionResponseCircle(b2,b1,t,n);
if(collInfo->responseType==CollisionResponse_Circle){
if(vec2_dot(collInfo->ent1->vel,collInfo->ent1->vel)>
vec2_dot(collInfo->ent2->vel,collInfo->ent2->vel))
{
Entity_CollisionResponseCircle(collInfo->ent1,collInfo->ent2,collInfo->t,n2);
}else{
Entity_CollisionResponseCircle(collInfo->ent2,collInfo->ent1,collInfo->t,n1);
}
} }
return(1); return(1);
} }
if (response==2) { if (response==2) {
return(1); return(1);
} }
return(0);
collInfo=collInfo->next;
} }
return(0); return(0);
} }
@@ -690,7 +567,7 @@ int Entity_CollisionInfoResponse(CollisionInfo collInfo){
// Entity_Overlaps // Entity_Overlaps
// //
// //
void Entity_Overlaps(Entity b1,Entity b2){ void Entity_Overlaps(Entity *b1,Entity *b2){
vec2 len; vec2 len;
vec2_minus(len,b1->pos,b2->pos); vec2_minus(len,b1->pos,b2->pos);
@@ -717,7 +594,7 @@ void Entity_Overlaps(Entity b1,Entity b2){
// Entity_GetPos // Entity_GetPos
// //
// //
void Entity_GetPos(Entity e,vec2 pos){ void Entity_GetPos(Entity *e,vec2 pos){
vec2_copy(pos,e->pos); vec2_copy(pos,e->pos);
} }
@@ -725,7 +602,7 @@ void Entity_GetPos(Entity e,vec2 pos){
// Entity_UpdatePos // Entity_UpdatePos
// //
// //
void Entity_UpdatePos(Entity e,vec2 pos){ void Entity_UpdatePos(Entity *e,vec2 pos){
// Mark the update of the position. // Mark the update of the position.
vec2_copy(e->oldpos,e->pos); vec2_copy(e->oldpos,e->pos);
@@ -738,7 +615,7 @@ void Entity_UpdatePos(Entity e,vec2 pos){
// Entity_AddVelLimit // Entity_AddVelLimit
// //
// //
void Entity_AddVelLimit(Entity e,vec2 vel,float limit){ void Entity_AddVelLimit(Entity *e,vec2 vel,float limit){
float vlen_orig,vlen; float vlen_orig,vlen;
vec2 dir,vel_temp; vec2 dir,vel_temp;
@@ -756,7 +633,6 @@ void Entity_AddVelLimit(Entity e,vec2 vel,float limit){
vec2_scale(vel_temp,dir,vlen); vec2_scale(vel_temp,dir,vlen);
vec2_plus(e->vel,e->vel,vel_temp); vec2_plus(e->vel,e->vel,vel_temp);
} }
Entity_CalcBBox(e);
} }
@@ -764,7 +640,7 @@ void Entity_AddVelLimit(Entity e,vec2 vel,float limit){
// Entity_SetColor // Entity_SetColor
// //
// //
void Entity_SetColor(Entity e,float r,float g,float b,float a){ void Entity_SetColor(Entity *e,float r,float g,float b,float a){
e->color[0]=r; e->color[0]=r;
e->color[1]=g; e->color[1]=g;
e->color[2]=b; e->color[2]=b;
@@ -776,7 +652,7 @@ void Entity_SetColor(Entity e,float r,float g,float b,float a){
// Entity_AddColor // Entity_AddColor
// //
// //
void Entity_AddColor(Entity e,float r,float g,float b,float a){ void Entity_AddColor(Entity *e,float r,float g,float b,float a){
e->color[0]+=r; e->color[0]+=r;
if(e->color[0]>1.0f) if(e->color[0]>1.0f)
e->color[0]=1.0f; e->color[0]=1.0f;
@@ -796,7 +672,7 @@ void Entity_AddColor(Entity e,float r,float g,float b,float a){
// Entity_SetLight // Entity_SetLight
// //
// //
void Entity_SetLight(Entity e,float r,float g,float b,float rad){ void Entity_SetLight(Entity *e,float r,float g,float b,float rad){
e->light[0]=r; e->light[0]=r;
e->light[1]=g; e->light[1]=g;
e->light[2]=b; e->light[2]=b;
@@ -809,7 +685,7 @@ void Entity_SetLight(Entity e,float r,float g,float b,float rad){
// Entity_Iluminate // Entity_Iluminate
// //
// //
void Entity_Iluminate(Entity e,Entity *elist,int n){ void Entity_Iluminate(Entity *e,Entity **elist,int n){
int i; int i;
vec2 vdist; vec2 vdist;
float qdist,f; float qdist,f;
@@ -849,7 +725,7 @@ void Entity_Iluminate(Entity e,Entity *elist,int n){
// Entity_MarkUpdateLight // Entity_MarkUpdateLight
// //
// //
void Entity_MarkUpdateLight(Entity e,Entity *elist,int n){ void Entity_MarkUpdateLight(Entity *e,Entity **elist,int n){
if(e->flags&EntityFlag_Light){ if(e->flags&EntityFlag_Light){
int i; int i;
vec2 max,min; vec2 max,min;

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2011-2014 Valeriano Alfonso Rodriguez (Kableado) // Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
#ifndef _ENTITY_H_ #ifndef _ENTITY_H_
#define _ENTITY_H_ #define _ENTITY_H_
@@ -9,7 +9,8 @@
//////////////////////////////////////////////// ////////////////////////////////////////////////
// Entity // Entity //
////////////
// //
#define EntityFlag_Collision 1 #define EntityFlag_Collision 1
#define EntityFlag_Platform 2 #define EntityFlag_Platform 2
@@ -20,17 +21,14 @@
#define EntityFlag_Light 16 #define EntityFlag_Light 16
#define EntityFlag_UpdateLight 32 #define EntityFlag_UpdateLight 32
#define EntityFlag_UpdatedPos 64 #define EntityFlag_UpdatedPos 64
typedef struct TEntity TEntity, *Entity; typedef struct Tag_Entity {
struct TEntity { struct Tag_Entity *base;
Entity base;
int type; int type;
vec2 oldpos; vec2 oldpos;
vec2 pos0;
vec2 pos; vec2 pos;
int flags; int flags;
int zorder; int zorder;
float sortYOffset;
vec2 dir; vec2 dir;
@@ -51,134 +49,72 @@ struct TEntity {
float color[4]; float color[4];
float light[4]; float light[4];
void (*oncopy)(Entity ent); void (*oncopy)(struct Tag_Entity *ent);
void (*ondelete)(Entity ent); void (*ondelete)(struct Tag_Entity *ent);
void (*proc)(Entity ent,int ft); void (*proc)(struct Tag_Entity *ent,int ft);
void (*postproc)(Entity ent,int ft); void (*postproc)(struct Tag_Entity *ent,int ft);
int (*collision)(Entity ent, Entity ent2, float t,vec2 n); int (*collision)(
void (*overlap)(Entity ent, Entity ent2); struct Tag_Entity *ent,
struct Tag_Entity *ent2,
float t,vec2 n);
void (*overlap)(
struct Tag_Entity *ent,
struct Tag_Entity *ent2);
int A; int A;
int B; int B;
int C; int C;
int D; int D;
Entity child; struct Tag_Entity *child;
float maxX,minX; void *next;
float maxY,minY; } Entity;
Entity next;
};
///////////////////////////// /////////////////////////////
// Entity_New // Entity_New
// //
Entity Entity_New(); //
Entity *Entity_New();
///////////////////////////// /////////////////////////////
// Entity_Destroy // Entity_Destroy
// //
void Entity_Destroy(Entity e); //
void Entity_Destroy(Entity *e);
///////////////////////////// /////////////////////////////
// Entity_Copy // Entity_Copy
// //
Entity Entity_Copy(Entity e);
/////////////////////////////
// Entity_CalcBBox
// //
// Entity *Entity_Copy(Entity *e);
void Entity_CalcBBox(Entity e);
/////////////////////////////
// Entity_BBoxIntersect
//
//
int Entity_BBoxIntersect(Entity ent1,Entity ent2);
///////////////////////////// /////////////////////////////
// Entity_Draw // Entity_Draw
// //
void Entity_Draw(Entity e,int x,int y,float f); //
void Entity_Draw(Entity *e,int x,int y);
///////////////////////////// /////////////////////////////
// Entity_IsVisible // Entity_IsVisible
// //
int Entity_IsVisible(Entity e,int x,int y,int w,int h); //
int Entity_IsVisible(Entity *e,int x,int y,int w,int h);
///////////////////////////// /////////////////////////////
// Entity_Process // Entity_Process
// //
void Entity_Process(Entity e,int ft); //
void Entity_Process(Entity *e,int ft);
///////////////////////////// /////////////////////////////
// Entity_PostProcess // Entity_PostProcess
// //
void Entity_PostProcess(Entity e,int ft);
////////////////////////////////////////////////
// CollisionInfo
// //
#define CollisionResponse_Circle 1 void Entity_PostProcess(Entity *e,int ft);
#define CollisionResponse_Line 2
typedef struct TCollisionInfo TCollisionInfo,*CollisionInfo;
struct TCollisionInfo {
int responseType;
Entity ent1;
Entity ent2;
float t;
vec2 n;
int applyFriction;
CollisionInfo next;
};
/////////////////////////////
// CollisionInfo_New
//
//
CollisionInfo CollisionInfo_New(int responseType,Entity ent1,Entity ent2,float t,vec2 n,int applyFriction);
/////////////////////////////
// CollisionInfo_Destroy
//
//
void CollisionInfo_Destroy(CollisionInfo *collInfoRef);
/////////////////////////////
// CollisionInfo_Add
//
//
void CollisionInfo_Add(CollisionInfo *collInfo,
int responseType,Entity ent1,Entity ent2,float t,vec2 n,int applyFriction);
/////////////////////////////
// CollisionInfo_CheckRepetition
//
//
int CollisionInfo_CheckRepetition(CollisionInfo collInfo,Entity ent1,Entity ent2);
/////////////////////////////
// Entity_CheckCollision
//
//
int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef);
///////////////////////////// /////////////////////////////
@@ -186,7 +122,7 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef);
// //
// Normal response to a collision of spheres. // Normal response to a collision of spheres.
void Entity_CollisionResponseCircle( void Entity_CollisionResponseCircle(
Entity b1,Entity b2,float t,vec2 n); Entity *b1,Entity *b2,float t,vec2 n);
///////////////////////////// /////////////////////////////
@@ -194,69 +130,75 @@ void Entity_CollisionResponseCircle(
// //
// Normal response to a collision with a line. // Normal response to a collision with a line.
void Entity_CollisionResponseLine( void Entity_CollisionResponseLine(
Entity ent,Entity ent2,float t,vec2 n,int applyFriction); Entity *ent,Entity *ent2,float t,vec2 n,int applyFriction);
///////////////////////////// /////////////////////////////
// Entity_CollisionInfoResponse // Entity_Collide
// //
// //
int Entity_CollisionInfoResponse(CollisionInfo collInfo); int Entity_Collide(Entity *b1,Entity *b2);
///////////////////////////// /////////////////////////////
// Entity_Overlaps // Entity_Overlaps
// //
void Entity_Overlaps(Entity b1,Entity b2); //
void Entity_Overlaps(Entity *b1,Entity *b2);
///////////////////////////// /////////////////////////////
// Entity_GetPos // Entity_GetPos
// //
void Entity_GetPos(Entity e,vec2 pos); //
void Entity_GetPos(Entity *e,vec2 pos);
///////////////////////////// /////////////////////////////
// Entity_UpdatePos // Entity_UpdatePos
// //
void Entity_UpdatePos(Entity e,vec2 pos); //
void Entity_UpdatePos(Entity *e,vec2 pos);
///////////////////////////// /////////////////////////////
// Entity_AddVelLimit // Entity_AddVelLimit
// //
void Entity_AddVelLimit(Entity e,vec2 vel,float limit); //
void Entity_AddVelLimit(Entity *e,vec2 vel,float limit);
///////////////////////////// /////////////////////////////
// Entity_SetColor // Entity_SetColor
// //
void Entity_SetColor(Entity e,float r,float g,float b,float a); //
void Entity_SetColor(Entity *e,float r,float g,float b,float a);
///////////////////////////// /////////////////////////////
// Entity_AddColor // Entity_AddColor
// //
void Entity_AddColor(Entity e,float r,float g,float b,float a); //
void Entity_AddColor(Entity *e,float r,float g,float b,float a);
///////////////////////////// /////////////////////////////
// Entity_AddColor // Entity_AddColor
// //
void Entity_SetLight(Entity e,float r,float g,float b,float rad); //
void Entity_SetLight(Entity *e,float r,float g,float b,float rad);
///////////////////////////// /////////////////////////////
// Entity_AddColor // Entity_AddColor
// //
void Entity_Iluminate(Entity e,Entity *elist,int n); //
void Entity_Iluminate(Entity *e,Entity **elist,int n);
///////////////////////////// /////////////////////////////
// Entity_MarkUpdateLight // Entity_MarkUpdateLight
// //
void Entity_MarkUpdateLight(Entity e,Entity *elist,int n); //
void Entity_MarkUpdateLight(Entity *e,Entity **elist,int n);
#endif #endif

View File

@@ -1,9 +1,6 @@
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado) // Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
#include <math.h> #include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include "Time.h" #include "Time.h"
@@ -17,7 +14,8 @@
#include "GameLib.h" #include "GameLib.h"
// Globals // Globals
Entity *_entity=NULL; int _running;
Entity **_entity=NULL;
int *_entity_flag=NULL; int *_entity_flag=NULL;
int _n_entities=0; int _n_entities=0;
int _n_entities_res=0; int _n_entities_res=0;
@@ -25,12 +23,11 @@ int _entities_lock=0;
int _entities_compactate=0; int _entities_compactate=0;
void (*_gameproc)()=NULL; void (*_gameproc)()=NULL;
void (*_gamepostproc)()=NULL; void (*_gamepostproc)()=NULL;
void (*_gamepredraw)(float f)=NULL; void (*_gamepredraw)()=NULL;
void (*_gamedraw)(float f)=NULL; void (*_gamedraw)()=NULL;
int _pft; int _ft;
int _game_size[2]; int _game_size[2];
int _game_pos0[2]; int _game_pos[2];
int _game_pos1[2];
long long t_proc; long long t_proc;
long long t_col; long long t_col;
@@ -58,12 +55,10 @@ int GameLib_Init(int w,int h,char *title,int pfps,int fps){
_game_size[0]=w; _game_size[0]=w;
_game_size[1]=h; _game_size[1]=h;
_game_pos0[0]=0; _game_pos[0]=0;
_game_pos0[1]=0; _game_pos[1]=0;
_game_pos1[0]=0;
_game_pos1[1]=0;
_pft=1000/pfps; _ft=1000/fps;
return(1); return(1);
} }
@@ -73,9 +68,9 @@ int GameLib_Init(int w,int h,char *title,int pfps,int fps){
// GameLib_AddEntity // GameLib_AddEntity
// //
// Adds an entity to the game. // Adds an entity to the game.
void GameLib_AddEntity(Entity e){ void GameLib_AddEntity(Entity *e){
if(_n_entities>=_n_entities_res){ if(_n_entities>=_n_entities_res){
Entity *entity_aux; Entity **entity_aux;
int *entity_flag_aux; int *entity_flag_aux;
int i; int i;
@@ -84,7 +79,7 @@ void GameLib_AddEntity(Entity e){
_n_entities_res=32; _n_entities_res=32;
else else
_n_entities_res*=2; _n_entities_res*=2;
entity_aux=malloc(sizeof(Entity)*_n_entities_res); entity_aux=malloc(sizeof(Entity *)*_n_entities_res);
entity_flag_aux=malloc(sizeof(int)*_n_entities_res); entity_flag_aux=malloc(sizeof(int)*_n_entities_res);
for(i=0;i<_n_entities;i++){ for(i=0;i<_n_entities;i++){
entity_aux[i]=_entity[i]; entity_aux[i]=_entity[i];
@@ -105,8 +100,6 @@ void GameLib_AddEntity(Entity e){
// Mark for light update // Mark for light update
Entity_MarkUpdateLight(e,_entity,_n_entities); Entity_MarkUpdateLight(e,_entity,_n_entities);
Entity_CalcBBox(e);
} }
@@ -114,7 +107,7 @@ void GameLib_AddEntity(Entity e){
// GameLib_UnrefEntity // GameLib_UnrefEntity
// //
// removes the reference to the entity. // removes the reference to the entity.
int GameLib_UnrefEntity(Entity e){ int GameLib_UnrefEntity(Entity *e){
int i; int i;
for(i=0;i<_n_entities;i++){ for(i=0;i<_n_entities;i++){
if(e==_entity[i]){ if(e==_entity[i]){
@@ -140,7 +133,7 @@ int GameLib_UnrefEntity(Entity e){
// GameLib_DelEntity // GameLib_DelEntity
// //
// Adds an entity to the game. // Adds an entity to the game.
int GameLib_DelEntity(Entity e){ int GameLib_DelEntity(Entity *e){
int i; int i;
if((i=GameLib_UnrefEntity(e))==-1){ if((i=GameLib_UnrefEntity(e))==-1){
return(0); return(0);
@@ -184,19 +177,15 @@ void GameLib_Compactate(){
_entities_lock=0; _entities_lock=0;
} }
///////////////////////////// /////////////////////////////
// GameLib_ProcLoop // GameLib_ProcLoop
// //
// Process the loop. // Process the loop.
void GameLib_ProcLoop(void *data){ int GameLib_ProcLoop(){
int i,j; int i,j;
int repeat,count; int repeat,count;
long long time; long long time;
// Step the gamePosition
_game_pos0[0]=_game_pos1[0];
_game_pos0[1]=_game_pos1[1];
// Process // Process
time=Time_GetTime(); time=Time_GetTime();
@@ -207,43 +196,31 @@ void GameLib_ProcLoop(void *data){
for(i=0;i<_n_entities;i++){ for(i=0;i<_n_entities;i++){
if(!_entity[i]) if(!_entity[i])
continue; continue;
Entity_Process(_entity[i],_pft); Entity_Process(_entity[i],_ft);
} }
GameLib_Compactate(); GameLib_Compactate();
t_proc+=Time_GetTime()-time; t_proc+=Time_GetTime()-time;
// Colisions between entities // Colisions between entities
time=Time_GetTime(); time=Time_GetTime();
GameLib_Compactate();_entities_lock=1; GameLib_Compactate();_entities_lock=1;
count=0; count=0;
do{ do{
repeat=0; repeat=0;
CollisionInfo collInfo=NULL;
for(i=0;i<_n_entities;i++){ for(i=0;i<_n_entities;i++){
if(!(_entity[i]->flags&EntityFlag_Collision) || _entity[i]->mass<0.0f) if(!(_entity[i]->flags&EntityFlag_Collision) || _entity[i]->mass<0.0f)
continue; continue;
if(_entity[i]->vel[0]<=0.0f && _entity[i]->vel[0]>=-0.0f &&
_entity[i]->vel[1]<=0.0f && _entity[i]->vel[1]>=-0.0f)
{
continue;
}
for(j=0;j<_n_entities;j++){ for(j=0;j<_n_entities;j++){
if(!(_entity[j]->flags&EntityFlag_Collision) || if(!(_entity[j]->flags&EntityFlag_Collision) || i==j)
!Entity_BBoxIntersect(_entity[i],_entity[j]) ||
CollisionInfo_CheckRepetition(collInfo,_entity[i],_entity[j]))
{
continue; continue;
if(Entity_Collide(_entity[i],_entity[j])){
repeat=1;
} }
Entity_CheckCollision(_entity[i],_entity[j],&collInfo);
} }
} }
if(Entity_CollisionInfoResponse(collInfo)){
repeat=1;
}
CollisionInfo_Destroy(&collInfo);
count++; count++;
}while(repeat && count<50); }while(repeat && count<10);
// Stop remaining collisions // Stop remaining collisions
if(count==10){ if(count==10){
for(i=0;i<_n_entities;i++){ for(i=0;i<_n_entities;i++){
@@ -252,11 +229,9 @@ void GameLib_ProcLoop(void *data){
for(j=0;j<_n_entities;j++){ for(j=0;j<_n_entities;j++){
if(!(_entity[j]->flags&EntityFlag_Collision) || i==j) if(!(_entity[j]->flags&EntityFlag_Collision) || i==j)
continue; continue;
if(Entity_CheckCollision(_entity[i],_entity[j],NULL)){ if(Entity_Collide(_entity[i],_entity[j])){
vec2_set(_entity[i]->vel,0,0); vec2_set(_entity[i]->vel,0,0);
Entity_CalcBBox(_entity[i]);
vec2_set(_entity[j]->vel,0,0); vec2_set(_entity[j]->vel,0,0);
Entity_CalcBBox(_entity[j]);
} }
} }
} }
@@ -285,25 +260,21 @@ void GameLib_ProcLoop(void *data){
do{ do{
n2=0; n2=0;
for(i=1;i<n;i++){ for(i=1;i<n;i++){
Entity ent1=_entity[i-1];
Entity ent2=_entity[i];
swap=0; swap=0;
if(ent1->zorder > ent2->zorder){ if(_entity[i-1]->zorder > _entity[i]->zorder){
// Lower level // Lower level
swap=1; swap=1;
}else }else
if(ent1->zorder < ent2->zorder){ if(_entity[i-1]->zorder < _entity[i]->zorder){
// Upper level // Upper level
}else{ }else{
// Same level // Same level
float y1=ent1->pos[1]+ent1->sortYOffset; if(_entity[i-1]->pos[1] > _entity[i]->pos[1]){
float y2=ent2->pos[1]+ent2->sortYOffset;
if(y1 > y2){
swap=1; swap=1;
} }
} }
if(swap){ if(swap){
Entity ent; Entity *ent;
ent=_entity[i]; ent=_entity[i];
_entity[i]=_entity[i-1]; _entity[i]=_entity[i-1];
_entity[i-1]=ent; _entity[i-1]=ent;
@@ -313,11 +284,12 @@ void GameLib_ProcLoop(void *data){
n=n2; n=n2;
}while(n>0); }while(n>0);
// PostProcess // PostProcess
time=Time_GetTime(); time=Time_GetTime();
GameLib_Compactate();_entities_lock=1; GameLib_Compactate();_entities_lock=1;
for(i=0;i<_n_entities;i++){ for(i=0;i<_n_entities;i++){
Entity_PostProcess(_entity[i],_pft); Entity_PostProcess(_entity[i],_ft);
if(_entity[i]->flags&EntityFlag_UpdatedPos){ if(_entity[i]->flags&EntityFlag_UpdatedPos){
Entity_MarkUpdateLight(_entity[i],_entity,_n_entities); Entity_MarkUpdateLight(_entity[i],_entity,_n_entities);
} }
@@ -329,6 +301,8 @@ void GameLib_ProcLoop(void *data){
t_postproc+=Time_GetTime()-time; t_postproc+=Time_GetTime()-time;
fproc_count++; fproc_count++;
return(_running);
} }
@@ -336,19 +310,20 @@ void GameLib_ProcLoop(void *data){
// GameLib_DrawLoop // GameLib_DrawLoop
// //
// //
void GameLib_DrawLoop(void *data, float f){ void GameLib_DrawLoop(){
long long time; long long time;
int i; int i;
int game_pos[2];
game_pos[0]=_game_pos0[0]+f*(_game_pos1[0]-_game_pos0[0]);
game_pos[1]=_game_pos0[1]+f*(_game_pos1[1]-_game_pos0[1]);
time=Time_GetTime(); time=Time_GetTime();
// Update Lights
//GameLib_UpdateIlumination();
// Predibujado // Predibujado
if(_gamepredraw){ if(_gamepredraw){
_gamepredraw(f); _gamepredraw();
}else{ }else{
// Limpiar pantalla // Limpiar pantalla
Draw_Clean(0,0,0); Draw_Clean(0,0,0);
@@ -357,11 +332,11 @@ void GameLib_DrawLoop(void *data, float f){
// Draw entities // Draw entities
GameLib_Compactate();_entities_lock=1; GameLib_Compactate();_entities_lock=1;
for(i=0;i<_n_entities;i++){ for(i=0;i<_n_entities;i++){
Entity e=_entity[i]; Entity *e=_entity[i];
// Check visivility // Check visivility
if(!Entity_IsVisible(e, if(!Entity_IsVisible(e,
game_pos[0],game_pos[1], _game_pos[0],_game_pos[1],
_game_size[0],_game_size[1])) _game_size[0],_game_size[1]))
{ {
continue; continue;
@@ -373,37 +348,18 @@ void GameLib_DrawLoop(void *data, float f){
e->flags&=~EntityFlag_UpdateLight; e->flags&=~EntityFlag_UpdateLight;
} }
Entity_Draw(e,-game_pos[0],-game_pos[1],f); Entity_Draw(e,-_game_pos[0],-_game_pos[1]);
} }
Draw_SetColor(1,1,1,1); Draw_SetColor(1,1,1,1);
if(_gamedraw){ if(_gamedraw){
_gamedraw(f); _gamedraw();
} }
GameLib_Compactate(); GameLib_Compactate();
t_draw+=Time_GetTime()-time; t_draw+=Time_GetTime()-time;
fdraw_count++; fdraw_count++;
if(Input_GetKey(InputKey_DumpProfiling)==InputKey_Pressed){
printf("Profiling:::::::::\n");
if(fproc_count>0){
printf("t_proc.....:%6lld\n",t_proc/fproc_count);
printf("t_col......:%6lld\n",t_col/fproc_count);
printf("t_over.....:%6lld\n",t_over/fproc_count);
printf("t_postproc.:%6lld\n",t_postproc/fproc_count);
}
if(fdraw_count>0){
printf("t_draw.....:%6lld\n",t_draw/fdraw_count);
}
t_proc=0;
t_col=0;
t_over=0;
t_postproc=0;
t_draw=0;
fproc_count=0;
fdraw_count=0;
}
} }
@@ -414,9 +370,11 @@ void GameLib_DrawLoop(void *data, float f){
void GameLib_Loop( void GameLib_Loop(
void (*gameproc)(), void (*gameproc)(),
void (*gamepostproc)(), void (*gamepostproc)(),
void (*gamepredraw)(float f), void (*gamepredraw)(),
void (*gamedraw)(float f)) void (*gamedraw)())
{ {
_running=1;
_gameproc=gameproc; _gameproc=gameproc;
_gamepostproc=gamepostproc; _gamepostproc=gamepostproc;
_gamepredraw=gamepredraw; _gamepredraw=gamepredraw;
@@ -428,30 +386,41 @@ void GameLib_Loop(
t_draw=0; t_draw=0;
fproc_count=0; fproc_count=0;
fdraw_count=0; fdraw_count=0;
Draw_Loop(GameLib_ProcLoop,GameLib_DrawLoop,NULL); Draw_Loop(GameLib_ProcLoop,GameLib_DrawLoop);
if (gamelib_debug) {
printf("Profiling:::::::::\n");
printf("t_proc.....:%6lld\n",t_proc/fproc_count);
printf("t_col......:%6lld\n",t_col/fproc_count);
printf("t_over.....:%6lld\n",t_over/fproc_count);
printf("t_postproc.:%6lld\n",t_postproc/fproc_count);
printf("t_draw.....:%6lld\n",t_draw/fdraw_count);
}
}
/////////////////////////////
// GameLib_BreakLoop
//
// Breaks the game loop.
void GameLib_BreakLoop(){
_running=0;
} }
///////////////////////////// /////////////////////////////
// GameLib_GetPos // GameLib_GetPos
// GameLib_SetPos // GameLib_SetPos
// GameLib_UpdatePos
// GameLib_SetPos // GameLib_SetPos
// //
// //
void GameLib_GetPos(int pos[2]){ void GameLib_GetPos(int pos[2]){
pos[0]=_game_pos1[0]; pos[0]=_game_pos[0];
pos[1]=_game_pos1[1]; pos[1]=_game_pos[1];
} }
void GameLib_SetPos(int pos[2]){ void GameLib_SetPos(int pos[2]){
_game_pos0[0]=pos[0]; _game_pos[0]=pos[0];
_game_pos0[1]=pos[1]; _game_pos[1]=pos[1];
_game_pos1[0]=pos[0];
_game_pos1[1]=pos[1];
}
void GameLib_UpdatePos(int pos[2]){
_game_pos1[0]=pos[0];
_game_pos1[1]=pos[1];
} }
void GameLib_GetSize(int size[2]){ void GameLib_GetSize(int size[2]){
size[0]=_game_size[0]; size[0]=_game_size[0];
@@ -472,10 +441,10 @@ void GameLib_MoveToPos(vec2 pos,float f){
GameLib_MoveToPosV(pos,f); GameLib_MoveToPosV(pos,f);
} }
void GameLib_MoveToPosH(vec2 pos,float f){ void GameLib_MoveToPosH(vec2 pos,float f){
_game_pos1[0]=_game_pos1[0]+(pos[0]-(_game_pos1[0]+(_game_size[0]/2.0f)))*f; _game_pos[0]=_game_pos[0]+(pos[0]-(_game_pos[0]+(_game_size[0]/2.0f)))*f;
} }
void GameLib_MoveToPosV(vec2 pos,float f){ void GameLib_MoveToPosV(vec2 pos,float f){
_game_pos1[1]=_game_pos1[1]+(pos[1]-(_game_pos1[1]+(_game_size[1]/2.0f)))*f; _game_pos[1]=_game_pos[1]+(pos[1]-(_game_pos[1]+(_game_size[1]/2.0f)))*f;
} }
@@ -501,7 +470,7 @@ void GameLib_DelEnts(){
// GameLib_ForEachEn // GameLib_ForEachEn
// //
// Iterates every entity. // Iterates every entity.
void GameLib_ForEachEnt(int (*func)(Entity ent)){ void GameLib_ForEachEnt(int (*func)(Entity *ent)){
int i; int i;
for(i=0;i<_n_entities;i++){ for(i=0;i<_n_entities;i++){
if(!_entity[i]) if(!_entity[i])
@@ -513,25 +482,6 @@ void GameLib_ForEachEnt(int (*func)(Entity ent)){
} }
/////////////////////////////
// GameLib_SearchEnt
//
// Searches throught the entities.
Entity GameLib_SearchEnt(int (*func)(Entity ent,void *d),void *d){
int i;
Entity ent=NULL;
for(i=0;i<_n_entities;i++){
if(!_entity[i])
continue;
if(func(_entity[i],d)){
ent=_entity[i];
break;
}
}
return ent;
}
///////////////////////////// /////////////////////////////
// GameLib_PlaySound // GameLib_PlaySound
// //
@@ -541,8 +491,8 @@ void GameLib_PlaySound(AudioSnd snd,int x,int y){
int r,cx,cy,off; int r,cx,cy,off;
// Get the screen context // Get the screen context
cx=_game_pos1[0]+_game_size[0]/2; cx=_game_pos[0]+_game_size[0]/2;
cy=_game_pos1[1]+_game_size[1]/2; cy=_game_pos[1]+_game_size[1]/2;
if(_game_size[0]>_game_size[1]){ if(_game_size[0]>_game_size[1]){
r=_game_size[0]/2; r=_game_size[0]/2;
}else{ }else{
@@ -590,7 +540,7 @@ void GameLib_Iluminate(){
// GameLib_EntitySetLight // GameLib_EntitySetLight
// //
// //
void GameLib_EntitySetLight(Entity e,float r,float g,float b,float rad){ void GameLib_EntitySetLight(Entity *e,float r,float g,float b,float rad){
if(e->flags&EntityFlag_Light){ if(e->flags&EntityFlag_Light){
Entity_MarkUpdateLight(e,_entity,_n_entities); Entity_MarkUpdateLight(e,_entity,_n_entities);
Entity_SetLight(e,r,g,b,rad); Entity_SetLight(e,r,g,b,rad);

View File

@@ -23,21 +23,21 @@ int GameLib_Init(int w,int h,char *title,int pfps,int fps);
// GameLib_AddEntity // GameLib_AddEntity
// //
// Adds an entity to the game. // Adds an entity to the game.
void GameLib_AddEntity(Entity e); void GameLib_AddEntity(Entity *e);
///////////////////////////// /////////////////////////////
// GameLib_UnrefEntity // GameLib_UnrefEntity
// //
// removes the reference to the entity. // removes the reference to the entity.
int GameLib_UnrefEntity(Entity e); int GameLib_UnrefEntity(Entity *e);
///////////////////////////// /////////////////////////////
// GameLib_DelEntity // GameLib_DelEntity
// //
// Adds an entity to the game. // Adds an entity to the game.
int GameLib_DelEntity(Entity e); int GameLib_DelEntity(Entity *e);
///////////////////////////// /////////////////////////////
@@ -47,8 +47,15 @@ int GameLib_DelEntity(Entity e);
void GameLib_Loop( void GameLib_Loop(
void (*gameproc)(), void (*gameproc)(),
void (*gamepostproc)(), void (*gamepostproc)(),
void (*gamepredraw)(float f), void (*gamepredraw)(),
void (*gamedraw)(float f)); void (*gamedraw)());
/////////////////////////////
// GameLib_BreakLoop
//
// Breaks the game loop.
void GameLib_BreakLoop();
///////////////////////////// /////////////////////////////
@@ -81,17 +88,10 @@ void GameLib_DelEnts();
///////////////////////////// /////////////////////////////
// GameLib_ForEachEnt // GameLib_ForEachEn
// //
// Iterates every entity. // Iterates every entity.
void GameLib_ForEachEnt(int (*func)(Entity ent)); void GameLib_ForEachEnt(int (*func)(Entity *ent));
/////////////////////////////
// GameLib_SearchEnt
//
// Searches throught the entities.
Entity GameLib_SearchEnt(int (*func)(Entity ent,void *d),void *d);
///////////////////////////// /////////////////////////////
@@ -112,7 +112,7 @@ void GameLib_Iluminate();
// GameLib_EntitySetLight // GameLib_EntitySetLight
// //
// //
void GameLib_EntitySetLight(Entity e,float r,float g,float b,float rad); void GameLib_EntitySetLight(Entity *e,float r,float g,float b,float rad);
///////////////////////////// /////////////////////////////

View File

@@ -2,21 +2,15 @@
#include <math.h> #include <math.h>
#include <SDL/SDL.h> #include <SDL/SDL.h>
#ifdef EMSCRIPTEN
#define SDL_GetKeyState SDL_GetKeyboardState
#endif
#include "Util.h" #include "Util.h"
#include "Input.h" #include "Input.h"
// Globals // Globals
InputKeyStatus _keys[InputKey_Max]; InputKeyStatus _keys[InputKey_Max];
int _pointerDown=0;
SDL_Joystick *_joy; SDL_Joystick *_joy;
///////////////////////////// /////////////////////////////
// Input_Init // Input_Init
// //
@@ -62,10 +56,8 @@ int Input_Init(){
void Input_Frame(){ void Input_Frame(){
Uint8* keys; Uint8* keys;
// Get keyboard state
keys=(Uint8 *)SDL_GetKeyState(NULL);
// Process Keys // Process Keys
keys=SDL_GetKeyState(NULL);
Input_SetKey(InputKey_Action1,keys[SDLK_z]); Input_SetKey(InputKey_Action1,keys[SDLK_z]);
Input_SetKey(InputKey_Action2,keys[SDLK_x]); Input_SetKey(InputKey_Action2,keys[SDLK_x]);
Input_SetKey(InputKey_Up,keys[SDLK_UP]); Input_SetKey(InputKey_Up,keys[SDLK_UP]);
@@ -73,9 +65,7 @@ void Input_Frame(){
Input_SetKey(InputKey_Left,keys[SDLK_LEFT]); Input_SetKey(InputKey_Left,keys[SDLK_LEFT]);
Input_SetKey(InputKey_Right,keys[SDLK_RIGHT]); Input_SetKey(InputKey_Right,keys[SDLK_RIGHT]);
Input_SetKey(InputKey_Jump,keys[SDLK_SPACE]); Input_SetKey(InputKey_Jump,keys[SDLK_SPACE]);
Input_SetKey(InputKey_Continue,keys[SDLK_RETURN]|keys[SDLK_KP_ENTER]|_pointerDown); Input_SetKey(InputKey_Continue,keys[SDLK_RETURN]|keys[SDLK_KP_ENTER]);
Input_SetKey(InputKey_DumpProfiling,keys[SDLK_p]);
} }
@@ -105,14 +95,6 @@ InputKeyStatus Input_GetKey(InputKey key){
} }
/////////////////////////////
// Input_SetPointerDown
//
void Input_SetPointerDown(int pointerDown){
_pointerDown=pointerDown;
}
///////////////////////////// /////////////////////////////
// Input_AnyKey // Input_AnyKey
// //

View File

@@ -33,10 +33,6 @@ typedef enum {
InputKey_Right, InputKey_Right,
InputKey_Jump, InputKey_Jump,
InputKey_Continue, InputKey_Continue,
InputKey_Exit,
InputKey_DumpProfiling,
InputKey_Max InputKey_Max
} InputKey; } InputKey;
@@ -66,12 +62,6 @@ typedef enum {
InputKeyStatus Input_GetKey(InputKey key); InputKeyStatus Input_GetKey(InputKey key);
/////////////////////////////
// Input_SetPointerDown
//
void Input_SetPointerDown(int pointerDown);
///////////////////////////// /////////////////////////////
// Input_AnyKey // Input_AnyKey
// //

View File

@@ -1,78 +0,0 @@
// Copyright (C) 2013 Valeriano Alfonso Rodriguez (Kableado)
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "QuadArray2D.h"
QuadArray2D QuadArray2D_Create(int resVertex){
QuadArray2D quadArray=NULL;
quadArray=malloc(sizeof(TQuadArray2D));
quadArray->vertexData=malloc(sizeof(float)*Vertex2D_Length*resVertex);
quadArray->nVertex=0;
quadArray->resVertex=resVertex;
return quadArray;
}
void QuadArray2D_Destroy(QuadArray2D *quadArray){
if(!quadArray) return;
if(!quadArray[0]) return;
free(quadArray[0]->vertexData);
free(quadArray[0]);
quadArray[0]=NULL;
}
void QuadArray2D_Clean(QuadArray2D quadArray){
quadArray->nVertex=0;
}
void QuadArray2D_AddVertex(QuadArray2D quadArray,float v[]){
if(quadArray->resVertex<=quadArray->nVertex){
// Grow vertexData
quadArray->resVertex*=2;
float *newVertexData=malloc(sizeof(float)*Vertex2D_Length*
quadArray->resVertex);
memcpy(newVertexData,quadArray->vertexData,
sizeof(float)*Vertex2D_Length*quadArray->nVertex);
free(quadArray->vertexData);
quadArray->vertexData=newVertexData;
}
// Add the vertex
memcpy(
quadArray->vertexData+
(Vertex2D_Length*quadArray->nVertex),
v,sizeof(float)*Vertex2D_Length);
quadArray->nVertex++;
}
void QuadArray2D_AddQuad(QuadArray2D quadArray,
float x0, float y0,float u0, float v0,
float x1, float y1,float u1, float v1,
float color[])
{
float v[Vertex2D_Length];
int firstIndex=quadArray->nVertex;
// Set the color
v[4]=color[0];
v[5]=color[1];
v[6]=color[2];
v[7]=color[3];
// Add the vertexes
v[0]=x0; v[1]=y0; v[2]=u0; v[3]=v0; QuadArray2D_AddVertex(quadArray,v);
v[0]=x1; v[1]=y0; v[2]=u1; v[3]=v0; QuadArray2D_AddVertex(quadArray,v);
v[0]=x1; v[1]=y1; v[2]=u1; v[3]=v1; QuadArray2D_AddVertex(quadArray,v);
v[0]=x1; v[1]=y1; v[2]=u1; v[3]=v1; QuadArray2D_AddVertex(quadArray,v);
v[0]=x0; v[1]=y1; v[2]=u0; v[3]=v1; QuadArray2D_AddVertex(quadArray,v);
v[0]=x0; v[1]=y0; v[2]=u0; v[3]=v0; QuadArray2D_AddVertex(quadArray,v);
}

View File

@@ -1,35 +0,0 @@
// Copyright (C) 2013 Valeriano Alfonso Rodriguez (Kableado)
#ifndef _QUADARRAY2D_H_
#define _QUADARRAY2D_H_
// Vertex2D -> (x,y) (u,v) (r,g,b,a)
#define Vertex2D_Length 8
////////////////////////////////////////////////
// QuadArray2D
//
typedef struct TQuadArray2D TQuadArray2D, *QuadArray2D;
struct TQuadArray2D {
float *vertexData;
int nVertex;
int resVertex;
};
QuadArray2D QuadArray2D_Create(int resVertex);
void QuadArray2D_Destroy(QuadArray2D *quadArray);
void QuadArray2D_Clean(QuadArray2D quadArray);
void QuadArray2D_AddVertex(QuadArray2D quadArray,float v[]);
void QuadArray2D_AddQuad(QuadArray2D quadArray,
float x0, float y0,float u0, float v0,
float x1, float y1,float u1, float v1,
float color[]);
#endif

View File

@@ -1,10 +1,11 @@
// Copyright (C) 2011-2014 Valeriano Alfonso Rodriguez (Kableado) // Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <SDL/SDL.h>
#include "Time.h" #include "Time.h"
@@ -37,7 +38,7 @@ void Time_Pause(int pausa){
do{ do{
diff=tend-t; diff=tend-t;
if(diff>1000){ if(diff>1000){
Sleep(diff/1000); SDL_Delay(diff/1000);
}else{ }else{
Sleep(0); Sleep(0);
} }
@@ -45,6 +46,25 @@ void Time_Pause(int pausa){
}while(tend>=t); }while(tend>=t);
} }
#else #else
#ifdef MACOSX
#include <mach/mach_time.h>
// MacOSX
long long Time_GetTime(){
static mach_timebase_info_data_t info = {0,0};
uint64_t t;
if(info.denom==0){
mach_timebase_info(&info);
}
t=mach_absolute_time()*(info.numer / info.denom);
return(t/1000);
}
void Time_Pause(int pausa){
struct timeval tv;
tv.tv_sec=(long long)pausa/1000000;
tv.tv_usec=(long long)pausa%1000000;
select(0, NULL, NULL, NULL, &tv);
}
#else
// UNIX // UNIX
long long Time_GetTime(){ long long Time_GetTime(){
struct timeval t; struct timeval t;
@@ -59,6 +79,7 @@ void Time_Pause(int pausa){
tv.tv_usec=(long long)pausa%1000000; tv.tv_usec=(long long)pausa%1000000;
select(0, NULL, NULL, NULL, &tv); select(0, NULL, NULL, NULL, &tv);
} }
#endif // if MACOSX
#endif // if WIN32 #endif // if WIN32

View File

@@ -1,8 +1,6 @@
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado) // Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
#include <math.h> #include <math.h>
#include <stdlib.h>
#include <string.h>
#include "Util.h" #include "Util.h"
@@ -17,60 +15,6 @@ float vec2_norm(vec2 v){
return(len); return(len);
} }
void vec2_orthogonalize4(vec2 v) {
if (fabs(v[0]) > fabs(v[1])) {
if (v[0] >= 0) {
v[0] = 1.0f;
v[1] = 0.0f;
} else {
v[0] = -1.0f;
v[1] = 0.0f;
}
} else {
if (v[1] >= 0) {
v[1] = 1.0f;
v[0] = 0.0f;
} else {
v[1] = -1.0f;
v[0] = 0.0f;
}
}
}
void vec2_orthogonalize8(vec2 v) {
float diff = fabs(fabs(v[0]) - fabs(v[1]));
if (diff > 0.2f) {
if (fabs(v[0]) > fabs(v[1])) {
if (v[0] >= 0) {
v[0] = 1.0f;
v[1] = 0.0f;
} else {
v[0] = -1.0f;
v[1] = 0.0f;
}
} else {
if (v[1] >= 0) {
v[1] = 1.0f;
v[0] = 0.0f;
} else {
v[1] = -1.0f;
v[0] = 0.0f;
}
}
} else {
if (v[0] > 0.0f) {
v[0] = 0.707f;
} else {
v[0] = -0.707f;
}
if (v[1] > 0.0f) {
v[1] = 0.707f;
} else {
v[1] = -0.707f;
}
}
}
///////////////////////////// /////////////////////////////
// SolveQuadratic // SolveQuadratic
@@ -176,9 +120,10 @@ int Colision_CircleCircle(
vec2_scale(cen_a,cir2,invrads); vec2_scale(cen_a,cir2,invrads);
if(Intersec_RayUnitCircle(orig_a,vel_a,cen_a,t)){ if(Intersec_RayUnitCircle(orig_a,vel_a,cen_a,t)){
// Calculate n // Calculate n
vec2_scaleadd(temp,cir1,vel,*t); vec2_scale(temp,vel,*t);
vec2_minus(n,temp,cir2); vec2_plus(temp,cir1,temp);
vec2_scale(n,n,invrads); vec2_minus(temp,cir2,temp);
vec2_scale(n,temp,1.0f/rads);
return(1); return(1);
} }
return(0); return(0);
@@ -243,6 +188,7 @@ int absmod(int v,int d){
return(v%d); return(v%d);
} }
} }
float fabsmod(float v,int d){ float fabsmod(float v,int d){
if(v<0){ if(v<0){
v+=d*((((int)(v/d))*(-1))+1); v+=d*((((int)(v/d))*(-1))+1);
@@ -254,29 +200,4 @@ float fabsmod(float v,int d){
} }
/////////////////////////////
// IsBigEndian
//
int IsBigEndian(){
union{
unsigned int i;
char c[4];
} bint={0x01020304};
return bint.c[0]==1;
}
/////////////////////////////
// EndsWith
//
int EndsWith(char *str, char *suffix){
if (!str || !suffix)
return 0;
int lenStr = strlen(str);
int lenSuffix = strlen(suffix);
if (lenSuffix > lenStr)
return 0;
return strncmp(str+lenStr-lenSuffix, suffix, lenSuffix)==0;
}

View File

@@ -26,12 +26,6 @@ typedef float vec2[2];
#define vec2_perp(v,n) (v)[0]=-(n)[1];(v)[1]=(n)[0]; #define vec2_perp(v,n) (v)[0]=-(n)[1];(v)[1]=(n)[0];
#define vec2_scaleadd(v,v1,v2,s) (v)[0]=(v2)[0]*(s)+(v1)[0];(v)[1]=(v2)[1]*(s)+(v1)[1]; #define vec2_scaleadd(v,v1,v2,s) (v)[0]=(v2)[0]*(s)+(v1)[0];(v)[1]=(v2)[1]*(s)+(v1)[1];
float vec2_norm(vec2 v); float vec2_norm(vec2 v);
#define vec2_interpol(v,v1,v2,f) \
(v)[0]=(v1)[0]-f*((v1)[0]-(v2)[0]);\
(v)[1]=(v1)[1]-f*((v1)[1]-(v2)[1]);
void vec2_orthogonalize4(vec2 v);
void vec2_orthogonalize8(vec2 v);
///////////////////////////// /////////////////////////////
@@ -40,7 +34,6 @@ void vec2_orthogonalize8(vec2 v);
// Intersection between a ray and a Unit Circle. // Intersection between a ray and a Unit Circle.
int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t); int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t);
///////////////////////////// /////////////////////////////
// Intersect_CircleCircle // Intersect_CircleCircle
// //
@@ -50,7 +43,6 @@ int Colision_CircleCircle(
vec2 cb,float rb, vec2 cb,float rb,
float *t,vec2 n); float *t,vec2 n);
///////////////////////////// /////////////////////////////
// Intersect_RayEdge // Intersect_RayEdge
// //
@@ -61,6 +53,7 @@ int Intersect_RayEdge(
float *t); float *t);
///////////////////////////// /////////////////////////////
// absmod // absmod
// //
@@ -68,16 +61,4 @@ int absmod(int v,int d);
float fabsmod(float v,int d); float fabsmod(float v,int d);
/////////////////////////////
// IsBigEndian
//
int IsBigEndian();
/////////////////////////////
// EndsWith
//
int EndsWith(char *str, char *suffix);
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

295
GameMap.c
View File

@@ -1,216 +1,173 @@
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado) // Copyright (C) 2012 Valeriano Alfonso Rodriguez (Kableado)
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <stdlib.h>
#include <math.h>
#include "GameLib.h" #include "GameLib.h"
#include "GameEnts.h"
#include "GameEnts.h"
#include "GameMap.h" #include "GameMap.h"
Entity GameMapAux_CreateEnt(Entity ent,int i,int j){
Entity e;
e=Entity_Copy(ent);
vec2_set(e->pos,16+i*32,16+j*32);
Entity_CalcBBox(e);
GameLib_AddEntity(e);
return(e);
}
void Aux_Linea(FILE *f,char *line){ int ReadLine(FILE *f,char *line,int max){
int c; int c;
int i=0; int i=0;
memset(line,0,1024); while(i<(max-1)){
while(i<1024){
c=fgetc(f); c=fgetc(f);
if(c==EOF){ if(c==EOF){
line[i]=0; line[i]=0;
break; return(-1);
} }
if(c=='\r'){ if(c=='\r'){
continue; continue;
} }
if(c=='\n'){ if(c=='\n'){
line[i]=0; line[i]=0;
break; return(i);
} }
line[i]=c; line[i]=c;
i++; i++;
} }
line[i]=0;
return(i);
} }
int _startpoint;
int GameMapAux_CreatePlayer(Entity ent){ Entity *GameMapAux_CreateEnt(Entity *ent,int i,int j,int res){
if(ent->type==Ent_SavePoint){ Entity *e;
if(ent->A==_startpoint){ vec2 pos;
Entity e; e=Entity_Copy(ent);
e=Entity_Copy(ent_player); vec2_set(pos,(res/2)+i*res,(res/2)+j*res);
vec2_copy(e->pos,ent->pos); vec2_plus(e->pos,e->pos,pos);
GameLib_AddEntity(e); GameLib_AddEntity(e);
return(0); return(e);
}
}
return(1);
} }
int GameMapAux_IsFloor(char c){
if( c=='.' ||
c=='#' ||
c=='m' ||
c=='B' ||
c=='S' ||
c=='E' ||
c=='F' ||
c=='A' ||
c=='V' ||
c=='<' ||
c=='>' ||
c=='r' ||
c=='T' ||
c=='D' ||
c=='l' )
{
return(1);
}
return(0);
}
int GameMap_CreateLevel(int level,int point){ #define MaxLineLen 1024
char filename[128];
int GameMap_LoadLevel(char *filename,int res){
FILE *file; FILE *file;
char line[1024]; char line[MaxLineLen];
int w,h; int len,i,j;
int i,j,i2; int width,height;
int floor; char *map;
sprintf(filename,"data/level_%02d.txt",level);
file=fopen(filename,"r"); // Open the file
file=fopen(filename,"rb");
if(!file){ if(!file){
return(0); return(0);
} }
GameLib_DelEnts(); // Read the file to determine sizes
width=0;
height=0;
do{
len=ReadLine(file,line,MaxLineLen);
if(len>-1){
if(len>height){
height=len;
}
width++;
}
}while(len>-1);
fseek(file,0,SEEK_SET);
Aux_Linea(file,line);
sscanf(line,"%d %d",&w,&h); // Build the map
for(j=0;j<h;j++){ map=malloc(sizeof(char)*width*height);
Aux_Linea(file,line); memset(map,0,width*height);
for(i=0;i<w;i++){ #define MAP(x,y) map[(x)+((y)*width)]
i2=i*2; j=0;
// Prepare the floor do{
floor=0; len=ReadLine(file,line,MaxLineLen);
if(i>0){ for(i=0;i<len;i++){
if(GameMapAux_IsFloor(line[i2-2])){ MAP(j,(height-1)-i)=line[i];
floor|=4; }
} j++;
}while(len>-1);
// Close the file
fclose(file);
// Parse the map
for(j=0;j<height;j++){
for(i=0;i<width;i++){
Entity *ent;
if(MAP(i,j)=='P'){
// Player
GameMapAux_CreateEnt(ent_Wizard,i,j,res);
} }
if(i<(w-1)){ if(MAP(i,j)=='#'){
if(GameMapAux_IsFloor(line[i2+2])){ // Earth
floor|=1; int x,y;
} int up,down,left,right;
ent=GameMapAux_CreateEnt(ent_Earth,i,j,res);
x=i;y=j-1;if(y<0)y=0;
up=MAP(x,y)=='#'?0:1;
x=i;y=j+1;if(y>=height)y=height-1;
down=MAP(x,y)=='#'?0:1;
x=i-1;y=j;if(x<0)x=0;
left=MAP(x,y)=='#'?0:1;
x=i+1;y=j;if(x>=width)x=width-1;
right=MAP(x,y)=='#'?0:1;
EntEarth_Init(ent,up,down,left,right);
} }
if(GameMapAux_IsFloor(line[i2])){ if(MAP(i,j)=='R'){
floor|=2; // StoneBrick
} int x,y;
if(floor==7){ int up,down,left,right;
GameMapAux_CreateEnt(ent_floor,i,j);
} ent=GameMapAux_CreateEnt(ent_StoneBrick,i,j,res);
if(floor==6){
GameMapAux_CreateEnt(ent_floor_right,i,j); x=i;y=j-1;if(y<0)y=0;
} up=MAP(x,y)=='R'?0:1;
if(floor==3){ x=i;y=j+1;if(y>=height)y=height-1;
GameMapAux_CreateEnt(ent_floor_left,i,j); down=MAP(x,y)=='R'?0:1;
} x=i-1;y=j;if(x<0)x=0;
if(floor==2){ left=MAP(x,y)=='R'?0:1;
GameMapAux_CreateEnt(ent_floor_center,i,j); x=i+1;y=j;if(x>=width)x=width-1;
right=MAP(x,y)=='R'?0:1;
EntStoneBrick_Init(ent,up,down,left,right);
} }
// Put the rest of the entities if(MAP(i,j)=='S'){
if(line[i2]=='.'){ // Spiked Bush
// Floor ent=GameMapAux_CreateEnt(ent_SpikedBush,i,j,res);
}else }
if(line[i2]=='#'){
// Column if(MAP(i,j)=='F'){
GameMapAux_CreateEnt(ent_column,i,j); // Flower
}else ent=GameMapAux_CreateEnt(ent_Flower[0],i,j,res);
if(line[i2]=='m'){ }
// Column faded if(MAP(i,j)=='f'){
GameMapAux_CreateEnt(ent_column_faded,i,j); // Flower
}else ent=GameMapAux_CreateEnt(ent_Flower[1],i,j,res);
if(line[i2]=='r'){ }
// Rock
GameMapAux_CreateEnt(ent_rock,i,j); if(MAP(i,j)=='B'){
}else // Bunny
if(line[i2]=='l'){ ent=GameMapAux_CreateEnt(ent_Bunny,i,j,res);
// Lamp }
GameMapAux_CreateEnt(ent_lamp,i,j);
}else
if(line[i2]=='B'){
// Barrel
GameMapAux_CreateEnt(ent_barrel,i,j);
}else
if(line[i2]=='|'){
// Spiked hole
GameMapAux_CreateEnt(ent_hole_spiked,i,j);
}else
if(line[i2]=='L'){
// Lava hole
GameMapAux_CreateEnt(ent_hole_lava,i,j);
}else
if(line[i2]=='S'){
Entity e;
// Save point
e=GameMapAux_CreateEnt(ent_savepoint,i,j);
e->A=line[i2+1]-'0';
}else
if(line[i2]=='E'){
// Exit point
GameMapAux_CreateEnt(ent_exitpoint,i,j);
}else
if(line[i2]=='F'){
// End point
GameMapAux_CreateEnt(ent_endpoint,i,j);
}else
if(line[i2]=='>'){
// ArrowShooter right
GameMapAux_CreateEnt(ent_arrowshooter_right,i,j);
}else
if(line[i2]=='<'){
// ArrowShooter left
GameMapAux_CreateEnt(ent_arrowshooter_left,i,j);
}else
if(line[i2]=='V'){
// ArrowShooter down
GameMapAux_CreateEnt(ent_arrowshooter_down,i,j);
}else
if(line[i2]=='A'){
// ArrowShooter up
GameMapAux_CreateEnt(ent_arrowshooter_up,i,j);
}else
/*if(line[i2]=='T'){
// Teleporter
Entity ent=GameMapAux_CreateEnt(ent_teleporter,i,j);
ent->A=line[i2+1]-'0';
}else
if(line[i2]=='D'){
// Teleporter Destination
Entity ent=GameMapAux_CreateEnt(ent_teleporter_dest,i,j);
ent->A=line[i2+1]-'0';
}else
*/
{}
} }
} }
fclose(file);
// Find the player start position // Cleanup
_startpoint=point; free(map);
GameLib_ForEachEnt(GameMapAux_CreatePlayer); #undef MAP
// Iluminate
//GameLib_Iluminate();
return(1); return(1);
} }

View File

@@ -1,10 +1,8 @@
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado) // Copyright (C) 2012 Valeriano Alfonso Rodriguez (Kableado)
#ifndef _GAMEMAP_H_ #ifndef _GAMEMAP_H_
#define _GAMEMAP_H_ #define _GAMEMAP_H_
int GameMap_CreateLevel(int level,int point); int GameMap_LoadLevel(char *filename,int res);
#endif #endif _GAMEMAP_H_

View File

@@ -7,7 +7,6 @@ CFLAGS += -IGameLib
HEADS= \ HEADS= \
GameLib/Time.h \ GameLib/Time.h \
GameLib/Util.h \ GameLib/Util.h \
GameLib/QuadArray2D.h \
GameLib/Draw.h \ GameLib/Draw.h \
GameLib/Input.h \ GameLib/Input.h \
GameLib/Audio.h \ GameLib/Audio.h \
@@ -17,7 +16,6 @@ HEADS= \
OBJS= \ OBJS= \
$(BUILDDIR)/GameLib/Time.o \ $(BUILDDIR)/GameLib/Time.o \
$(BUILDDIR)/GameLib/Util.o \ $(BUILDDIR)/GameLib/Util.o \
$(BUILDDIR)/GameLib/QuadArray2D.o \
$(BUILDDIR)/GameLib/Draw.o \ $(BUILDDIR)/GameLib/Draw.o \
$(BUILDDIR)/GameLib/Input.o \ $(BUILDDIR)/GameLib/Input.o \
$(BUILDDIR)/GameLib/Audio.o \ $(BUILDDIR)/GameLib/Audio.o \
@@ -26,6 +24,7 @@ OBJS= \
$(BUILDDIR)/GameLib/GameLib.o \ $(BUILDDIR)/GameLib/GameLib.o \
##################### #####################
# Game Declarations # # Game Declarations #
##################### #####################
@@ -37,6 +36,11 @@ OBJS+= \
$(BUILDDIR)/main.o $(BUILDDIR)/main.o
################# #################
# General Rules # # General Rules #
################# #################
@@ -49,10 +53,12 @@ $(BUILDDIR):
clean: clean:
rm -f $(OBJS) $(BUILDDIR)/$(RESULT) rm -f $(OBJS) $(BUILDDIR)/$(RESULT)
run: $(BUILDDIR) $(BUILDDIR)/$(RESULT) run: $(BUILDDIR)/$(RESULT)
$(LAUNCHER) ./$(BUILDDIR)/$(RESULT) debug ./$(BUILDDIR)/$(RESULT) debug
rebuild: clean all
################# #################
# GameLib Rules # # GameLib Rules #
@@ -61,8 +67,6 @@ $(BUILDDIR)/GameLib/Time.o: GameLib/Time.c $(HEADS)
$(CC) -c GameLib/Time.c -o $(BUILDDIR)/GameLib/Time.o $(CFLAGS) $(CC) -c GameLib/Time.c -o $(BUILDDIR)/GameLib/Time.o $(CFLAGS)
$(BUILDDIR)/GameLib/Util.o: GameLib/Util.c $(HEADS) $(BUILDDIR)/GameLib/Util.o: GameLib/Util.c $(HEADS)
$(CC) -c GameLib/Util.c -o $(BUILDDIR)/GameLib/Util.o $(CFLAGS) $(CC) -c GameLib/Util.c -o $(BUILDDIR)/GameLib/Util.o $(CFLAGS)
$(BUILDDIR)/GameLib/QuadArray2D.o: GameLib/QuadArray2D.c $(HEADS)
$(CC) -c GameLib/QuadArray2D.c -o $(BUILDDIR)/GameLib/QuadArray2D.o $(CFLAGS)
$(BUILDDIR)/GameLib/Draw.o: GameLib/Draw.c $(HEADS) $(BUILDDIR)/GameLib/Draw.o: GameLib/Draw.c $(HEADS)
$(CC) -c GameLib/Draw.c -o $(BUILDDIR)/GameLib/Draw.o $(CFLAGS) $(CC) -c GameLib/Draw.c -o $(BUILDDIR)/GameLib/Draw.o $(CFLAGS)
$(BUILDDIR)/GameLib/Input.o: GameLib/Input.c $(HEADS) $(BUILDDIR)/GameLib/Input.o: GameLib/Input.c $(HEADS)
@@ -77,6 +81,7 @@ $(BUILDDIR)/GameLib/GameLib.o: GameLib/GameLib.c $(HEADS)
$(CC) -c GameLib/GameLib.c -o $(BUILDDIR)/GameLib/GameLib.o $(CFLAGS) $(CC) -c GameLib/GameLib.c -o $(BUILDDIR)/GameLib/GameLib.o $(CFLAGS)
############## ##############
# Game Rules # # Game Rules #
############## ##############
@@ -90,13 +95,8 @@ $(BUILDDIR)/GameMap.o: GameMap.c $(HEADS)
$(BUILDDIR)/main.o: main.c $(HEADS) $(BUILDDIR)/main.o: main.c $(HEADS)
$(CC) -c main.c -o $(BUILDDIR)/main.o $(CFLAGS) $(CC) -c main.c -o $(BUILDDIR)/main.o $(CFLAGS)
################
# Result Rules #
################
$(BUILDDIR)/$(RESULT): $(OBJS) $(BUILDDIR)/$(RESULT): $(OBJS)
$(CC) -o $(BUILDDIR)/$(RESULT) $(OBJS) $(LIBS) $(CFLAGS) $(LDFLAGS) $(CC) -o $(BUILDDIR)/$(RESULT) $(OBJS) $(LIBS) $(CFLAGS)

View File

@@ -1,21 +0,0 @@
CC= emcc
LAUNCHER= start
RM=rm -rf
LIBS=
CFLAGS= -s FULL_ES2=1 -s ASM_JS=1 -O1 -Wno-implicit-function-declaration
#LDFLAGS= --embed-file data
LDFLAGS= --preload-file data
RESULT=game.html
BUILDDIR=build-emscripten
ifeq ($(target),release)
CFLAGS= -s FULL_ES2=1 -s ASM_JS=1 -O2 --llvm-lto 1 -Wno-implicit-function-declaration
BUILDDIR=build-emscripten-release
endif
include Makefile.common

View File

@@ -1,10 +1,7 @@
CC=gcc
LAUNCHER=
RM=rm -rf
LIBS= -lSDL -lpthread -L/usr/X11R6/lib -L/usr/lib -lm -lGL -lX11 LIBS= -lSDL -lpthread -L/usr/X11R6/lib -L/usr/lib -lm -lGL -lX11
CFLAGS= -Wall -g -I/usr/include/ -I/usr/include/SDL/ -I/usr/X11R6/include/ CFLAGS= -Wall -g -I/usr/include/ -I/usr/include/SDL/ -I/usr/X11R6/include/
LDFLAGS= CC=gcc
RM=rm -rf
RESULT=game RESULT=game
BUILDDIR=build-linux BUILDDIR=build-linux

9
Makefile.macosx Normal file
View File

@@ -0,0 +1,9 @@
LIBS=-lm -ldl -framework Cocoa -framework SDL -framework OpenGL macosx/SDLMain.m
CFLAGS=-g -DDEBUG -Wall -DMACOSX -ObjC -Dmain=SDL_main
CC=gcc
RM=rm -rf
RESULT=game
BUILDDIR=build-macosx
include Makefile.common

View File

@@ -1,10 +1,7 @@
CC= i486-mingw32-gcc
LAUNCHER=
RM=rm -rf
LIBS= -L/usr/i486-mingw/lib -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32 LIBS= -L/usr/i486-mingw/lib -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32
CFLAGS= -I/usr/i486-mingw/include -lmingw32 -lSDLmain -lSDL -mwindows CFLAGS= -I/usr/i486-mingw/include -lmingw32 -lSDLmain -lSDL -mwindows
LDFLAGS= CC= i486-mingw32-gcc
RM=rm -rf
RESULT=game.exe RESULT=game.exe
BUILDDIR=build-mingw BUILDDIR=build-mingw

View File

@@ -1,10 +1,7 @@
CC=gcc
LAUNCHER=
RM=rm -rf
LIBS=-I/mingw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32 LIBS=-I/mingw/include/SDL -D_GNU_SOURCE=1 -Dmain=SDL_main -lopengl32
CFLAGS= -L/mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows -g CFLAGS= -L/mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows -g
LDFLAGS= CC=gcc
RM=rm -rf
RESULT=game.exe RESULT=game.exe
BUILDDIR=build-mingw BUILDDIR=build-mingw

View File

@@ -1,61 +0,0 @@
TODO
----
- Entities:
- Teleporters
- Doors and Buttons
- Buttons
- Music
- Non-SFXR sounds
DONE
----
- Util
- Circle collision
- Draw
- Screen init
- Image loading
- Image drawing
- Font loading
- Text Drawing
- Draw loop
- Input
- Keyboard
- Mouse
- Audio
- Sound loading
- Sound playing
- Anim
- Animation loading
- Animation playing
- Entity
- Process
- Overlap
- Collision
- GameLib
- Game loop
- Entity processing
- Sound playing spatially
- Lighting
- Game Map
- Loading
- Game Entities:
- Player
- Barrel
- Spikes
- Lava
- ArrowShooters
- Arrows
- Columns
- Rock
- Floor
- Save points
- Light points
- Title Screen
- Game End Screen
- Game saving and loading
- Level and savepoint

BIN
SDL.dll

Binary file not shown.

88
conv.c
View File

@@ -1,88 +0,0 @@
#include <stdio.h>
#include <string.h>
int Aux_Linea(FILE *f,char *line){
int c;
int i=0;
memset(line,0,1024);
while(i<1024){
c=fgetc(f);
if(c==EOF){
line[i]=0;
return(0);
}
if(c=='\r'){
continue;
}
if(c=='\n'){
line[i]=0;
break;
}
line[i]=c;
i++;
}
return(1);
}
int convert(char *file){
FILE *f,*f2;
char file2[1024];
char line[1024];
int w,h;
int i,n;
int loop;
f=fopen(file,"rb");
if(!f){
return(0);
}
sprintf(file2,"%s.txt",file);
f2=fopen(file2,"wb");
if(!f2){
fclose(f);
return(0);
}
Aux_Linea(f,line);
sscanf(line,"%d %d",&w,&h);
fprintf(f2,"%d %d\n",w,h);
loop=0;
do{
loop=Aux_Linea(f,line);
n=strlen(line);
for(i=0;i<n;i++){
fprintf(f2,"%c%c",line[i],line[i]);
}
fprintf(f2,"\n");
}while(loop);
fclose(f);
fclose(f2);
return(1);
}
int main(int argc,char *argv[]){
char file[1024];
int i;
i=0;
do{
sprintf(file,"data/level_%02d.txt",i);
printf("%s\n",file);
if(!convert(file)){
break;
}
i++;
}while(1);
return(1);
}

View File

@@ -1 +0,0 @@
3,0.5,0.32,0.31,,0.285,,1,,-1,-1,,,0.14,,,-1,,-1,,,,,-1,-1,1,1,,,-1,,-1,masterVolume

View File

@@ -1 +0,0 @@
3,0.5,,0.2901,0.4276,0.4858,0.3,0.0327,,0.0396,,,,,,,,,,,,,0.4513,0.4207,-0.2057,1,,,,,,,masterVolume

View File

@@ -1 +0,0 @@
3,0.5,,0.0824,,0.1102,0.3,0.2174,,-0.551,,,,,,,,,,,,,,,,1,,,,,,,masterVolume

View File

@@ -1 +0,0 @@
3,0.5,,0.0316,,0.2791,0.3,0.2286,,-0.5036,,,,,,,,,,,,,,,,1,,,0.0144,,,,masterVolume

View File

@@ -1 +0,0 @@
8,0.5,,0.1744,0.1511,0.1706,0.3,0.6762,0.2,-0.2748,,,,,,,,,,,0.5075,-0.0829,,0.395,-0.3199,0.625,,,,,,,masterVolume

View File

@@ -1 +0,0 @@
2,0.5,,0.3096,,0.4346,0.3,0.2865,,0.1628,,0.5293,0.426,,,,,,,,0.3934,,,,,1,,,,,,,masterVolume

View File

@@ -1 +0,0 @@
2,0.5,,0.1458,,0.3359,0.3,0.2684,,0.2068,,,,,,,,,,,0.5759,,0.4191,,,1,,,,,,,masterVolume

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More